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

debt(forge): remove testFail* #9574

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 13 additions & 2 deletions crates/forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,20 @@ impl<'a> FunctionRunner<'a> {
return self.result;
}

let test_fail_deprecation = |should_fail: bool| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we want to deprecate with a warning first for 0.3?

Copy link
Member Author

@yash-atreya yash-atreya Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Ptal #9581

if should_fail {
return Some(TestResult::fail(format!("`testFail*` has been deprecated. Consider changing {} to something along the lines of `test_Revert[If|When]_Condition` and expecting a revert.", func.name)));
}
None
};

match kind {
TestFunctionKind::UnitTest { should_fail } => self.run_unit_test(func, should_fail),
TestFunctionKind::FuzzTest { should_fail } => self.run_fuzz_test(func, should_fail),
TestFunctionKind::UnitTest { should_fail } => {
test_fail_deprecation(should_fail).unwrap_or(self.run_unit_test(func, should_fail))
}
TestFunctionKind::FuzzTest { should_fail } => {
test_fail_deprecation(should_fail).unwrap_or(self.run_fuzz_test(func, should_fail))
}
TestFunctionKind::InvariantTest => {
self.run_invariant_test(func, call_after_invariant, identified_contracts.unwrap())
}
Expand Down
69 changes: 69 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2807,3 +2807,72 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
"#]],
);
});

// expect revert //

forgetest_init!(expect_revert_tests_should_fail, |prj, cmd| {
prj.insert_ds_test();
prj.insert_vm();
let expect_revert_failure_tests = include_str!("../fixtures/ExpectRevertFailures.t.sol");

prj.add_source("ExpectRevertFailures.sol", expect_revert_failure_tests).unwrap();

cmd.forge_fuse()
.args(["test", "--mc", "ExpectRevertFailureTest"])
.assert_failure()
.stdout_eq(
r#"[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
...
[FAIL: next call did not revert as expected] testShouldFailExpectRevertAnyRevertDidNotRevert() ([GAS])
[FAIL: next call did not revert as expected] testShouldFailExpectRevertDangling() ([GAS])
[FAIL: next call did not revert as expected] testShouldFailExpectRevertDidNotRevert() ([GAS])
[FAIL: Error != expected error: but reverts with this message != should revert with this message] testShouldFailExpectRevertErrorDoesNotMatch() ([GAS])
[FAIL: revert: some message] testShouldFailexpectCheatcodeRevertForCreate() ([GAS])
[FAIL: revert: revert] testShouldFailexpectCheatcodeRevertForExtCall() ([GAS])
Suite result: FAILED. 0 passed; 6 failed; 0 skipped; [ELAPSED]
...
"#,
);

cmd.forge_fuse()
.args(["test", "--mc", "ExpectRevertWithReverterFailureTest"])
.assert_failure()
.stdout_eq(
r#"No files changed, compilation skipped
...
[FAIL: next call did not revert as expected] testShouldFailExpectRevertsNotOnImmediateNextCall() ([GAS])
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; [ELAPSED]
...
"#,
);

cmd.forge_fuse()
.args(["test", "--mc", "ExpectRevertCountFailureTest"])
.assert_failure()
.stdout_eq(
r#"No files changed, compilation skipped
...
[FAIL: call reverted when it was expected not to revert] testShouldFailNoRevert() ([GAS])
[FAIL: expected 0 reverts with reason: revert, but got one] testShouldFailNoRevertSpecific() ([GAS])
[FAIL: Error != expected error: second-revert != revert] testShouldFailReverCountSpecifc() ([GAS])
[FAIL: next call did not revert as expected] testShouldFailRevertCountAny() ([GAS])
[FAIL: Error != expected error: wrong revert != called a function and then reverted] testShouldFailRevertCountCallsThenReverts() ([GAS])
Suite result: FAILED. 0 passed; 5 failed; 0 skipped; [ELAPSED]
...
"#,
);

cmd.forge_fuse()
.args(["test", "--mc", "ExpectRevertCountWithReverterFailures"])
.assert_failure()
.stdout_eq(r#"No files changed, compilation skipped
...
[FAIL: expected 0 reverts from address: 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f, but got one] testShouldFailNoRevertWithReverter() ([GAS])
[FAIL: Reverter != expected reverter: 0x2e234DAe75C793f67A35089C9d99245E1C58470b != 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f] testShouldFailRevertCountWithReverter() ([GAS])
[FAIL: Error != expected error: wrong revert != revert] testShouldFailReverterCountWithWrongData() ([GAS])
[FAIL: Reverter != expected reverter: 0x2e234DAe75C793f67A35089C9d99245E1C58470b != 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f] testShouldFailWrongReverterCountWithData() ([GAS])
Suite result: FAILED. 0 passed; 4 failed; 0 skipped; [ELAPSED]
...
"#);
});
Loading
Loading