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(forge test): record only test fns in test failures #9286

Merged
merged 1 commit into from
Nov 8, 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
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
Loading