From 79276103eaab95023f54a8caddb32dea11afd2c2 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Tue, 5 Nov 2024 16:23:54 +0200 Subject: [PATCH] Test --- crates/forge/tests/cli/config.rs | 34 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/crates/forge/tests/cli/config.rs b/crates/forge/tests/cli/config.rs index f38dcf414a009..58013959cb979 100644 --- a/crates/forge/tests/cli/config.rs +++ b/crates/forge/tests/cli/config.rs @@ -574,25 +574,37 @@ forgetest_init!(can_detect_lib_foundry_toml, |prj, cmd| { // test remappings with closer paths are prioritised // so that `dep/=lib/a/src` will take precedent over `dep/=lib/a/lib/b/src` forgetest_init!(can_prioritise_closer_lib_remappings, |prj, cmd| { + // `root` path has `forge-std/=lib/forge-std/src/` remapping. + // `lib/dep1` has `forge-std/=lib/forge-std/src/` and `my-dep/=path/to/dep` remappings. + // `lib/dep1/lib/dep2` has `forge-std/=lib/forge-std/src/`, `my-dep/=path/to/dep` and + // `my-dep2/=path/to/dep` remappings. + // Resolved remappings should be `forge-std` to `root`, `my-dep` to `lib/dep1` and `my-dep2` to + // `lib/dep1/lib/dep2`. let config = cmd.config(); - // create a new lib directly in the `lib` folder with conflicting remapping `forge-std/` let mut config = config; - config.remappings = vec![Remapping::from_str("forge-std/=lib/forge-std/src/").unwrap().into()]; + config.remappings.push(Remapping::from_str("my-dep/=path/to/dep").unwrap().into()); let nested = prj.paths().libraries[0].join("dep1"); pretty_err(&nested, fs::create_dir_all(&nested)); let toml_file = nested.join("foundry.toml"); pretty_err(&toml_file, fs::write(&toml_file, config.to_string_pretty().unwrap())); - let config = cmd.config(); - let remappings = config.get_all_remappings().collect::>(); - similar_asserts::assert_eq!( - remappings, - vec![ - "dep1/=lib/dep1/src/".parse().unwrap(), - "forge-std/=lib/forge-std/src/".parse().unwrap() - ] - ); + let nested_lib = prj.paths().libraries[0].join("dep1").join("lib/dep2"); + pretty_err(&nested, fs::create_dir_all(&nested_lib)); + let toml_file = nested_lib.join("foundry.toml"); + config.remappings.push(Remapping::from_str("my-dep2/=path/to/dep").unwrap().into()); + pretty_err(&toml_file, fs::write(&toml_file, config.to_string_pretty().unwrap())); + + cmd.args(["remappings", "--pretty"]).assert_success().stdout_eq(str![[r#" +Global: +- dep1/=lib/dep1/src/ +- dep2/=lib/dep1/lib/dep2/src/ +- forge-std/=lib/forge-std/src/ +- my-dep/=lib/dep1/path/to/dep/ +- my-dep2/=lib/dep1/lib/dep2/path/to/dep/ + + +"#]]); }); // Test that remappings within root of the project have priority over remappings of sub-projects.