Skip to content

Commit

Permalink
chore: don't display filter used if empty (#8929)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Sep 22, 2024
1 parent cd1c77a commit a592f7a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
16 changes: 13 additions & 3 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,21 @@ impl TestArgs {
self.flamechart) &&
num_filtered != 1
{
let action = if self.flamegraph {
"generate a flamegraph"
} else if self.flamechart {
"generate a flamechart"
} else {
"run the debugger"
};
let filter = if filter.is_empty() {
String::new()
} else {
format!("\n\nFilter used:\n{filter}")
};
eyre::bail!(
"{num_filtered} tests matched your criteria, but exactly 1 test must match in order to {action}.\n\n\
Use --match-contract and --match-path to further limit the search.\n\
Filter used:\n{filter}",
action = if self.flamegraph {"generate a flamegraph"} else if self.flamechart {"generate a flamechart"} else {"run the debugger"},
Use --match-contract and --match-path to further limit the search.{filter}",
);
}

Expand Down
28 changes: 28 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,3 +2174,31 @@ Warning: the following cheatcode(s) are deprecated and will be removed in future
"#]]);
}
);

forgetest_init!(requires_single_test, |prj, cmd| {
cmd.args(["test", "--debug", "test"]).assert_failure().stderr_eq(str![[r#"
Error:
2 tests matched your criteria, but exactly 1 test must match in order to run the debugger.
Use --match-contract and --match-path to further limit the search.
Filter used:
match-test: `test`
"#]]);
cmd.forge_fuse().args(["test", "--flamegraph"]).assert_failure().stderr_eq(str![[r#"
Error:
2 tests matched your criteria, but exactly 1 test must match in order to generate a flamegraph.
Use --match-contract and --match-path to further limit the search.
"#]]);
cmd.forge_fuse().args(["test", "--flamechart"]).assert_failure().stderr_eq(str![[r#"
Error:
2 tests matched your criteria, but exactly 1 test must match in order to generate a flamechart.
Use --match-contract and --match-path to further limit the search.
"#]]);
});

0 comments on commit a592f7a

Please sign in to comment.