@@ -42,56 +42,38 @@ pub(super) fn handle_only(config: &Config, comment: TestComment<'_>) -> IgnoreDe
42
42
43
43
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
44
44
/// or `normalize-stderr-32bit`.
45
- pub ( super ) fn parse_cfg_name_directive < ' line > (
45
+ pub ( super ) fn parse_cfg_name_directive (
46
46
config : & Config ,
47
- comment : & ' line TestComment < ' line > ,
47
+ comment : & TestComment < ' _ > ,
48
48
prefix : & str ,
49
- ) -> MatchOutcome < ' line > {
50
- match comment. comment ( ) {
51
- CommentKind :: Compiletest ( line) => {
52
- parse_cfg_name_directive_compiletest ( config, line, prefix)
53
- }
54
- CommentKind :: UiTest ( line) => parse_cfg_name_directive_ui_test ( config, line, prefix) ,
55
- }
56
- }
57
-
58
- fn directive_name_for_line < ' line , ' p > (
59
- line : & ' line str ,
60
- prefix : & ' p str ,
61
- ) -> Option < ( & ' line str , Option < & ' line str > ) > {
62
- // Directives start with a specified prefix, and are immediately followed by a '-'.
63
- let expected_start = format ! ( "{}-" , prefix) ;
64
- let after_prefix = if line. starts_with ( expected_start. as_str ( ) ) {
65
- & line[ expected_start. len ( ) ..]
66
- } else {
67
- return None ;
49
+ ) -> MatchOutcome {
50
+ let comment_kind = comment. comment ( ) ;
51
+ let Some ( ( name, comment) ) = comment_kind. parse_name_comment ( ) . and_then ( |( name, comment) | {
52
+ name. strip_prefix ( format ! ( "{}-" , prefix) . as_str ( ) ) . map ( |stripped| ( stripped, comment) )
53
+ } ) else {
54
+ return MatchOutcome :: NotADirective ;
68
55
} ;
56
+ let comment = comment. map ( |c| c. trim ( ) . trim_start_matches ( '-' ) . trim ( ) . to_owned ( ) ) ;
69
57
70
- // If there is a ':' or a ' ' (space), split the name off, and consider the rest of the line to
71
- // be a "comment" that is ignored.
72
- let ( name, comment) = after_prefix
73
- . split_once ( & [ ':' , ' ' ] )
74
- . map ( |( l, c) | ( l. trim ( ) , Some ( c) ) )
75
- . unwrap_or ( ( after_prefix, None ) ) ;
76
-
77
- // Some of the matchers might be "" depending on what the target information is. To avoid
78
- // problems we outright reject empty directives.
79
- if name == "" { None } else { Some ( ( name, comment) ) }
58
+ match comment_kind {
59
+ CommentKind :: Compiletest ( _) => {
60
+ parse_cfg_name_directive_compiletest ( config, name, comment, prefix)
61
+ }
62
+ CommentKind :: UiTest ( _) => parse_cfg_name_directive_ui_test ( config, name, comment) ,
63
+ }
80
64
}
81
65
82
- fn parse_cfg_name_directive_ui_test < ' line > (
66
+ fn parse_cfg_name_directive_ui_test (
83
67
config : & Config ,
84
- line : & ' line str ,
85
- prefix : & str ,
86
- ) -> MatchOutcome < ' line > {
87
- let Some ( ( name, comment) ) = directive_name_for_line ( line, prefix) else {
88
- return MatchOutcome :: NotADirective ;
89
- } ;
90
- let comment = comment. map ( |c| c. trim ( ) . trim_start_matches ( '-' ) . trim ( ) ) ;
91
-
68
+ name : & str ,
69
+ comment : Option < String > ,
70
+ ) -> MatchOutcome {
92
71
let target_cfg = config. target_cfg ( ) ;
93
72
94
- if name == "on-host" {
73
+ // Parsing copied from ui_test: https://github.com/oli-obk/ui_test/blob/a18ef37bf3dcccf5a1a631eddd55759fe0b89617/src/parser.rs#L187
74
+ if name == "test" {
75
+ MatchOutcome :: Match { message : String :: from ( "always" ) , comment }
76
+ } else if name == "on-host" {
95
77
unimplemented ! ( "idk what to do about this yet" )
96
78
} else if let Some ( bits) = name. strip_suffix ( "bit" ) {
97
79
let Ok ( bits) = bits. parse :: < u32 > ( ) else {
@@ -126,16 +108,12 @@ fn parse_cfg_name_directive_ui_test<'line>(
126
108
}
127
109
}
128
110
129
- fn parse_cfg_name_directive_compiletest < ' a > (
111
+ fn parse_cfg_name_directive_compiletest (
130
112
config : & Config ,
131
- line : & ' a str ,
113
+ name : & str ,
114
+ comment : Option < String > ,
132
115
prefix : & str ,
133
- ) -> MatchOutcome < ' a > {
134
- let Some ( ( name, comment) ) = directive_name_for_line ( line, prefix) else {
135
- return MatchOutcome :: NotADirective ;
136
- } ;
137
- let comment = comment. map ( |c| c. trim ( ) . trim_start_matches ( '-' ) . trim ( ) ) ;
138
-
116
+ ) -> MatchOutcome {
139
117
macro_rules! condition {
140
118
(
141
119
name: $name: expr,
@@ -315,11 +293,11 @@ fn parse_cfg_name_directive_compiletest<'a>(
315
293
}
316
294
317
295
#[ derive( Clone , PartialEq , Debug ) ]
318
- pub ( super ) enum MatchOutcome < ' a > {
296
+ pub ( super ) enum MatchOutcome {
319
297
/// No match.
320
- NoMatch { message : String , comment : Option < & ' a str > } ,
298
+ NoMatch { message : String , comment : Option < String > } ,
321
299
/// Match.
322
- Match { message : String , comment : Option < & ' a str > } ,
300
+ Match { message : String , comment : Option < String > } ,
323
301
/// The directive was invalid.
324
302
Invalid ,
325
303
/// The directive is handled by other parts of our tooling.
0 commit comments