@@ -87,9 +87,7 @@ impl Diff {
8787 self
8888 }
8989
90- #[ track_caller]
91- pub fn run ( & mut self ) {
92- self . drop_bomb . defuse ( ) ;
90+ fn run_common ( & self ) -> ( & str , & str , String , String ) {
9391 let expected = self . expected . as_ref ( ) . expect ( "expected text not set" ) ;
9492 let mut actual = self . actual . as_ref ( ) . expect ( "actual text not set" ) . to_string ( ) ;
9593 let expected_name = self . expected_name . as_ref ( ) . unwrap ( ) ;
@@ -104,6 +102,14 @@ impl Diff {
104102 . header ( expected_name, actual_name)
105103 . to_string ( ) ;
106104
105+ ( expected_name, actual_name, output, actual)
106+ }
107+
108+ #[ track_caller]
109+ pub fn run ( & mut self ) {
110+ self . drop_bomb . defuse ( ) ;
111+ let ( expected_name, actual_name, output, actual) = self . run_common ( ) ;
112+
107113 if !output. is_empty ( ) {
108114 // If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
109115 // environment variable set), then we write into the file and return.
@@ -120,4 +126,26 @@ impl Diff {
120126 )
121127 }
122128 }
129+
130+ #[ track_caller]
131+ pub fn run_fail ( & mut self ) {
132+ self . drop_bomb . defuse ( ) ;
133+ let ( expected_name, actual_name, output, actual) = self . run_common ( ) ;
134+
135+ if output. is_empty ( ) {
136+ // If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
137+ // environment variable set), then we write into the file and return.
138+ if let Some ( ref expected_file) = self . expected_file {
139+ if std:: env:: var ( "RUSTC_BLESS_TEST" ) . is_ok ( ) {
140+ println ! ( "Blessing `{}`" , expected_file. display( ) ) ;
141+ fs_wrapper:: write ( expected_file, actual) ;
142+ return ;
143+ }
144+ }
145+ panic ! (
146+ "test failed: `{}` is not different from `{}`\n \n {}" ,
147+ expected_name, actual_name, output
148+ )
149+ }
150+ }
123151}
0 commit comments