@@ -408,7 +408,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
408
408
tests. add_test ( text. to_owned ( ) ,
409
409
block_info. should_panic , block_info. no_run ,
410
410
block_info. ignore , block_info. test_harness ,
411
- block_info. compile_fail ) ;
411
+ block_info. compile_fail , block_info . error_codes ) ;
412
412
}
413
413
}
414
414
@@ -454,6 +454,7 @@ struct LangString {
454
454
rust : bool ,
455
455
test_harness : bool ,
456
456
compile_fail : bool ,
457
+ error_codes : Vec < String > ,
457
458
}
458
459
459
460
impl LangString {
@@ -465,16 +466,22 @@ impl LangString {
465
466
rust : true , // NB This used to be `notrust = false`
466
467
test_harness : false ,
467
468
compile_fail : false ,
469
+ error_codes : Vec :: new ( ) ,
468
470
}
469
471
}
470
472
471
473
fn parse ( string : & str ) -> LangString {
472
474
let mut seen_rust_tags = false ;
473
475
let mut seen_other_tags = false ;
474
476
let mut data = LangString :: all_false ( ) ;
475
- let allow_compile_fail = match get_unstable_features_setting ( ) {
476
- UnstableFeatures :: Allow | UnstableFeatures :: Cheat => true ,
477
- _ => false ,
477
+ let mut allow_compile_fail = false ;
478
+ let mut allow_error_code_check = false ;
479
+ match get_unstable_features_setting ( ) {
480
+ UnstableFeatures :: Allow | UnstableFeatures :: Cheat => {
481
+ allow_compile_fail = true ;
482
+ allow_error_code_check = true ;
483
+ }
484
+ _ => { } ,
478
485
} ;
479
486
480
487
let tokens = string. split ( |c : char |
@@ -493,7 +500,15 @@ impl LangString {
493
500
data. compile_fail = true ;
494
501
seen_rust_tags = true ;
495
502
data. no_run = true ;
496
- } ,
503
+ }
504
+ x if allow_error_code_check && x. starts_with ( "E" ) && x. len ( ) == 5 => {
505
+ if let Ok ( _) = x[ 1 ..] . parse :: < u32 > ( ) {
506
+ data. error_codes . push ( x. to_owned ( ) ) ;
507
+ seen_rust_tags = true ;
508
+ } else {
509
+ seen_other_tags = true ;
510
+ }
511
+ }
497
512
_ => { seen_other_tags = true }
498
513
}
499
514
}
@@ -577,30 +592,34 @@ mod tests {
577
592
fn test_lang_string_parse ( ) {
578
593
fn t ( s : & str ,
579
594
should_panic : bool , no_run : bool , ignore : bool , rust : bool , test_harness : bool ,
580
- compile_fail : bool ) {
595
+ compile_fail : bool , error_codes : Vec < String > ) {
581
596
assert_eq ! ( LangString :: parse( s) , LangString {
582
597
should_panic: should_panic,
583
598
no_run: no_run,
584
599
ignore: ignore,
585
600
rust: rust,
586
601
test_harness: test_harness,
587
602
compile_fail: compile_fail,
603
+ error_codes: error_codes,
588
604
} )
589
605
}
590
606
591
607
// marker | should_panic| no_run| ignore| rust | test_harness| compile_fail
592
- t ( "" , false , false , false , true , false , false ) ;
593
- t ( "rust" , false , false , false , true , false , false ) ;
594
- t ( "sh" , false , false , false , false , false , false ) ;
595
- t ( "ignore" , false , false , true , true , false , false ) ;
596
- t ( "should_panic" , true , false , false , true , false , false ) ;
597
- t ( "no_run" , false , true , false , true , false , false ) ;
598
- t ( "test_harness" , false , false , false , true , true , false ) ;
599
- t ( "compile_fail" , false , true , false , true , false , true ) ;
600
- t ( "{.no_run .example}" , false , true , false , true , false , false ) ;
601
- t ( "{.sh .should_panic}" , true , false , false , true , false , false ) ;
602
- t ( "{.example .rust}" , false , false , false , true , false , false ) ;
603
- t ( "{.test_harness .rust}" , false , false , false , true , true , false ) ;
608
+ // | error_codes
609
+ t ( "" , false , false , false , true , false , false , Vec :: new ( ) ) ;
610
+ t ( "rust" , false , false , false , true , false , false , Vec :: new ( ) ) ;
611
+ t ( "sh" , false , false , false , false , false , false , Vec :: new ( ) ) ;
612
+ t ( "ignore" , false , false , true , true , false , false , Vec :: new ( ) ) ;
613
+ t ( "should_panic" , true , false , false , true , false , false , Vec :: new ( ) ) ;
614
+ t ( "no_run" , false , true , false , true , false , false , Vec :: new ( ) ) ;
615
+ t ( "test_harness" , false , false , false , true , true , false , Vec :: new ( ) ) ;
616
+ t ( "compile_fail" , false , true , false , true , false , true , Vec :: new ( ) ) ;
617
+ t ( "E0450" , false , false , false , true , false , false ,
618
+ vec ! ( "E0450" . to_owned( ) ) ) ;
619
+ t ( "{.no_run .example}" , false , true , false , true , false , false , Vec :: new ( ) ) ;
620
+ t ( "{.sh .should_panic}" , true , false , false , true , false , false , Vec :: new ( ) ) ;
621
+ t ( "{.example .rust}" , false , false , false , true , false , false , Vec :: new ( ) ) ;
622
+ t ( "{.test_harness .rust}" , false , false , false , true , true , false , Vec :: new ( ) ) ;
604
623
}
605
624
606
625
#[ test]
0 commit comments