File tree 3 files changed +42
-1
lines changed
3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -765,6 +765,8 @@ pub struct TestSetup {
765
765
pub reason : Option < String > ,
766
766
/// Whether setup and entire test suite is skipped.
767
767
pub skipped : bool ,
768
+ /// Whether the test failed to deploy.
769
+ pub deployment_failure : bool ,
768
770
}
769
771
770
772
impl TestSetup {
Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ impl<'a> ContractRunner<'a> {
158
158
U256 :: ZERO ,
159
159
Some ( & self . mcr . revert_decoder ) ,
160
160
) ;
161
+
162
+ result. deployment_failure = deploy_result. is_err ( ) ;
163
+
161
164
if let Ok ( dr) = & deploy_result {
162
165
debug_assert_eq ! ( dr. address, address) ;
163
166
}
@@ -340,9 +343,14 @@ impl<'a> ContractRunner<'a> {
340
343
341
344
if setup. reason . is_some ( ) {
342
345
// The setup failed, so we return a single test result for `setUp`
346
+ let fail_msg = if !setup. deployment_failure {
347
+ "setUp()" . to_string ( )
348
+ } else {
349
+ "constructor()" . to_string ( )
350
+ } ;
343
351
return SuiteResult :: new (
344
352
start. elapsed ( ) ,
345
- [ ( "setUp()" . to_string ( ) , TestResult :: setup_result ( setup) ) ] . into ( ) ,
353
+ [ ( fail_msg , TestResult :: setup_result ( setup) ) ] . into ( ) ,
346
354
warnings,
347
355
)
348
356
}
Original file line number Diff line number Diff line change @@ -3137,3 +3137,34 @@ Encountered a total of 1 failing tests, 1 tests succeeded
3137
3137
3138
3138
"# ] ] ) ;
3139
3139
} ) ;
3140
+
3141
+ forgetest_init ! ( catch_test_deployment_failure, |prj, cmd| {
3142
+ prj. add_test(
3143
+ "TestDeploymentFailure.t.sol" ,
3144
+ r#"
3145
+ import "forge-std/Test.sol";
3146
+ contract TestDeploymentFailure is Test {
3147
+
3148
+ constructor() {
3149
+ require(false);
3150
+ }
3151
+
3152
+ function setUp() public {
3153
+ require(true);
3154
+ }
3155
+
3156
+ function test_something() public {
3157
+ require(1 == 1);
3158
+ }
3159
+ }
3160
+ "# ,
3161
+ )
3162
+ . unwrap( ) ;
3163
+
3164
+ cmd. args( [ "t" , "--mt" , "test_something" ] ) . assert_failure( ) . stdout_eq( str ![ [ r#"
3165
+ ...
3166
+ Failing tests:
3167
+ Encountered 1 failing test in test/TestDeploymentFailure.t.sol:TestDeploymentFailure
3168
+ [FAIL: EvmError: Revert] constructor() ([GAS])
3169
+ ..."# ] ] ) ;
3170
+ } ) ;
You can’t perform that action at this time.
0 commit comments