Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --match-path is broken #7579

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/forge/bin/cmd/test/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ impl FileFilter for ProjectPathsAwareFilter {
///
/// If no file regex is set this returns true if the file ends with `.t.sol`, see
/// [FoundryPathExr::is_sol_test()]
fn is_match(&self, file: &Path) -> bool {
fn is_match(&self, mut file: &Path) -> bool {
file = file.strip_prefix(&self.paths.root).unwrap_or(file);
self.args_filter.is_match(file)
}
}
Expand All @@ -210,8 +211,9 @@ impl TestFilter for ProjectPathsAwareFilter {
self.args_filter.matches_contract(contract_name)
}

fn matches_path(&self, path: &Path) -> bool {
fn matches_path(&self, mut path: &Path) -> bool {
// we don't want to test files that belong to a library
path = path.strip_prefix(&self.paths.root).unwrap_or(path);
self.args_filter.matches_path(path) && !self.paths.has_library_ancestor(path)
}
}
Expand Down
15 changes: 15 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,18 @@ contract GasLimitTest is Test {

cmd.args(["test", "-vvvv", "--isolate", "--disable-block-gas-limit"]).assert_success();
});

forgetest!(test_match_path, |prj, cmd| {
prj.add_source(
"dummy",
r"
contract Dummy {
function testDummy() public {}
}
",
)
.unwrap();

cmd.args(["test", "--match-path", "src/dummy.sol"]);
cmd.assert_success()
});
Loading