@@ -112,14 +112,8 @@ impl Diff {
112
112
let ( expected_name, actual_name, output, actual) = self . run_common ( ) ;
113
113
114
114
if !output. is_empty ( ) {
115
- // If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
116
- // environment variable set), then we write into the file and return.
117
- if let Some ( ref expected_file) = self . expected_file {
118
- if std:: env:: var ( "RUSTC_BLESS_TEST" ) . is_ok ( ) {
119
- println ! ( "Blessing `{}`" , expected_file. display( ) ) ;
120
- fs:: write ( expected_file, actual) ;
121
- return ;
122
- }
115
+ if self . maybe_bless_expected_file ( & actual) {
116
+ return ;
123
117
}
124
118
panic ! (
125
119
"test failed: `{}` is different from `{}`\n \n {}" ,
@@ -134,19 +128,28 @@ impl Diff {
134
128
let ( expected_name, actual_name, output, actual) = self . run_common ( ) ;
135
129
136
130
if output. is_empty ( ) {
137
- // If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
138
- // environment variable set), then we write into the file and return.
139
- if let Some ( ref expected_file) = self . expected_file {
140
- if std:: env:: var ( "RUSTC_BLESS_TEST" ) . is_ok ( ) {
141
- println ! ( "Blessing `{}`" , expected_file. display( ) ) ;
142
- fs:: write ( expected_file, actual) ;
143
- return ;
144
- }
131
+ if self . maybe_bless_expected_file ( & actual) {
132
+ return ;
145
133
}
146
134
panic ! (
147
135
"test failed: `{}` is not different from `{}`\n \n {}" ,
148
136
expected_name, actual_name, output
149
137
)
150
138
}
151
139
}
140
+
141
+ /// If we have an expected file to write into, and `RUSTC_BLESS_TEST` is
142
+ /// set, then write the actual output into the file and return `true`.
143
+ fn maybe_bless_expected_file ( & self , actual : & str ) -> bool {
144
+ let Some ( ref expected_file) = self . expected_file else {
145
+ return false ;
146
+ } ;
147
+ if std:: env:: var ( "RUSTC_BLESS_TEST" ) . is_err ( ) {
148
+ return false ;
149
+ }
150
+
151
+ println ! ( "Blessing `{}`" , expected_file. display( ) ) ;
152
+ fs:: write ( expected_file, actual) ;
153
+ true
154
+ }
152
155
}
0 commit comments