@@ -289,9 +289,9 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
289
289
was_expected = true ;
290
290
}
291
291
292
- if !was_expected && ( str :: contains ( line, ~"error" ) ||
293
- str :: contains ( line , ~"warning" ) ) {
294
- fatal_procres ( fmt ! ( "unexpected error pattern '%s'!" , line) ,
292
+ if !was_expected && is_compiler_error_or_warning ( line) {
293
+ fatal_procres ( fmt ! ( "unexpected compiler error or warning: '%s'" ,
294
+ line) ,
295
295
procres) ;
296
296
}
297
297
}
@@ -305,6 +305,81 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
305
305
}
306
306
}
307
307
308
+ fn is_compiler_error_or_warning ( line : ~str ) -> bool {
309
+ let mut i = 0 u;
310
+ return
311
+ scan_until_char ( line, ':' , & mut i) &&
312
+ scan_char ( line, ':' , & mut i) &&
313
+ scan_integer ( line, & mut i) &&
314
+ scan_char ( line, ':' , & mut i) &&
315
+ scan_integer ( line, & mut i) &&
316
+ scan_char ( line, ':' , & mut i) &&
317
+ scan_char ( line, ' ' , & mut i) &&
318
+ scan_integer ( line, & mut i) &&
319
+ scan_char ( line, ':' , & mut i) &&
320
+ scan_integer ( line, & mut i) &&
321
+ scan_char ( line, ' ' , & mut i) &&
322
+ ( scan_string ( line, ~"error", & mut i) ||
323
+ scan_string ( line, ~"warning", & mut i) ) ;
324
+ }
325
+
326
+ fn scan_until_char ( haystack : ~str , needle : char , idx : & mut uint ) -> bool {
327
+ if * idx >= haystack. len ( ) {
328
+ return false ;
329
+ }
330
+ let opt = str:: find_char_from ( haystack, needle, * idx) ;
331
+ if opt. is_none ( ) {
332
+ return false ;
333
+ }
334
+ * idx = opt. get ( ) ;
335
+ return true ;
336
+ }
337
+
338
+ fn scan_char ( haystack : ~str , needle : char , idx : & mut uint ) -> bool {
339
+ if * idx >= haystack. len ( ) {
340
+ return false ;
341
+ }
342
+ let { ch, next} = str:: char_range_at ( haystack, * idx) ;
343
+ if ch != needle {
344
+ return false ;
345
+ }
346
+ * idx = next;
347
+ return true ;
348
+ }
349
+
350
+ fn scan_integer ( haystack : ~str , idx : & mut uint ) -> bool {
351
+ let mut i = * idx;
352
+ while i < haystack. len ( ) {
353
+ let { ch, next} = str:: char_range_at ( haystack, i) ;
354
+ if ch < '0' || '9' < ch {
355
+ break ;
356
+ }
357
+ i = next;
358
+ }
359
+ if i == * idx {
360
+ return false ;
361
+ }
362
+ * idx = i;
363
+ return true ;
364
+ }
365
+
366
+ fn scan_string ( haystack : ~str , needle : ~str , idx : & mut uint ) -> bool {
367
+ let mut haystack_i = * idx;
368
+ let mut needle_i = 0 u;
369
+ while needle_i < needle. len ( ) {
370
+ if haystack_i >= haystack. len ( ) {
371
+ return false ;
372
+ }
373
+ let { ch, next} = str:: char_range_at ( haystack, haystack_i) ;
374
+ haystack_i = next;
375
+ if !scan_char ( needle, ch, & mut needle_i) {
376
+ return false ;
377
+ }
378
+ }
379
+ * idx = haystack_i;
380
+ return true ;
381
+ }
382
+
308
383
type procargs = { prog : ~str , args : ~[ ~str ] } ;
309
384
310
385
type procres = { status : int , stdout : ~str , stderr : ~str , cmdline : ~str } ;
0 commit comments