@@ -42,7 +42,16 @@ fn run_cfail_test(cx: cx, props: test_props, testfile: str) {
42
42
}
43
43
44
44
check_correct_failure_status ( procres) ;
45
- check_error_patterns ( props, testfile, procres) ;
45
+
46
+ let expected_errors = errors:: load_errors ( testfile) ;
47
+ if vec:: is_not_empty ( expected_errors) {
48
+ if vec:: is_not_empty ( props. error_patterns ) {
49
+ fatal ( "both error pattern and expected errors specified" ) ;
50
+ }
51
+ check_expected_errors ( expected_errors, testfile, procres) ;
52
+ } else {
53
+ check_error_patterns ( props, testfile, procres) ;
54
+ }
46
55
}
47
56
48
57
fn run_rfail_test ( cx : cx , props : test_props , testfile : str ) {
@@ -181,7 +190,9 @@ actual:\n\
181
190
}
182
191
}
183
192
184
- fn check_error_patterns ( props : test_props , testfile : str , procres : procres ) {
193
+ fn check_error_patterns ( props : test_props ,
194
+ testfile : str ,
195
+ procres : procres ) {
185
196
if vec:: is_empty ( props. error_patterns ) {
186
197
fatal ( "no error pattern specified in " + testfile) ;
187
198
}
@@ -218,6 +229,60 @@ fn check_error_patterns(props: test_props, testfile: str, procres: procres) {
218
229
}
219
230
}
220
231
232
+ fn check_expected_errors ( expected_errors : [ errors:: expected_error ] ,
233
+ testfile : str ,
234
+ procres : procres ) {
235
+
236
+ // true if we found the error in question
237
+ let found_flags = vec:: init_elt_mut ( false , vec:: len ( expected_errors) ) ;
238
+
239
+ if procres. status == 0 {
240
+ fatal ( "process did not return an error status" ) ;
241
+ }
242
+
243
+ // Scan and extract our error/warning messages,
244
+ // which look like:
245
+ // filename:line1:col1: line2:col2: *error:* msg
246
+ // filename:line1:col1: line2:col2: *warning:* msg
247
+ // where line1:col1: is the starting point, line2:col2:
248
+ // is the ending point, and * represents ANSI color codes.
249
+ for line: str in str:: split ( procres. stdout , '\n' as u8 ) {
250
+ let was_expected = false ;
251
+ vec:: iteri ( expected_errors) { |i, ee|
252
+ if !found_flags[ i] {
253
+ let needle = #fmt ( "%s:%u:" , testfile, ee. line ) ;
254
+ #debug[ "needle=%s ee.kind=%s ee.msg=%s line=%s" ,
255
+ needle, ee. kind , ee. msg , line] ;
256
+ if ( str:: contains ( line, needle) &&
257
+ str:: contains ( line, ee. kind ) &&
258
+ str:: contains ( line, ee. msg ) ) {
259
+ found_flags[ i] = true ;
260
+ was_expected = true ;
261
+ }
262
+ }
263
+ }
264
+
265
+ // ignore this msg which gets printed at the end
266
+ if str:: contains ( line, "aborting due to previous errors" ) {
267
+ was_expected = true ;
268
+ }
269
+
270
+ if !was_expected && ( str:: contains ( line, "error" ) ||
271
+ str:: contains ( line, "warning" ) ) {
272
+ fatal_procres ( #fmt[ "unexpected error pattern '%s'!" , line] ,
273
+ procres) ;
274
+ }
275
+ }
276
+
277
+ uint:: range ( 0 u, vec:: len ( found_flags) ) { |i|
278
+ if !found_flags[ i] {
279
+ let ee = expected_errors[ i] ;
280
+ fatal_procres ( #fmt[ "expected %s on line %u not found: %s" ,
281
+ ee. kind , ee. line , ee. msg ] , procres) ;
282
+ }
283
+ }
284
+ }
285
+
221
286
type procargs = { prog: str , args: [ str] } ;
222
287
223
288
type procres = { status : int , stdout : str , stderr : str , cmdline : str } ;
0 commit comments