@@ -3238,17 +3238,35 @@ impl<'test> TestCx<'test> {
3238
3238
match output_kind {
3239
3239
TestOutput :: Compile => {
3240
3240
if !self . props . dont_check_compiler_stdout {
3241
- errors +=
3242
- self . compare_output ( stdout_kind, & normalized_stdout, & expected_stdout) ;
3241
+ errors += self . compare_output (
3242
+ stdout_kind,
3243
+ & normalized_stdout,
3244
+ & expected_stdout,
3245
+ self . props . compare_output_lines_by_subset ,
3246
+ ) ;
3243
3247
}
3244
3248
if !self . props . dont_check_compiler_stderr {
3245
- errors +=
3246
- self . compare_output ( stderr_kind, & normalized_stderr, & expected_stderr) ;
3249
+ errors += self . compare_output (
3250
+ stderr_kind,
3251
+ & normalized_stderr,
3252
+ & expected_stderr,
3253
+ self . props . compare_output_lines_by_subset ,
3254
+ ) ;
3247
3255
}
3248
3256
}
3249
3257
TestOutput :: Run => {
3250
- errors += self . compare_output ( stdout_kind, & normalized_stdout, & expected_stdout) ;
3251
- errors += self . compare_output ( stderr_kind, & normalized_stderr, & expected_stderr) ;
3258
+ errors += self . compare_output (
3259
+ stdout_kind,
3260
+ & normalized_stdout,
3261
+ & expected_stdout,
3262
+ self . props . compare_output_lines_by_subset ,
3263
+ ) ;
3264
+ errors += self . compare_output (
3265
+ stderr_kind,
3266
+ & normalized_stderr,
3267
+ & expected_stderr,
3268
+ self . props . compare_output_lines_by_subset ,
3269
+ ) ;
3252
3270
}
3253
3271
}
3254
3272
errors
@@ -3332,7 +3350,12 @@ impl<'test> TestCx<'test> {
3332
3350
)
3333
3351
} ) ;
3334
3352
3335
- errors += self . compare_output ( "fixed" , & fixed_code, & expected_fixed) ;
3353
+ errors += self . compare_output (
3354
+ "fixed" ,
3355
+ & fixed_code,
3356
+ & expected_fixed,
3357
+ self . props . compare_output_lines_by_subset ,
3358
+ ) ;
3336
3359
} else if !expected_fixed. is_empty ( ) {
3337
3360
panic ! (
3338
3361
"the `// run-rustfix` directive wasn't found but a `*.fixed` \
@@ -3790,11 +3813,38 @@ impl<'test> TestCx<'test> {
3790
3813
}
3791
3814
}
3792
3815
3793
- fn compare_output ( & self , kind : & str , actual : & str , expected : & str ) -> usize {
3816
+ fn compare_output (
3817
+ & self ,
3818
+ kind : & str ,
3819
+ actual : & str ,
3820
+ expected : & str ,
3821
+ compare_output_by_lines : bool ,
3822
+ ) -> usize {
3794
3823
if actual == expected {
3795
3824
return 0 ;
3796
3825
}
3797
3826
3827
+ let tmp;
3828
+ let ( expected, actual) : ( & str , & str ) = if compare_output_by_lines {
3829
+ let actual_lines: HashSet < _ > = actual. lines ( ) . collect ( ) ;
3830
+ let expected_lines: Vec < _ > = expected. lines ( ) . collect ( ) ;
3831
+ let mut used = expected_lines. clone ( ) ;
3832
+ used. retain ( |line| actual_lines. contains ( line) ) ;
3833
+ // check if `expected` contains a subset of the lines of `actual`
3834
+ if used. len ( ) == expected_lines. len ( ) && ( expected. is_empty ( ) == actual. is_empty ( ) ) {
3835
+ return 0 ;
3836
+ }
3837
+ if expected_lines. is_empty ( ) {
3838
+ // if we have no lines to check, force a full overwite
3839
+ ( "" , actual)
3840
+ } else {
3841
+ tmp = ( expected_lines. join ( "\n " ) , used. join ( "\n " ) ) ;
3842
+ ( & tmp. 0 , & tmp. 1 )
3843
+ }
3844
+ } else {
3845
+ ( expected, actual)
3846
+ } ;
3847
+
3798
3848
if !self . config . bless {
3799
3849
if expected. is_empty ( ) {
3800
3850
println ! ( "normalized {}:\n {}\n " , kind, actual) ;
0 commit comments