cli.rs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. let assert = cmd
  26. .args([
  27. "compile",
  28. "examples/solana/flipper.sol",
  29. "--target",
  30. "solana",
  31. "--contract",
  32. "flipper",
  33. "--contract-authors",
  34. "itchy and cratchy",
  35. "--output",
  36. ])
  37. .arg(test2.clone())
  38. .arg("--output-meta")
  39. .arg(test2_meta.clone())
  40. .assert()
  41. .success();
  42. File::open(test2.join("flipper.so")).expect("should exist");
  43. File::open(test2_meta.join("flipper.json")).expect("should exist");
  44. let output = assert.get_output();
  45. assert_eq!(
  46. String::from_utf8_lossy(&output.stderr),
  47. "warning: the `authors` flag will be ignored for Solana target\n"
  48. );
  49. let mut cmd = Command::cargo_bin("solang").unwrap();
  50. cmd.args([
  51. "compile",
  52. "examples/solana/flipper.sol",
  53. "--target",
  54. "solana",
  55. "--output",
  56. "examples/solana/flipper.sol",
  57. ])
  58. .assert()
  59. .failure();
  60. let mut cmd = Command::cargo_bin("solang").unwrap();
  61. let test3 = tmp.path().join("test3");
  62. cmd.args([
  63. "compile",
  64. "examples/solana/flipper.sol",
  65. "--target",
  66. "solana",
  67. "--contract",
  68. "flapper,flipper", // not just flipper
  69. "--output",
  70. ])
  71. .arg(test3.clone())
  72. .assert()
  73. .failure();
  74. // nothing should have been created because flapper does not exist
  75. assert!(!test3.exists());
  76. }
  77. #[test]
  78. fn basic_compilation_from_toml() {
  79. let mut new_cmd = Command::cargo_bin("solang").unwrap();
  80. let tmp = TempDir::new_in("tests").unwrap();
  81. let solana_test = tmp.path().join("solana_test");
  82. //solang new --target solana
  83. new_cmd
  84. .arg("new")
  85. .arg(solana_test.clone())
  86. .args(["--target", "solana"])
  87. .assert()
  88. .success();
  89. File::open(solana_test.join("flipper.sol")).expect("should exist");
  90. File::open(solana_test.join("solang.toml")).expect("should exist");
  91. // compile flipper using config file
  92. let mut compile_cmd = Command::cargo_bin("solang").unwrap();
  93. compile_cmd
  94. .args(["compile"])
  95. .current_dir(solana_test)
  96. .assert()
  97. .success();
  98. let polkadot_test = tmp.path().join("polkadot_test");
  99. let _new_cmd = Command::cargo_bin("solang")
  100. .unwrap()
  101. .arg("new")
  102. .arg(polkadot_test.clone())
  103. .args(["--target", "solana"])
  104. .assert()
  105. .success();
  106. compile_cmd.current_dir(polkadot_test).assert().success();
  107. }