Skip to content

Commit

Permalink
fix(forge test): record only test fns in test failures (foundry-rs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy authored and rplusq committed Nov 29, 2024
1 parent 2830f36 commit ae3864c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
12 changes: 7 additions & 5 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use foundry_cli::{
opts::CoreBuildArgs,
utils::{self, LoadConfig},
};
use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs, shell};
use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs, shell, TestFunctionExt};
use foundry_compilers::{
artifacts::output_selection::OutputSelection,
compilers::{multi::MultiCompilerLanguage, CompilerSettings, Language},
Expand Down Expand Up @@ -935,10 +935,12 @@ fn persist_run_failures(config: &Config, outcome: &TestOutcome) {
let mut filter = String::new();
let mut failures = outcome.failures().peekable();
while let Some((test_name, _)) = failures.next() {
if let Some(test_match) = test_name.split("(").next() {
filter.push_str(test_match);
if failures.peek().is_some() {
filter.push('|');
if test_name.is_any_test() {
if let Some(test_match) = test_name.split("(").next() {
filter.push_str(test_match);
if failures.peek().is_some() {
filter.push('|');
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,30 @@ Encountered a total of 2 failing tests, 0 tests succeeded
"#]]);
});

// <https://github.com/foundry-rs/foundry/issues/9285>
forgetest_init!(should_not_record_setup_failures, |prj, cmd| {
prj.add_test(
"ReplayFailures.t.sol",
r#"
import {Test} from "forge-std/Test.sol";
contract SetupFailureTest is Test {
function setUp() public {
require(2 > 1);
}
function testA() public pure {
}
}
"#,
)
.unwrap();

cmd.args(["test"]).assert_success();
// Test failure filter should not be persisted if `setUp` failed.
assert!(!prj.root().join("cache/test-failures").exists());
});

// https://github.com/foundry-rs/foundry/issues/7530
forgetest_init!(should_show_precompile_labels, |prj, cmd| {
prj.wipe_contracts();
Expand Down

0 comments on commit ae3864c

Please sign in to comment.