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 7a7d1de
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,26 +573,32 @@ 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| {
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()];
forgetest!(can_prioritise_closer_lib_remappings, |prj, cmd| {
// `lib/dep1` has `my-dep/=path/to/dep` remappings.
// `lib/dep1/lib/dep2` has `my-dep/=path/to/dep` and `my-dep2/=path/to/dep` remappings.
// Resolved remappings should be `my-dep` to `lib/dep1` and `my-dep2` to `lib/dep1/lib/dep2`.
let mut config = cmd.config();
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/
- 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 7a7d1de

Please sign in to comment.