Skip to content

Commit

Permalink
fix(forge): exit with error code on fail fast (foundry-rs#4883) (foun…
Browse files Browse the repository at this point in the history
  • Loading branch information
agostbiro authored Jun 12, 2023
1 parent 19881cf commit 89f2782
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cli/src/cmd/forge/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ fn test(
SignaturesIdentifier::new(Config::foundry_cache_dir(), config.offline)?;

'outer: for (contract_name, suite_result) in rx {
results.insert(contract_name.clone(), suite_result.clone());

let mut tests = suite_result.test_results.clone();
println!();
for warning in suite_result.warnings.iter() {
Expand Down Expand Up @@ -617,12 +619,9 @@ fn test(
}
}
}
let block_outcome = TestOutcome::new(
[(contract_name.clone(), suite_result.clone())].into(),
allow_failure,
);
let block_outcome =
TestOutcome::new([(contract_name, suite_result)].into(), allow_failure);
println!("{}", block_outcome.summary());
results.insert(contract_name, suite_result);
}

if gas_reporting {
Expand Down
38 changes: 38 additions & 0 deletions cli/tests/it/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,41 @@ contract ContractTest is Test {
.join("tests/fixtures/can_use_libs_in_multi_fork.stdout"),
);
});

static FAILING_TEST: &str = r#"
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import "forge-std/Test.sol";
contract FailingTest is Test {
function testShouldFail() public {
assertTrue(false);
}
}
"#;

forgetest_init!(exit_code_error_on_fail_fast, |prj: TestProject, mut cmd: TestCommand| {
prj.wipe_contracts();
prj.inner().add_source("failing_test", FAILING_TEST).unwrap();

// set up command
cmd.args(["test", "--fail-fast"]);

// run command and assert error exit code
cmd.assert_err();
});

forgetest_init!(
exit_code_error_on_fail_fast_with_json,
|prj: TestProject, mut cmd: TestCommand| {
prj.wipe_contracts();

prj.inner().add_source("failing_test", FAILING_TEST).unwrap();
// set up command
cmd.args(["test", "--fail-fast", "--json"]);

// run command and assert error exit code
cmd.assert_err();
}
);

0 comments on commit 89f2782

Please sign in to comment.