cli.rs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: Apache-2.0
  2. use assert_cmd::Command;
  3. use std::fs::File;
  4. use tempfile::TempDir;
  5. #[test]
  6. fn create_output_dir() {
  7. let mut cmd = Command::cargo_bin("solang").unwrap();
  8. let tmp = TempDir::new_in("tests").unwrap();
  9. let test1 = tmp.path().join("test1");
  10. cmd.args([
  11. "compile",
  12. "examples/solana/flipper.sol",
  13. "--target",
  14. "solana",
  15. "--output",
  16. ])
  17. .arg(test1.clone())
  18. .assert()
  19. .success();
  20. File::open(test1.join("flipper.json")).expect("should exist");
  21. File::open(test1.join("flipper.so")).expect("should exist");
  22. let mut cmd = Command::cargo_bin("solang").unwrap();
  23. let test2 = tmp.path().join("test2");
  24. let test2_meta = tmp.path().join("test2_meta");
  25. cmd.args([
  26. "compile",
  27. "examples/solana/flipper.sol",
  28. "--target",
  29. "solana",
  30. "--contract",
  31. "flipper",
  32. "--output",
  33. ])
  34. .arg(test2.clone())
  35. .arg("--output-meta")
  36. .arg(test2_meta.clone())
  37. .assert()
  38. .success();
  39. File::open(test2.join("flipper.so")).expect("should exist");
  40. File::open(test2_meta.join("flipper.json")).expect("should exist");
  41. let mut cmd = Command::cargo_bin("solang").unwrap();
  42. cmd.args([
  43. "compile",
  44. "examples/solana/flipper.sol",
  45. "--target",
  46. "solana",
  47. "--output",
  48. "examples/solana/flipper.sol",
  49. ])
  50. .assert()
  51. .failure();
  52. let mut cmd = Command::cargo_bin("solang").unwrap();
  53. let test3 = tmp.path().join("test3");
  54. cmd.args([
  55. "compile",
  56. "examples/solana/flipper.sol",
  57. "--target",
  58. "solana",
  59. "--contract",
  60. "flapper,flipper", // not just flipper
  61. "--output",
  62. ])
  63. .arg(test3.clone())
  64. .assert()
  65. .failure();
  66. // nothing should have been created because flapper does not exist
  67. assert!(!test3.exists());
  68. }
  69. #[test]
  70. fn basic_compilation_from_toml() {
  71. let mut new_cmd = Command::cargo_bin("solang").unwrap();
  72. let tmp = TempDir::new_in("tests").unwrap();
  73. let solana_test = tmp.path().join("solana_test");
  74. //solang new --target solana
  75. new_cmd
  76. .arg("new")
  77. .arg(solana_test.clone())
  78. .args(["--target", "solana"])
  79. .assert()
  80. .success();
  81. File::open(solana_test.join("flipper.sol")).expect("should exist");
  82. File::open(solana_test.join("solang.toml")).expect("should exist");
  83. // compile flipper using config file
  84. let mut compile_cmd = Command::cargo_bin("solang").unwrap();
  85. compile_cmd
  86. .args(["compile"])
  87. .current_dir(solana_test)
  88. .assert()
  89. .success();
  90. let substrate_test = tmp.path().join("substrate_test");
  91. let _new_cmd = Command::cargo_bin("solang")
  92. .unwrap()
  93. .arg("new")
  94. .arg(substrate_test.clone())
  95. .args(["--target", "solana"])
  96. .assert()
  97. .success();
  98. compile_cmd.current_dir(substrate_test).assert().success();
  99. }