@@ -109,14 +109,13 @@ fn compare_generated_header(header: &PathBuf, builder: Builder) -> Result<(), Er
109
109
expectation. pop ( ) ;
110
110
expectation. push ( "expectations" ) ;
111
111
expectation. push ( "tests" ) ;
112
- expectation. push ( file_name) ;
113
- expectation. set_extension ( "rs" ) ;
114
112
115
- // If the expectation file doesn't exist, see if we have different test
116
- // expectations for different libclang versions.
117
- if !expectation. is_file ( ) {
118
- let file_name = expectation. file_name ( ) . unwrap ( ) . to_owned ( ) ;
119
- expectation. pop ( ) ;
113
+ let mut looked_at = vec ! [ ] ;
114
+ let mut expectation_file;
115
+
116
+ // Try more specific expectations first.
117
+ {
118
+ let mut expectation = expectation. clone ( ) ;
120
119
121
120
if cfg ! ( feature = "testing_only_libclang_4" ) {
122
121
expectation. push ( "libclang-4" ) ;
@@ -144,17 +143,32 @@ fn compare_generated_header(header: &PathBuf, builder: Builder) -> Result<(), Er
144
143
}
145
144
146
145
expectation. push ( file_name) ;
146
+ expectation. set_extension ( "rs" ) ;
147
+ expectation_file = fs:: File :: open ( & expectation) . ok ( ) ;
148
+ looked_at. push ( expectation) ;
149
+ }
147
150
148
- if !expectation. is_file ( ) {
149
- panic ! (
150
- "missing test expectation file and/or 'testing_only_libclang_$VERSION' \
151
- feature for header '{}'; looking for expectation file at '{}'",
152
- header. display( ) ,
153
- expectation. display( )
154
- ) ;
155
- }
151
+ // Try the default path otherwise.
152
+ if expectation_file. is_none ( ) {
153
+ expectation. push ( file_name) ;
154
+ expectation. set_extension ( "rs" ) ;
155
+ expectation_file = fs:: File :: open ( & expectation) . ok ( ) ;
156
+ looked_at. push ( expectation) ;
156
157
}
157
158
159
+ let mut expected = String :: new ( ) ;
160
+ match expectation_file {
161
+ Some ( f) => {
162
+ BufReader :: new ( f) . read_to_string ( & mut expected) ?;
163
+ }
164
+ None => panic ! (
165
+ "missing test expectation file and/or 'testing_only_libclang_$VERSION' \
166
+ feature for header '{}'; looking for expectation file at '{:?}'",
167
+ header. display( ) ,
168
+ looked_at,
169
+ ) ,
170
+ } ;
171
+
158
172
// We skip the generate() error here so we get a full diff below
159
173
let ( actual, rustfmt_stderr) = match builder. generate ( ) {
160
174
Ok ( bindings) => {
@@ -165,13 +179,6 @@ fn compare_generated_header(header: &PathBuf, builder: Builder) -> Result<(), Er
165
179
} ;
166
180
println ! ( "{}" , rustfmt_stderr) ;
167
181
168
- let mut expected = String :: new ( ) ;
169
- {
170
- if let Ok ( expectation_file) = fs:: File :: open ( & expectation) {
171
- BufReader :: new ( expectation_file) . read_to_string ( & mut expected) ?;
172
- }
173
- }
174
-
175
182
let ( expected, rustfmt_stderr) = rustfmt ( expected) ;
176
183
println ! ( "{}" , rustfmt_stderr) ;
177
184
@@ -188,7 +195,7 @@ fn compare_generated_header(header: &PathBuf, builder: Builder) -> Result<(), Er
188
195
println ! ( "{}" , rustfmt_stderr) ;
189
196
190
197
println ! ( "diff expected generated" ) ;
191
- println ! ( "--- expected: {:?}" , expectation ) ;
198
+ println ! ( "--- expected: {:?}" , looked_at . last ( ) . unwrap ( ) ) ;
192
199
println ! ( "+++ generated from: {:?}" , header) ;
193
200
194
201
for diff in diff:: lines ( & expected, & actual) {
@@ -201,7 +208,7 @@ fn compare_generated_header(header: &PathBuf, builder: Builder) -> Result<(), Er
201
208
202
209
// Overwrite the expectation with actual output.
203
210
if env:: var_os ( OVERWRITE_ENV_VAR ) . is_some ( ) {
204
- let mut expectation_file = fs:: File :: create ( & expectation ) ?;
211
+ let mut expectation_file = fs:: File :: create ( looked_at . last ( ) . unwrap ( ) ) ?;
205
212
expectation_file. write_all ( actual. as_bytes ( ) ) ?;
206
213
}
207
214
0 commit comments