From 5a8bd893eeeeb9489ea66dd52a02eeaa580e3af0 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Thu, 19 Dec 2024 18:59:08 +0200 Subject: [PATCH] chore: testFail* deprecation warning (#9581) * chore: testFail* deprecation warning * test * fix --- crates/forge/src/runner.rs | 17 +++++++++++++++++ crates/forge/tests/cli/test_cmd.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/crates/forge/src/runner.rs b/crates/forge/src/runner.rs index 7b1293a72824..467f1acd6bc1 100644 --- a/crates/forge/src/runner.rs +++ b/crates/forge/src/runner.rs @@ -402,6 +402,23 @@ impl<'a> ContractRunner<'a> { .collect::>(); 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::>() + .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) } } diff --git a/crates/forge/tests/cli/test_cmd.rs b/crates/forge/tests/cli/test_cmd.rs index e8da6a49035a..20f865fc9e6c 100644 --- a/crates/forge/tests/cli/test_cmd.rs +++ b/crates/forge/tests/cli/test_cmd.rs @@ -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. +"#); +});