Skip to content

Commit

Permalink
chore: testFail* deprecation warning (#9581)
Browse files Browse the repository at this point in the history
* chore: testFail* deprecation warning

* test

* fix
  • Loading branch information
yash-atreya authored Dec 19, 2024
1 parent 7ac0502 commit 5a8bd89
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ impl<'a> ContractRunner<'a> {
.collect::<BTreeMap<_, _>>();

let duration = start.elapsed();
let test_fail_deprecations = self
.contract
.abi
.functions()
.filter_map(|func| {
TestFunctionKind::classify(&func.name, !func.inputs.is_empty())
.is_any_test_fail()
.then_some(func.name.clone())
})
.collect::<Vec<_>>()
.join(", ");

if !test_fail_deprecations.is_empty() {
warnings.push(format!(
"`testFail*` has been deprecated and will be removed in the next release. Consider changing to test_Revert[If|When]_Condition and expecting a revert. Found deprecated testFail* function(s): {test_fail_deprecations}.",
));
}
SuiteResult::new(duration, test_results, warnings)
}
}
Expand Down
27 changes: 27 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,30 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
"#]],
);
});

forgetest!(test_fail_deprecation_warning, |prj, cmd| {
prj.insert_ds_test();

prj.add_source(
"WarnDeprecationTestFail.t.sol",
r#"
import "./test.sol";
contract WarnDeprecationTestFail is DSTest {
function testFail_deprecated() public {
revert("deprecated");
}
function testFail_deprecated2() public {
revert("deprecated2");
}
}
"#,
)
.unwrap();

cmd.forge_fuse()
.args(["test", "--mc", "WarnDeprecationTestFail"])
.assert_success()
.stderr_eq(r#"Warning: `testFail*` has been deprecated and will be removed in the next release. Consider changing to test_Revert[If|When]_Condition and expecting a revert. Found deprecated testFail* function(s): testFail_deprecated, testFail_deprecated2.
"#);
});

0 comments on commit 5a8bd89

Please sign in to comment.