@@ -24,6 +24,7 @@ enum ParsedNameDirective {
24
24
25
25
/// Properties which must be known very early, before actually running
26
26
/// the test.
27
+ #[ derive( Default ) ]
27
28
pub struct EarlyProps {
28
29
pub ignore : bool ,
29
30
pub should_fail : bool ,
@@ -34,18 +35,16 @@ pub struct EarlyProps {
34
35
35
36
impl EarlyProps {
36
37
pub fn from_file ( config : & Config , testfile : & Path ) -> Self {
37
- let mut props = EarlyProps {
38
- ignore : false ,
39
- should_fail : false ,
40
- aux : Vec :: new ( ) ,
41
- aux_crate : Vec :: new ( ) ,
42
- revisions : vec ! [ ] ,
43
- } ;
38
+ let file = File :: open ( testfile) . unwrap ( ) ;
39
+ Self :: from_reader ( config, testfile, file)
40
+ }
44
41
42
+ pub fn from_reader < R : Read > ( config : & Config , testfile : & Path , rdr : R ) -> Self {
43
+ let mut props = EarlyProps :: default ( ) ;
45
44
let rustc_has_profiler_support = env:: var_os ( "RUSTC_PROFILER_SUPPORT" ) . is_some ( ) ;
46
45
let rustc_has_sanitizer_support = env:: var_os ( "RUSTC_SANITIZER_SUPPORT" ) . is_some ( ) ;
47
46
48
- iter_header ( testfile, None , & mut |ln| {
47
+ iter_header ( testfile, None , rdr , & mut |ln| {
49
48
// we should check if any only-<platform> exists and if it exists
50
49
// and does not matches the current platform, skip the test
51
50
if !props. ignore {
@@ -392,138 +391,143 @@ impl TestProps {
392
391
/// `//[foo]`), then the property is ignored unless `cfg` is
393
392
/// `Some("foo")`.
394
393
fn load_from ( & mut self , testfile : & Path , cfg : Option < & str > , config : & Config ) {
395
- iter_header ( testfile, cfg, & mut |ln| {
396
- if let Some ( ep) = config. parse_error_pattern ( ln) {
397
- self . error_patterns . push ( ep) ;
398
- }
394
+ if !testfile. is_dir ( ) {
395
+ let file = File :: open ( testfile) . unwrap ( ) ;
399
396
400
- if let Some ( flags) = config. parse_compile_flags ( ln) {
401
- self . compile_flags . extend ( flags. split_whitespace ( ) . map ( |s| s. to_owned ( ) ) ) ;
402
- }
397
+ iter_header ( testfile, cfg, file, & mut |ln| {
398
+ if let Some ( ep) = config. parse_error_pattern ( ln) {
399
+ self . error_patterns . push ( ep) ;
400
+ }
403
401
404
- if let Some ( edition ) = config. parse_edition ( ln) {
405
- self . compile_flags . push ( format ! ( "--edition={}" , edition ) ) ;
406
- }
402
+ if let Some ( flags ) = config. parse_compile_flags ( ln) {
403
+ self . compile_flags . extend ( flags . split_whitespace ( ) . map ( |s| s . to_owned ( ) ) ) ;
404
+ }
407
405
408
- if let Some ( r ) = config. parse_revisions ( ln) {
409
- self . revisions . extend ( r ) ;
410
- }
406
+ if let Some ( edition ) = config. parse_edition ( ln) {
407
+ self . compile_flags . push ( format ! ( "--edition={}" , edition ) ) ;
408
+ }
411
409
412
- if self . run_flags . is_none ( ) {
413
- self . run_flags = config . parse_run_flags ( ln ) ;
414
- }
410
+ if let Some ( r ) = config . parse_revisions ( ln ) {
411
+ self . revisions . extend ( r ) ;
412
+ }
415
413
416
- if self . pp_exact . is_none ( ) {
417
- self . pp_exact = config. parse_pp_exact ( ln, testfile ) ;
418
- }
414
+ if self . run_flags . is_none ( ) {
415
+ self . run_flags = config. parse_run_flags ( ln) ;
416
+ }
419
417
420
- if ! self . should_ice {
421
- self . should_ice = config. parse_should_ice ( ln) ;
422
- }
418
+ if self . pp_exact . is_none ( ) {
419
+ self . pp_exact = config. parse_pp_exact ( ln, testfile ) ;
420
+ }
423
421
424
- if !self . build_aux_docs {
425
- self . build_aux_docs = config. parse_build_aux_docs ( ln) ;
426
- }
422
+ if !self . should_ice {
423
+ self . should_ice = config. parse_should_ice ( ln) ;
424
+ }
427
425
428
- if !self . force_host {
429
- self . force_host = config. parse_force_host ( ln) ;
430
- }
426
+ if !self . build_aux_docs {
427
+ self . build_aux_docs = config. parse_build_aux_docs ( ln) ;
428
+ }
431
429
432
- if !self . check_stdout {
433
- self . check_stdout = config. parse_check_stdout ( ln) ;
434
- }
430
+ if !self . force_host {
431
+ self . force_host = config. parse_force_host ( ln) ;
432
+ }
435
433
436
- if !self . check_run_results {
437
- self . check_run_results = config. parse_check_run_results ( ln) ;
438
- }
434
+ if !self . check_stdout {
435
+ self . check_stdout = config. parse_check_stdout ( ln) ;
436
+ }
439
437
440
- if !self . dont_check_compiler_stdout {
441
- self . dont_check_compiler_stdout = config. parse_dont_check_compiler_stdout ( ln) ;
442
- }
438
+ if !self . check_run_results {
439
+ self . check_run_results = config. parse_check_run_results ( ln) ;
440
+ }
443
441
444
- if !self . dont_check_compiler_stderr {
445
- self . dont_check_compiler_stderr = config. parse_dont_check_compiler_stderr ( ln) ;
446
- }
442
+ if !self . dont_check_compiler_stdout {
443
+ self . dont_check_compiler_stdout = config. parse_dont_check_compiler_stdout ( ln) ;
444
+ }
447
445
448
- if !self . no_prefer_dynamic {
449
- self . no_prefer_dynamic = config. parse_no_prefer_dynamic ( ln) ;
450
- }
446
+ if !self . dont_check_compiler_stderr {
447
+ self . dont_check_compiler_stderr = config. parse_dont_check_compiler_stderr ( ln) ;
448
+ }
451
449
452
- if !self . pretty_expanded {
453
- self . pretty_expanded = config. parse_pretty_expanded ( ln) ;
454
- }
450
+ if !self . no_prefer_dynamic {
451
+ self . no_prefer_dynamic = config. parse_no_prefer_dynamic ( ln) ;
452
+ }
455
453
456
- if let Some ( m ) = config . parse_pretty_mode ( ln ) {
457
- self . pretty_mode = m ;
458
- }
454
+ if ! self . pretty_expanded {
455
+ self . pretty_expanded = config . parse_pretty_expanded ( ln ) ;
456
+ }
459
457
460
- if ! self . pretty_compare_only {
461
- self . pretty_compare_only = config . parse_pretty_compare_only ( ln ) ;
462
- }
458
+ if let Some ( m ) = config . parse_pretty_mode ( ln ) {
459
+ self . pretty_mode = m ;
460
+ }
463
461
464
- if let Some ( ab ) = config . parse_aux_build ( ln ) {
465
- self . aux_builds . push ( ab ) ;
466
- }
462
+ if ! self . pretty_compare_only {
463
+ self . pretty_compare_only = config . parse_pretty_compare_only ( ln ) ;
464
+ }
467
465
468
- if let Some ( ac ) = config. parse_aux_crate ( ln) {
469
- self . aux_crates . push ( ac ) ;
470
- }
466
+ if let Some ( ab ) = config. parse_aux_build ( ln) {
467
+ self . aux_builds . push ( ab ) ;
468
+ }
471
469
472
- if let Some ( ee ) = config. parse_env ( ln, "exec-env" ) {
473
- self . exec_env . push ( ee ) ;
474
- }
470
+ if let Some ( ac ) = config. parse_aux_crate ( ln) {
471
+ self . aux_crates . push ( ac ) ;
472
+ }
475
473
476
- if let Some ( ee) = config. parse_env ( ln, "rustc -env" ) {
477
- self . rustc_env . push ( ee) ;
478
- }
474
+ if let Some ( ee) = config. parse_env ( ln, "exec -env" ) {
475
+ self . exec_env . push ( ee) ;
476
+ }
479
477
480
- if let Some ( ev ) = config. parse_name_value_directive ( ln, "unset- rustc-env" ) {
481
- self . unset_rustc_env . push ( ev ) ;
482
- }
478
+ if let Some ( ee ) = config. parse_env ( ln, "rustc-env" ) {
479
+ self . rustc_env . push ( ee ) ;
480
+ }
483
481
484
- if let Some ( cl ) = config. parse_check_line ( ln) {
485
- self . check_lines . push ( cl ) ;
486
- }
482
+ if let Some ( ev ) = config. parse_name_value_directive ( ln, "unset-rustc-env" ) {
483
+ self . unset_rustc_env . push ( ev ) ;
484
+ }
487
485
488
- if let Some ( of ) = config. parse_forbid_output ( ln) {
489
- self . forbid_output . push ( of ) ;
490
- }
486
+ if let Some ( cl ) = config. parse_check_line ( ln) {
487
+ self . check_lines . push ( cl ) ;
488
+ }
491
489
492
- if ! self . check_test_line_numbers_match {
493
- self . check_test_line_numbers_match = config . parse_check_test_line_numbers_match ( ln ) ;
494
- }
490
+ if let Some ( of ) = config . parse_forbid_output ( ln ) {
491
+ self . forbid_output . push ( of ) ;
492
+ }
495
493
496
- self . update_pass_mode ( ln, cfg, config) ;
497
- self . update_fail_mode ( ln, config) ;
494
+ if !self . check_test_line_numbers_match {
495
+ self . check_test_line_numbers_match =
496
+ config. parse_check_test_line_numbers_match ( ln) ;
497
+ }
498
498
499
- if !self . ignore_pass {
500
- self . ignore_pass = config. parse_ignore_pass ( ln) ;
501
- }
499
+ self . update_pass_mode ( ln, cfg, config) ;
500
+ self . update_fail_mode ( ln, config) ;
502
501
503
- if let Some ( rule) = config. parse_custom_normalization ( ln, "normalize-stdout" ) {
504
- self . normalize_stdout . push ( rule) ;
505
- }
506
- if let Some ( rule) = config. parse_custom_normalization ( ln, "normalize-stderr" ) {
507
- self . normalize_stderr . push ( rule) ;
508
- }
502
+ if !self . ignore_pass {
503
+ self . ignore_pass = config. parse_ignore_pass ( ln) ;
504
+ }
509
505
510
- if let Some ( code) = config. parse_failure_status ( ln) {
511
- self . failure_status = code;
512
- }
506
+ if let Some ( rule) = config. parse_custom_normalization ( ln, "normalize-stdout" ) {
507
+ self . normalize_stdout . push ( rule) ;
508
+ }
509
+ if let Some ( rule) = config. parse_custom_normalization ( ln, "normalize-stderr" ) {
510
+ self . normalize_stderr . push ( rule) ;
511
+ }
513
512
514
- if ! self . run_rustfix {
515
- self . run_rustfix = config . parse_run_rustfix ( ln ) ;
516
- }
513
+ if let Some ( code ) = config . parse_failure_status ( ln ) {
514
+ self . failure_status = code ;
515
+ }
517
516
518
- if !self . rustfix_only_machine_applicable {
519
- self . rustfix_only_machine_applicable =
520
- config. parse_rustfix_only_machine_applicable ( ln) ;
521
- }
517
+ if !self . run_rustfix {
518
+ self . run_rustfix = config. parse_run_rustfix ( ln) ;
519
+ }
522
520
523
- if self . assembly_output . is_none ( ) {
524
- self . assembly_output = config. parse_assembly_output ( ln) ;
525
- }
526
- } ) ;
521
+ if !self . rustfix_only_machine_applicable {
522
+ self . rustfix_only_machine_applicable =
523
+ config. parse_rustfix_only_machine_applicable ( ln) ;
524
+ }
525
+
526
+ if self . assembly_output . is_none ( ) {
527
+ self . assembly_output = config. parse_assembly_output ( ln) ;
528
+ }
529
+ } ) ;
530
+ }
527
531
528
532
if self . failure_status == -1 {
529
533
self . failure_status = match config. mode {
@@ -617,7 +621,7 @@ impl TestProps {
617
621
}
618
622
}
619
623
620
- fn iter_header ( testfile : & Path , cfg : Option < & str > , it : & mut dyn FnMut ( & str ) ) {
624
+ fn iter_header < R : Read > ( testfile : & Path , cfg : Option < & str > , rdr : R , it : & mut dyn FnMut ( & str ) ) {
621
625
if testfile. is_dir ( ) {
622
626
return ;
623
627
}
@@ -628,12 +632,18 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
628
632
// It took me like 2 days to debug why compile-flags weren’t taken into account for my test :)
629
633
let comment_with_brace = comment. to_string ( ) + "[" ;
630
634
631
- let rdr = BufReader :: new ( File :: open ( testfile) . unwrap ( ) ) ;
632
- for ln in rdr. lines ( ) {
635
+ let mut rdr = BufReader :: new ( rdr) ;
636
+ let mut ln = String :: new ( ) ;
637
+
638
+ loop {
639
+ ln. clear ( ) ;
640
+ if rdr. read_line ( & mut ln) . unwrap ( ) == 0 {
641
+ break ;
642
+ }
643
+
633
644
// Assume that any directives will be found before the first
634
645
// module or function. This doesn't seem to be an optimization
635
646
// with a warm page cache. Maybe with a cold one.
636
- let ln = ln. unwrap ( ) ;
637
647
let ln = ln. trim ( ) ;
638
648
if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
639
649
return ;
0 commit comments