Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Nov 5, 2024
1 parent d308196 commit 7927610
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
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.
Expand Down

0 comments on commit 7927610

Please sign in to comment.