Skip to content

Commit 123cc41

Browse files
committed
include eventual comment in the compiletest ignore reason
1 parent 3328913 commit 123cc41

File tree

1 file changed

+55
-17
lines changed

1 file changed

+55
-17
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,20 @@ use crate::{extract_cdb_version, extract_gdb_version};
1616
mod tests;
1717

1818
/// The result of parse_cfg_name_directive.
19+
#[derive(Clone, PartialEq, Debug)]
20+
struct ParsedNameDirective {
21+
comment: Option<String>,
22+
outcome: MatchOutcome,
23+
}
24+
25+
impl ParsedNameDirective {
26+
fn invalid() -> Self {
27+
Self { comment: None, outcome: MatchOutcome::NoMatch }
28+
}
29+
}
30+
1931
#[derive(Clone, Copy, PartialEq, Debug)]
20-
enum ParsedNameDirective {
32+
enum MatchOutcome {
2133
/// No match.
2234
NoMatch,
2335
/// Match.
@@ -647,7 +659,7 @@ impl Config {
647659
}
648660

649661
fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
650-
if self.parse_cfg_name_directive(line, prefix) == ParsedNameDirective::Match {
662+
if self.parse_cfg_name_directive(line, prefix).outcome == MatchOutcome::Match {
651663
let from = parse_normalization_string(&mut line)?;
652664
let to = parse_normalization_string(&mut line)?;
653665
Some((from, to))
@@ -668,13 +680,15 @@ impl Config {
668680
/// or `normalize-stderr-32bit`.
669681
fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
670682
if !line.as_bytes().starts_with(prefix.as_bytes()) {
671-
return ParsedNameDirective::NoMatch;
683+
return ParsedNameDirective::invalid();
672684
}
673685
if line.as_bytes().get(prefix.len()) != Some(&b'-') {
674-
return ParsedNameDirective::NoMatch;
686+
return ParsedNameDirective::invalid();
675687
}
688+
let line = &line[prefix.len() + 1..];
676689

677-
let name = line[prefix.len() + 1..].split(&[':', ' '][..]).next().unwrap();
690+
let (name, comment) =
691+
line.split_once(&[':', ' ']).map(|(l, c)| (l, Some(c))).unwrap_or((line, None));
678692

679693
let matches_pointer_width = || {
680694
name.strip_suffix("bit")
@@ -723,7 +737,10 @@ impl Config {
723737
None => false,
724738
};
725739

726-
if is_match { ParsedNameDirective::Match } else { ParsedNameDirective::NoMatch }
740+
ParsedNameDirective {
741+
comment: comment.map(|c| c.trim().trim_start_matches('-').trim().to_string()),
742+
outcome: if is_match { MatchOutcome::Match } else { MatchOutcome::NoMatch },
743+
}
727744
}
728745

729746
fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool {
@@ -992,19 +1009,40 @@ pub fn make_test_description<R: Read>(
9921009
}
9931010
};
9941011
}
995-
ignore = match config.parse_cfg_name_directive(ln, "ignore") {
996-
ParsedNameDirective::Match => {
997-
ignore_message = Some("cfg -> ignore => Match");
998-
true
999-
}
1000-
ParsedNameDirective::NoMatch => ignore,
1001-
};
1012+
1013+
{
1014+
let parsed = config.parse_cfg_name_directive(ln, "ignore");
1015+
ignore = match parsed.outcome {
1016+
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+
});
1026+
true
1027+
}
1028+
MatchOutcome::NoMatch => ignore,
1029+
};
1030+
}
10021031

10031032
if config.has_cfg_prefix(ln, "only") {
1004-
ignore = match config.parse_cfg_name_directive(ln, "only") {
1005-
ParsedNameDirective::Match => ignore,
1006-
ParsedNameDirective::NoMatch => {
1007-
ignore_message = Some("cfg -> only => NoMatch");
1033+
let parsed = config.parse_cfg_name_directive(ln, "only");
1034+
ignore = match parsed.outcome {
1035+
MatchOutcome::Match => ignore,
1036+
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+
});
10081046
true
10091047
}
10101048
};

0 commit comments

Comments
 (0)