@@ -8,7 +8,7 @@ use std::process::Command;
8
8
9
9
use tracing:: * ;
10
10
11
- use crate :: common:: { CompareMode , Config , Debugger , FailMode , Mode , PassMode } ;
11
+ use crate :: common:: { Config , Debugger , FailMode , Mode , PassMode } ;
12
12
use crate :: util;
13
13
use crate :: { extract_cdb_version, extract_gdb_version} ;
14
14
@@ -17,14 +17,16 @@ mod tests;
17
17
18
18
/// The result of parse_cfg_name_directive.
19
19
#[ derive( Clone , PartialEq , Debug ) ]
20
- struct ParsedNameDirective {
21
- comment : Option < String > ,
20
+ struct ParsedNameDirective < ' a > {
21
+ name : Option < & ' a str > ,
22
+ pretty_reason : Option < String > ,
23
+ comment : Option < & ' a str > ,
22
24
outcome : MatchOutcome ,
23
25
}
24
26
25
- impl ParsedNameDirective {
27
+ impl ParsedNameDirective < ' _ > {
26
28
fn invalid ( ) -> Self {
27
- Self { comment : None , outcome : MatchOutcome :: NoMatch }
29
+ Self { name : None , pretty_reason : None , comment : None , outcome : MatchOutcome :: NoMatch }
28
30
}
29
31
}
30
32
@@ -678,7 +680,7 @@ impl Config {
678
680
679
681
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
680
682
/// or `normalize-stderr-32bit`.
681
- fn parse_cfg_name_directive ( & self , line : & str , prefix : & str ) -> ParsedNameDirective {
683
+ fn parse_cfg_name_directive < ' a > ( & self , line : & ' a str , prefix : & str ) -> ParsedNameDirective < ' a > {
682
684
if !line. as_bytes ( ) . starts_with ( prefix. as_bytes ( ) ) {
683
685
return ParsedNameDirective :: invalid ( ) ;
684
686
}
@@ -690,56 +692,124 @@ impl Config {
690
692
let ( name, comment) =
691
693
line. split_once ( & [ ':' , ' ' ] ) . map ( |( l, c) | ( l, Some ( c) ) ) . unwrap_or ( ( line, None ) ) ;
692
694
693
- let matches_pointer_width = || {
694
- name. strip_suffix ( "bit" )
695
- . and_then ( |width| width. parse :: < u32 > ( ) . ok ( ) )
696
- . map ( |width| self . get_pointer_width ( ) == width)
697
- . unwrap_or ( false )
698
- } ;
695
+ let mut is_match = None ;
696
+
697
+ 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) * ) ) ;
702
+ }
703
+ }
704
+ } ;
705
+ }
706
+ macro_rules! condition {
707
+ ( name: $name: expr, $( condition: $condition: expr, ) ? message: $( $message: tt) * ) => {
708
+ maybe_condition! {
709
+ name: Some ( $name) ,
710
+ $( condition: $condition, ) *
711
+ message: $( $message) *
712
+ }
713
+ } ;
714
+ }
715
+
716
+ condition ! {
717
+ name: "test" ,
718
+ message: "always"
719
+ }
720
+ condition ! {
721
+ name: & self . target,
722
+ message: "when the target is {name}"
723
+ }
724
+
725
+ let target_cfg = self . target_cfg ( ) ;
726
+ condition ! {
727
+ name: & target_cfg. os,
728
+ message: "when the operative system is {name}"
729
+ }
730
+ condition ! {
731
+ name: & target_cfg. env,
732
+ message: "when the target environment is {name}"
733
+ }
734
+ condition ! {
735
+ name: & target_cfg. abi,
736
+ message: "when the ABI is {name}"
737
+ }
738
+ condition ! {
739
+ name: & target_cfg. arch,
740
+ message: "when the architecture is {name}"
741
+ }
742
+ condition ! {
743
+ name: format!( "{}bit" , target_cfg. pointer_width) ,
744
+ message: "when the pointer width is {name}"
745
+ }
746
+ for family in & target_cfg. families {
747
+ condition ! {
748
+ name: family,
749
+ message: "when the target family is {name}"
750
+ }
751
+ }
699
752
700
753
// If something is ignored for emscripten, it likely also needs to be
701
754
// ignored for wasm32-unknown-unknown.
702
755
// `wasm32-bare` is an alias to refer to just wasm32-unknown-unknown
703
756
// (in contrast to `wasm32` which also matches non-bare targets like
704
757
// asmjs-unknown-emscripten).
705
- let matches_wasm32_alias = || {
706
- self . target == "wasm32-unknown-unknown" && matches ! ( name, "emscripten" | "wasm32-bare" )
707
- } ;
758
+ condition ! {
759
+ name: "emscripten" ,
760
+ condition: self . target == "wasm32-unknown-unknown" ,
761
+ message: "when the target is WASM" ,
762
+ }
763
+ condition ! {
764
+ name: "wasm32-bare" ,
765
+ condition: self . target == "wasm32-unknown-unknown" ,
766
+ message: "when the target is WASM"
767
+ }
708
768
709
- let is_match = name == "test" ||
710
- self . target == name || // triple
711
- self . matches_os ( name) ||
712
- self . matches_env ( name) ||
713
- self . matches_abi ( name) ||
714
- self . matches_family ( name) ||
715
- self . target . ends_with ( name) || // target and env
716
- self . matches_arch ( name) ||
717
- matches_wasm32_alias ( ) ||
718
- matches_pointer_width ( ) ||
719
- name == self . stage_id . split ( '-' ) . next ( ) . unwrap ( ) || // stage
720
- name == self . channel || // channel
721
- ( self . target != self . host && name == "cross-compile" ) ||
722
- ( name == "endian-big" && self . is_big_endian ( ) ) ||
723
- ( self . remote_test_client . is_some ( ) && name == "remote" ) ||
724
- match self . compare_mode {
725
- Some ( CompareMode :: Polonius ) => name == "compare-mode-polonius" ,
726
- Some ( CompareMode :: Chalk ) => name == "compare-mode-chalk" ,
727
- Some ( CompareMode :: NextSolver ) => name == "compare-mode-next-solver" ,
728
- Some ( CompareMode :: SplitDwarf ) => name == "compare-mode-split-dwarf" ,
729
- Some ( CompareMode :: SplitDwarfSingle ) => name == "compare-mode-split-dwarf-single" ,
730
- None => false ,
731
- } ||
732
- ( cfg ! ( debug_assertions) && name == "debug" ) ||
733
- match self . debugger {
734
- Some ( Debugger :: Cdb ) => name == "cdb" ,
735
- Some ( Debugger :: Gdb ) => name == "gdb" ,
736
- Some ( Debugger :: Lldb ) => name == "lldb" ,
737
- None => false ,
738
- } ;
769
+ condition ! {
770
+ name: & self . channel,
771
+ message: "when the release channel is {name}" ,
772
+ }
773
+ condition ! {
774
+ name: "cross-compile" ,
775
+ condition: self . target != self . host,
776
+ message: "when cross-compiling"
777
+ }
778
+ condition ! {
779
+ name: "endian-big" ,
780
+ condition: self . is_big_endian( ) ,
781
+ message: "on big-endian targets" ,
782
+ }
783
+ condition ! {
784
+ name: self . stage_id. split( '-' ) . next( ) . unwrap( ) ,
785
+ message: "when the bootstrapping stage is {name}" ,
786
+ }
787
+ condition ! {
788
+ name: "remote" ,
789
+ condition: self . remote_test_client. is_some( ) ,
790
+ message: "when running tests remotely" ,
791
+ }
792
+ condition ! {
793
+ name: "debug" ,
794
+ condition: cfg!( debug_assertions) ,
795
+ message: "when building with debug assertions" ,
796
+ }
797
+ maybe_condition ! {
798
+ name: self . debugger. as_ref( ) . map( |d| d. to_str( ) ) ,
799
+ message: "when the debugger is {name}" ,
800
+ }
801
+ maybe_condition ! {
802
+ name: self . compare_mode
803
+ . as_ref( )
804
+ . map( |d| format!( "compare-mode-{}" , d. to_str( ) ) ) ,
805
+ message: "when comparing with {name}" ,
806
+ }
739
807
740
808
ParsedNameDirective {
741
- comment : comment. map ( |c| c. trim ( ) . trim_start_matches ( '-' ) . trim ( ) . to_string ( ) ) ,
742
- outcome : if is_match { MatchOutcome :: Match } else { MatchOutcome :: NoMatch } ,
809
+ name : Some ( name) ,
810
+ 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,
743
813
}
744
814
}
745
815
@@ -1014,15 +1084,14 @@ pub fn make_test_description<R: Read>(
1014
1084
let parsed = config. parse_cfg_name_directive ( ln, "ignore" ) ;
1015
1085
ignore = match parsed. outcome {
1016
1086
MatchOutcome :: Match => {
1017
- ignore_message = Some ( match parsed. comment {
1018
- // The ignore reason must be a &'static str, so we have to leak memory to
1019
- // create it. This is fine, as the header is parsed only at the start of
1020
- // compiletest so it won't grow indefinitely.
1021
- Some ( comment) => Box :: leak ( Box :: < str > :: from ( format ! (
1022
- "cfg -> ignore => Match ({comment})"
1023
- ) ) ) ,
1024
- None => "cfg -> ignore => Match" ,
1025
- } ) ;
1087
+ let reason = parsed. pretty_reason . unwrap ( ) ;
1088
+ // The ignore reason must be a &'static str, so we have to leak memory to
1089
+ // create it. This is fine, as the header is parsed only at the start of
1090
+ // compiletest so it won't grow indefinitely.
1091
+ ignore_message = Some ( Box :: leak ( Box :: < str > :: from ( match parsed. comment {
1092
+ Some ( comment) => format ! ( "ignored {reason} ({comment})" ) ,
1093
+ None => format ! ( "ignored {reason}" ) ,
1094
+ } ) ) as & str ) ;
1026
1095
true
1027
1096
}
1028
1097
MatchOutcome :: NoMatch => ignore,
@@ -1034,15 +1103,14 @@ pub fn make_test_description<R: Read>(
1034
1103
ignore = match parsed. outcome {
1035
1104
MatchOutcome :: Match => ignore,
1036
1105
MatchOutcome :: NoMatch => {
1037
- ignore_message = Some ( match parsed. comment {
1038
- // The ignore reason must be a &'static str, so we have to leak memory to
1039
- // create it. This is fine, as the header is parsed only at the start of
1040
- // compiletest so it won't grow indefinitely.
1041
- Some ( comment) => Box :: leak ( Box :: < str > :: from ( format ! (
1042
- "cfg -> only => NoMatch ({comment})"
1043
- ) ) ) ,
1044
- None => "cfg -> only => NoMatch" ,
1045
- } ) ;
1106
+ let name = parsed. name . unwrap ( ) ;
1107
+ // The ignore reason must be a &'static str, so we have to leak memory to
1108
+ // create it. This is fine, as the header is parsed only at the start of
1109
+ // compiletest so it won't grow indefinitely.
1110
+ 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}" ) ,
1113
+ } ) ) as & str ) ;
1046
1114
true
1047
1115
}
1048
1116
} ;
0 commit comments