@@ -8,6 +8,7 @@ use std::process::Command;
8
8
9
9
use tracing:: * ;
10
10
11
+ use crate :: common:: CompareMode ;
11
12
use crate :: common:: { Config , Debugger , FailMode , Mode , PassMode } ;
12
13
use crate :: util;
13
14
use crate :: { extract_cdb_version, extract_gdb_version} ;
@@ -36,6 +37,10 @@ enum MatchOutcome {
36
37
NoMatch ,
37
38
/// Match.
38
39
Match ,
40
+ /// The directive was invalid.
41
+ Invalid ,
42
+ /// The directive is handled by other parts of our tooling.
43
+ External ,
39
44
}
40
45
41
46
/// Properties which must be known very early, before actually running
@@ -692,60 +697,99 @@ impl Config {
692
697
let ( name, comment) =
693
698
line. split_once ( & [ ':' , ' ' ] ) . map ( |( l, c) | ( l, Some ( c) ) ) . unwrap_or ( ( line, None ) ) ;
694
699
695
- let mut is_match = None ;
700
+ let mut outcome = MatchOutcome :: Invalid ;
701
+ let mut message = None ;
696
702
697
703
macro_rules! maybe_condition {
698
- ( name: $name: expr, $( condition: $condition: expr, ) ? message: $( $message: tt) * ) => {
699
- if let Some ( expected) = $name {
700
- if name == expected $( && $condition) ? {
701
- is_match = Some ( format!( $( $message) * ) ) ;
704
+ (
705
+ name: $name: expr,
706
+ $( allowed_names: $allowed_names: expr, ) ?
707
+ $( condition: $condition: expr, ) ?
708
+ message: $( $message: tt) *
709
+ ) => { {
710
+ // This is not inlined to avoid problems with macro repetitions.
711
+ let format_message = || format!( $( $message) * ) ;
712
+
713
+ if outcome != MatchOutcome :: Invalid {
714
+ // Ignore all other matches if we already found one
715
+ } else if $name. as_ref( ) . map( |n| n == & name) . unwrap_or( false ) {
716
+ message = Some ( format_message( ) ) ;
717
+ if true $( && $condition) ? {
718
+ outcome = MatchOutcome :: Match ;
719
+ } else {
720
+ outcome = MatchOutcome :: NoMatch ;
702
721
}
703
722
}
704
- } ;
723
+ $( else if $allowed_names. contains( name) {
724
+ message = Some ( format_message( ) ) ;
725
+ outcome = MatchOutcome :: NoMatch ;
726
+ } ) ?
727
+ } } ;
705
728
}
706
729
macro_rules! condition {
707
- ( name: $name: expr, $( condition: $condition: expr, ) ? message: $( $message: tt) * ) => {
730
+ (
731
+ name: $name: expr,
732
+ $( allowed_names: $allowed_names: expr, ) ?
733
+ $( condition: $condition: expr, ) ?
734
+ message: $( $message: tt) *
735
+ ) => {
708
736
maybe_condition! {
709
737
name: Some ( $name) ,
738
+ $( allowed_names: $allowed_names, ) *
710
739
$( condition: $condition, ) *
711
740
message: $( $message) *
712
741
}
713
742
} ;
714
743
}
744
+ macro_rules! hashset {
745
+ ( $( $value: expr) ,* $( , ) ?) => { {
746
+ let mut set = HashSet :: new( ) ;
747
+ $( set. insert( $value) ; ) *
748
+ set
749
+ } }
750
+ }
751
+
752
+ let target_cfgs = self . target_cfgs ( ) ;
753
+ let target_cfg = self . target_cfg ( ) ;
715
754
716
755
condition ! {
717
756
name: "test" ,
718
757
message: "always"
719
758
}
720
759
condition ! {
721
760
name: & self . target,
761
+ allowed_names: & target_cfgs. all_targets,
722
762
message: "when the target is {name}"
723
763
}
724
-
725
- let target_cfg = self . target_cfg ( ) ;
726
764
condition ! {
727
765
name: & target_cfg. os,
766
+ allowed_names: & target_cfgs. all_oses,
728
767
message: "when the operative system is {name}"
729
768
}
730
769
condition ! {
731
770
name: & target_cfg. env,
771
+ allowed_names: & target_cfgs. all_envs,
732
772
message: "when the target environment is {name}"
733
773
}
734
774
condition ! {
735
775
name: & target_cfg. abi,
776
+ allowed_names: & target_cfgs. all_abis,
736
777
message: "when the ABI is {name}"
737
778
}
738
779
condition ! {
739
780
name: & target_cfg. arch,
781
+ allowed_names: & target_cfgs. all_archs,
740
782
message: "when the architecture is {name}"
741
783
}
742
784
condition ! {
743
785
name: format!( "{}bit" , target_cfg. pointer_width) ,
786
+ allowed_names: & target_cfgs. all_pointer_widths,
744
787
message: "when the pointer width is {name}"
745
788
}
746
789
for family in & target_cfg. families {
747
790
condition ! {
748
791
name: family,
792
+ allowed_names: & target_cfgs. all_families,
749
793
message: "when the target family is {name}"
750
794
}
751
795
}
@@ -768,6 +812,7 @@ impl Config {
768
812
769
813
condition ! {
770
814
name: & self . channel,
815
+ allowed_names: hashset![ "stable" , "beta" , "nightly" ] ,
771
816
message: "when the release channel is {name}" ,
772
817
}
773
818
condition ! {
@@ -782,6 +827,7 @@ impl Config {
782
827
}
783
828
condition ! {
784
829
name: self . stage_id. split( '-' ) . next( ) . unwrap( ) ,
830
+ allowed_names: hashset![ "stable" , "beta" , "nightly" ] ,
785
831
message: "when the bootstrapping stage is {name}" ,
786
832
}
787
833
condition ! {
@@ -796,20 +842,38 @@ impl Config {
796
842
}
797
843
maybe_condition ! {
798
844
name: self . debugger. as_ref( ) . map( |d| d. to_str( ) ) ,
845
+ allowed_names: Debugger :: VARIANTS
846
+ . iter( )
847
+ . map( |v| v. to_str( ) )
848
+ . collect:: <HashSet <_>>( ) ,
799
849
message: "when the debugger is {name}" ,
800
850
}
801
851
maybe_condition ! {
802
852
name: self . compare_mode
803
853
. as_ref( )
804
854
. map( |d| format!( "compare-mode-{}" , d. to_str( ) ) ) ,
855
+ allowed_names: CompareMode :: VARIANTS
856
+ . iter( )
857
+ . map( |cm| format!( "compare-mode-{}" , cm. to_str( ) ) )
858
+ . collect:: <HashSet <_>>( ) ,
805
859
message: "when comparing with {name}" ,
806
860
}
807
861
862
+ // Don't error out for ignore-tidy-* diretives, as those are not handled by compiletest.
863
+ if prefix == "ignore" && name. starts_with ( "tidy-" ) && outcome == MatchOutcome :: Invalid {
864
+ outcome = MatchOutcome :: External ;
865
+ }
866
+
867
+ // Don't error out for ignore-pass, as that is handled elsewhere.
868
+ if prefix == "ignore" && name == "pass" && outcome == MatchOutcome :: Invalid {
869
+ outcome = MatchOutcome :: External ;
870
+ }
871
+
808
872
ParsedNameDirective {
809
873
name : Some ( name) ,
810
874
comment : comment. map ( |c| c. trim ( ) . trim_start_matches ( '-' ) . trim ( ) ) ,
811
- outcome : if is_match . is_some ( ) { MatchOutcome :: Match } else { MatchOutcome :: NoMatch } ,
812
- pretty_reason : is_match ,
875
+ outcome,
876
+ pretty_reason : message ,
813
877
}
814
878
}
815
879
@@ -1095,6 +1159,8 @@ pub fn make_test_description<R: Read>(
1095
1159
true
1096
1160
}
1097
1161
MatchOutcome :: NoMatch => ignore,
1162
+ MatchOutcome :: External => ignore,
1163
+ MatchOutcome :: Invalid => panic ! ( "invalid line in {}: {ln}" , path. display( ) ) ,
1098
1164
} ;
1099
1165
}
1100
1166
@@ -1103,16 +1169,18 @@ pub fn make_test_description<R: Read>(
1103
1169
ignore = match parsed. outcome {
1104
1170
MatchOutcome :: Match => ignore,
1105
1171
MatchOutcome :: NoMatch => {
1106
- let name = parsed. name . unwrap ( ) ;
1172
+ let reason = parsed. pretty_reason . unwrap ( ) ;
1107
1173
// The ignore reason must be a &'static str, so we have to leak memory to
1108
1174
// create it. This is fine, as the header is parsed only at the start of
1109
1175
// compiletest so it won't grow indefinitely.
1110
1176
ignore_message = Some ( Box :: leak ( Box :: < str > :: from ( match parsed. comment {
1111
- Some ( comment) => format ! ( "did not match only-{name } ({comment})" ) ,
1112
- None => format ! ( "did not match only-{name }" ) ,
1177
+ Some ( comment) => format ! ( "only executed {reason } ({comment})" ) ,
1178
+ None => format ! ( "only executed {reason }" ) ,
1113
1179
} ) ) as & str ) ;
1114
1180
true
1115
1181
}
1182
+ MatchOutcome :: External => ignore,
1183
+ MatchOutcome :: Invalid => panic ! ( "invalid line in {}: {ln}" , path. display( ) ) ,
1116
1184
} ;
1117
1185
}
1118
1186
0 commit comments