File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -765,6 +765,8 @@ pub struct TestSetup {
765765 pub reason : Option < String > ,
766766 /// Whether setup and entire test suite is skipped.
767767 pub skipped : bool ,
768+ /// Whether the test failed to deploy.
769+ pub deployment_failure : bool ,
768770}
769771
770772impl TestSetup {
Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ impl<'a> ContractRunner<'a> {
158158 U256 :: ZERO ,
159159 Some ( & self . mcr . revert_decoder ) ,
160160 ) ;
161+
162+ result. deployment_failure = deploy_result. is_err ( ) ;
163+
161164 if let Ok ( dr) = & deploy_result {
162165 debug_assert_eq ! ( dr. address, address) ;
163166 }
@@ -340,9 +343,14 @@ impl<'a> ContractRunner<'a> {
340343
341344 if setup. reason . is_some ( ) {
342345 // 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+ } ;
343351 return SuiteResult :: new (
344352 start. elapsed ( ) ,
345- [ ( "setUp()" . to_string ( ) , TestResult :: setup_result ( setup) ) ] . into ( ) ,
353+ [ ( fail_msg , TestResult :: setup_result ( setup) ) ] . into ( ) ,
346354 warnings,
347355 )
348356 }
Original file line number Diff line number Diff line change @@ -3137,3 +3137,34 @@ Encountered a total of 1 failing tests, 1 tests succeeded
31373137
31383138"# ] ] ) ;
31393139} ) ;
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