Skip to content

Commit a592f7a

Browse files
authored
chore: don't display filter used if empty (#8929)
1 parent cd1c77a commit a592f7a

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

crates/forge/bin/cmd/test/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,21 @@ impl TestArgs {
494494
self.flamechart) &&
495495
num_filtered != 1
496496
{
497+
let action = if self.flamegraph {
498+
"generate a flamegraph"
499+
} else if self.flamechart {
500+
"generate a flamechart"
501+
} else {
502+
"run the debugger"
503+
};
504+
let filter = if filter.is_empty() {
505+
String::new()
506+
} else {
507+
format!("\n\nFilter used:\n{filter}")
508+
};
497509
eyre::bail!(
498510
"{num_filtered} tests matched your criteria, but exactly 1 test must match in order to {action}.\n\n\
499-
Use --match-contract and --match-path to further limit the search.\n\
500-
Filter used:\n{filter}",
501-
action = if self.flamegraph {"generate a flamegraph"} else if self.flamechart {"generate a flamechart"} else {"run the debugger"},
511+
Use --match-contract and --match-path to further limit the search.{filter}",
502512
);
503513
}
504514

crates/forge/tests/cli/test_cmd.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,3 +2174,31 @@ Warning: the following cheatcode(s) are deprecated and will be removed in future
21742174
"#]]);
21752175
}
21762176
);
2177+
2178+
forgetest_init!(requires_single_test, |prj, cmd| {
2179+
cmd.args(["test", "--debug", "test"]).assert_failure().stderr_eq(str![[r#"
2180+
Error:
2181+
2 tests matched your criteria, but exactly 1 test must match in order to run the debugger.
2182+
2183+
Use --match-contract and --match-path to further limit the search.
2184+
2185+
Filter used:
2186+
match-test: `test`
2187+
2188+
2189+
"#]]);
2190+
cmd.forge_fuse().args(["test", "--flamegraph"]).assert_failure().stderr_eq(str![[r#"
2191+
Error:
2192+
2 tests matched your criteria, but exactly 1 test must match in order to generate a flamegraph.
2193+
2194+
Use --match-contract and --match-path to further limit the search.
2195+
2196+
"#]]);
2197+
cmd.forge_fuse().args(["test", "--flamechart"]).assert_failure().stderr_eq(str![[r#"
2198+
Error:
2199+
2 tests matched your criteria, but exactly 1 test must match in order to generate a flamechart.
2200+
2201+
Use --match-contract and --match-path to further limit the search.
2202+
2203+
"#]]);
2204+
});

0 commit comments

Comments
 (0)