fix(solc): improve remappings autodetection (#1335)

This commit is contained in:
Matthias Seitz 2022-06-01 17:25:27 +02:00 committed by GitHub
parent 89bc6420bb
commit 598c00e55d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -452,6 +452,14 @@ impl Candidate {
current_dir.to_path_buf()
};
// if the window start and the source dir are the same directory we can end early if
// we wrongfully detect something like: `<dep>/src/lib/`
if current_level > 0 &&
source_dir == window_start &&
(is_source_dir(&source_dir) || is_lib_dir(&source_dir))
{
return
}
candidates.push(Candidate { window_start, source_dir, window_level: current_level });
}
}
@ -759,6 +767,22 @@ mod tests {
assert_eq!(remappings[0].path, format!("{}/src/", path));
}
#[test]
fn can_resolve_contract_dir_combinations() {
let tmp_dir = tempdir("demo").unwrap();
let paths =
["lib/timeless/src/lib/A.sol", "lib/timeless/src/B.sol", "lib/timeless/src/test/C.sol"];
mkdir_or_touch(tmp_dir.path(), &paths[..]);
let tmp_dir_path = tmp_dir.path().join("lib");
let remappings = Remapping::find_many(&tmp_dir_path);
let expected = vec![Remapping {
name: "timeless/".to_string(),
path: to_str(tmp_dir_path.join("timeless/src")),
}];
pretty_assertions::assert_eq!(remappings, expected);
}
#[test]
fn can_resolve_geb_remappings() {
let tmp_dir = tempdir("geb").unwrap();