| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- // SPDX-License-Identifier: Apache-2.0
- use assert_cmd::Command;
- use std::path::PathBuf;
- fn solang_import_resolution_tests() -> PathBuf {
- PathBuf::from(env!("CARGO_MANIFEST_DIR"))
- .join("testdata")
- .join("solang_import_resolution_tests")
- }
- fn make_run(dir: &str) -> Command {
- let current_dir = solang_import_resolution_tests().join(dir);
- let mut cmd = Command::cargo_bin("solang").unwrap();
- cmd.current_dir(current_dir)
- .args(["compile", "--target", "solana"]);
- cmd
- }
- #[test]
- fn import_test_01_solang_remap_target() {
- // Command 1
- let mut cmd = make_run("01_solang_remap_target");
- let run = cmd.arg("contracts/Contract.sol").env("exit", "1").assert();
- let stderr = String::from_utf8_lossy(&run.get_output().stderr);
- println!("stderr: {stderr}");
- assert!(stderr.contains("file not found 'lib/Lib.sol'"));
- assert!(stderr.contains("'Lib' not foun"));
- assert!(stderr.contains("'x' not found"));
- // Command 2
- let mut cmd = make_run("01_solang_remap_target");
- let run = cmd
- .arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("lib=node_modules/lib")
- .assert()
- .failure();
- let stderr = String::from_utf8_lossy(&run.get_output().stderr);
- println!("stderr: {stderr}");
- assert!(stderr.contains("file not found 'lib/Lib.sol'"));
- assert!(stderr.contains("'Lib' not foun"));
- assert!(stderr.contains("'x' not found"));
- // Command 3
- let mut cmd = make_run("01_solang_remap_target");
- let run = cmd
- .arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("lib=node_modules/lib")
- .arg("--importpath")
- .arg(".")
- .assert()
- .failure();
- let stderr = String::from_utf8_lossy(&run.get_output().stderr);
- println!("stderr: {stderr}");
- assert!(stderr.contains("file not found 'lib/Lib.sol'"));
- assert!(stderr.contains("'Lib' not foun"));
- assert!(stderr.contains("'x' not found"));
- // Command 4
- let mut cmd = make_run("01_solang_remap_target");
- let run = cmd
- .arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("lib=node_modules/lib")
- .arg("--importpath")
- .arg(".")
- .arg("--importpath")
- .arg("resources/node_modules")
- .assert()
- .failure();
- let stderr = String::from_utf8_lossy(&run.get_output().stderr);
- println!("stderr: {stderr}");
- assert!(stderr.contains("file not found 'lib/Lib.sol'"));
- assert!(stderr.contains("'Lib' not foun"));
- assert!(stderr.contains("'x' not found"));
- // Command 5
- let mut cmd = make_run("01_solang_remap_target");
- cmd.arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("lib=node_modules/lib")
- .arg("--importpath")
- .arg(".")
- .arg("--importpath")
- .arg("resources")
- .assert()
- .success();
- }
- #[test]
- fn import_test_02_solang_incorrect_direct_imports() {
- // Command 1
- let mut cmd = make_run("02_solang_incorrect_direct_imports");
- cmd.arg("contracts/Contract.sol").env("exit", "0").assert();
- // Command 2
- let mut cmd = make_run("02_solang_incorrect_direct_imports");
- cmd.arg("contracts/Contract.sol")
- .arg("--importpath")
- .arg(".")
- .assert()
- .success();
- }
- #[test]
- fn import_test_03_ambiguous_imports_should_fail() {
- // Command 1
- let mut cmd = make_run("03_ambiguous_imports_should_fail");
- cmd.arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("lib=resources/node_modules/lib")
- .arg("--importpath")
- .arg("contracts")
- .arg("--importpath")
- .arg(".")
- .assert()
- .failure();
- }
- #[test]
- fn import_test_04_multiple_path_map_segments() {
- // Command 1
- let mut cmd = make_run("04_multiple_map_path_segments");
- cmd.arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("lib/nested=resources/node_modules/lib/nested")
- .arg("--importpath")
- .arg(".")
- .assert()
- .success();
- }
- #[test]
- fn import_test_06_redundant_remaps() {
- // Command 1
- let mut cmd = make_run("06_redundant_remaps");
- cmd.arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("node_modules=resources/node_modules")
- .arg("--importmap")
- .arg("node_modules=node_modules")
- .arg("--importpath")
- .arg("resources")
- .assert()
- .success();
- let mut cmd = make_run("06_redundant_remaps");
- cmd.arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("node_modules=node_modules")
- .arg("--importmap")
- .arg("node_modules=resources/node_modules")
- .arg("--importpath")
- .arg("resources")
- .assert()
- .failure();
- let mut cmd = make_run("06_redundant_remaps");
- cmd.arg("contracts/Contract.sol")
- .arg("--importmap")
- .arg("node_modules=node_modules")
- .arg("--importmap")
- .arg("node_modules=resources/node_modules")
- .arg("--importmap")
- .arg("node_modules=node_modules")
- .arg("--importpath")
- .arg("resources")
- .assert()
- .success();
- }
|