@@ -211,6 +211,9 @@ pub struct TestProps {
211
211
// The test must be compiled and run successfully. Only used in UI tests for
212
212
// now.
213
213
pub run_pass : bool ,
214
+ // customized normalization rules
215
+ pub normalize_stdout : Vec < ( String , String ) > ,
216
+ pub normalize_stderr : Vec < ( String , String ) > ,
214
217
}
215
218
216
219
impl TestProps {
@@ -237,6 +240,8 @@ impl TestProps {
237
240
must_compile_successfully : false ,
238
241
check_test_line_numbers_match : false ,
239
242
run_pass : false ,
243
+ normalize_stdout : vec ! [ ] ,
244
+ normalize_stderr : vec ! [ ] ,
240
245
}
241
246
}
242
247
@@ -351,6 +356,13 @@ impl TestProps {
351
356
if !self . run_pass {
352
357
self . run_pass = config. parse_run_pass ( ln) ;
353
358
}
359
+
360
+ if let Some ( rule) = config. parse_custom_normalization ( ln, "normalize-stdout" ) {
361
+ self . normalize_stdout . push ( rule) ;
362
+ }
363
+ if let Some ( rule) = config. parse_custom_normalization ( ln, "normalize-stderr" ) {
364
+ self . normalize_stderr . push ( rule) ;
365
+ }
354
366
} ) ;
355
367
356
368
for key in & [ "RUST_TEST_NOCAPTURE" , "RUST_TEST_THREADS" ] {
@@ -399,7 +411,6 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
399
411
}
400
412
401
413
impl Config {
402
-
403
414
fn parse_error_pattern ( & self , line : & str ) -> Option < String > {
404
415
self . parse_name_value_directive ( line, "error-pattern" )
405
416
}
@@ -497,6 +508,22 @@ impl Config {
497
508
}
498
509
}
499
510
511
+ fn parse_custom_normalization ( & self , mut line : & str , prefix : & str ) -> Option < ( String , String ) > {
512
+ if self . parse_cfg_name_directive ( line, prefix) {
513
+ let from = match parse_normalization_string ( & mut line) {
514
+ Some ( s) => s,
515
+ None => return None ,
516
+ } ;
517
+ let to = match parse_normalization_string ( & mut line) {
518
+ Some ( s) => s,
519
+ None => return None ,
520
+ } ;
521
+ Some ( ( from, to) )
522
+ } else {
523
+ None
524
+ }
525
+ }
526
+
500
527
/// Parses a name-value directive which contains config-specific information, e.g. `ignore-x86`
501
528
/// or `normalize-stderr-32bit`. Returns `true` if the line matches it.
502
529
fn parse_cfg_name_directive ( & self , line : & str , prefix : & str ) -> bool {
@@ -568,3 +595,29 @@ fn expand_variables(mut value: String, config: &Config) -> String {
568
595
569
596
value
570
597
}
598
+
599
+ /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line`
600
+ /// variable after the end of the quoted string.
601
+ ///
602
+ /// # Examples
603
+ ///
604
+ /// ```
605
+ /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
606
+ /// let first = parse_normalization_string(&mut s);
607
+ /// assert_eq!(first, Some("something (32 bits)".to_owned()));
608
+ /// assert_eq!(s, " -> \"something ($WORD bits)\".");
609
+ /// ```
610
+ fn parse_normalization_string ( line : & mut & str ) -> Option < String > {
611
+ // FIXME support escapes in strings.
612
+ let begin = match line. find ( '"' ) {
613
+ Some ( i) => i + 1 ,
614
+ None => return None ,
615
+ } ;
616
+ let end = match line[ begin..] . find ( '"' ) {
617
+ Some ( i) => i + begin,
618
+ None => return None ,
619
+ } ;
620
+ let result = line[ begin..end] . to_owned ( ) ;
621
+ * line = & line[ end+1 ..] ;
622
+ Some ( result)
623
+ }
0 commit comments