Skip to content

Commit 3a4e821

Browse files
committed
compiletest: Only pass the post-colon value to parse_normalize_rule
1 parent ef19017 commit 3a4e821

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/tools/compiletest/src/header.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -978,10 +978,10 @@ impl Config {
978978
}
979979
}
980980

981-
fn parse_custom_normalization(&self, line: &str) -> Option<NormalizeRule> {
981+
fn parse_custom_normalization(&self, raw_directive: &str) -> Option<NormalizeRule> {
982982
// FIXME(Zalathar): Integrate name/value splitting into `DirectiveLine`
983983
// instead of doing it here.
984-
let (directive_name, _value) = line.split_once(':')?;
984+
let (directive_name, raw_value) = raw_directive.split_once(':')?;
985985

986986
let kind = match directive_name {
987987
"normalize-stdout" => NormalizeKind::Stdout,
@@ -991,11 +991,9 @@ impl Config {
991991
_ => return None,
992992
};
993993

994-
// FIXME(Zalathar): The normalize rule parser should only care about
995-
// the value part, not the "line" (which isn't even the whole line).
996-
let Some((regex, replacement)) = parse_normalize_rule(line) else {
994+
let Some((regex, replacement)) = parse_normalize_rule(raw_value) else {
997995
panic!(
998-
"couldn't parse custom normalization rule: `{line}`\n\
996+
"couldn't parse custom normalization rule: `{raw_directive}`\n\
999997
help: expected syntax is: `{directive_name}: \"REGEX\" -> \"REPLACEMENT\"`"
1000998
);
1001999
};
@@ -1141,21 +1139,21 @@ enum NormalizeKind {
11411139
/// Parses the regex and replacement values of a `//@ normalize-*` header,
11421140
/// in the format:
11431141
/// ```text
1144-
/// normalize-*: "REGEX" -> "REPLACEMENT"
1142+
/// "REGEX" -> "REPLACEMENT"
11451143
/// ```
1146-
fn parse_normalize_rule(header: &str) -> Option<(String, String)> {
1144+
fn parse_normalize_rule(raw_value: &str) -> Option<(String, String)> {
11471145
// FIXME: Support escaped double-quotes in strings.
11481146
let captures = static_regex!(
11491147
r#"(?x) # (verbose mode regex)
11501148
^
1151-
[^:\s]+:\s* # (header name followed by colon)
1149+
\s* # (leading whitespace)
11521150
"(?<regex>[^"]*)" # "REGEX"
11531151
\s+->\s+ # ->
11541152
"(?<replacement>[^"]*)" # "REPLACEMENT"
11551153
$
11561154
"#
11571155
)
1158-
.captures(header)?;
1156+
.captures(raw_value)?;
11591157
let regex = captures["regex"].to_owned();
11601158
let replacement = captures["replacement"].to_owned();
11611159
// FIXME: Support escaped new-line in strings.

src/tools/compiletest/src/header/tests.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ fn make_test_description<R: Read>(
3535

3636
#[test]
3737
fn test_parse_normalize_rule() {
38-
let good_data = &[(
39-
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)""#,
40-
"something (32 bits)",
41-
"something ($WORD bits)",
42-
)];
38+
let good_data = &[
39+
(
40+
r#""something (32 bits)" -> "something ($WORD bits)""#,
41+
"something (32 bits)",
42+
"something ($WORD bits)",
43+
),
44+
(r#" " with whitespace" -> " replacement""#, " with whitespace", " replacement"),
45+
];
4346

4447
for &(input, expected_regex, expected_replacement) in good_data {
4548
let parsed = parse_normalize_rule(input);
@@ -49,15 +52,15 @@ fn test_parse_normalize_rule() {
4952
}
5053

5154
let bad_data = &[
52-
r#"normalize-stderr-32bit "something (32 bits)" -> "something ($WORD bits)""#,
53-
r#"normalize-stderr-16bit: something (16 bits) -> something ($WORD bits)"#,
54-
r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)"#,
55-
r#"normalize-stderr-32bit: "something (32 bits) -> something ($WORD bits)"#,
56-
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)"#,
57-
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)"."#,
55+
r#"something (11 bits) -> something ($WORD bits)"#,
56+
r#"something (12 bits) -> something ($WORD bits)"#,
57+
r#""something (13 bits) -> something ($WORD bits)"#,
58+
r#""something (14 bits)" -> "something ($WORD bits)"#,
59+
r#""something (15 bits)" -> "something ($WORD bits)"."#,
5860
];
5961

6062
for &input in bad_data {
63+
println!("- {input:?}");
6164
let parsed = parse_normalize_rule(input);
6265
assert_eq!(parsed, None);
6366
}

0 commit comments

Comments
 (0)