Skip to content

Commit

Permalink
Require a colon in //@ normalize-*: headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jul 11, 2024
1 parent fb13a98 commit 5d099f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,13 +1121,11 @@ fn expand_variables(mut value: String, config: &Config) -> String {
/// normalize-*: "REGEX" -> "REPLACEMENT"
/// ```
fn parse_normalize_rule(header: &str) -> Option<(String, String)> {
// FIXME(#126370): A colon after the header name should be mandatory, but
// currently is not, and there are many tests that lack the colon.
// FIXME: Support escaped double-quotes in strings.
let captures = static_regex!(
r#"(?x) # (verbose mode regex)
^
[^:\s]+:?\s* # (header name followed by optional colon)
[^:\s]+:\s* # (header name followed by colon)
"(?<regex>[^"]*)" # "REGEX"
\s+->\s+ # ->
"(?<replacement>[^"]*)" # "REPLACEMENT"
Expand Down
20 changes: 6 additions & 14 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,11 @@ fn make_test_description<R: Read>(

#[test]
fn test_parse_normalize_rule() {
let good_data = &[
(
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)""#,
"something (32 bits)",
"something ($WORD bits)",
),
// FIXME(#126370): A colon after the header name should be mandatory,
// but currently is not, and there are many tests that lack the colon.
(
r#"normalize-stderr-32bit "something (32 bits)" -> "something ($WORD bits)""#,
"something (32 bits)",
"something ($WORD bits)",
),
];
let good_data = &[(
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)""#,
"something (32 bits)",
"something ($WORD bits)",
)];

for &(input, expected_regex, expected_replacement) in good_data {
let parsed = parse_normalize_rule(input);
Expand All @@ -56,6 +47,7 @@ fn test_parse_normalize_rule() {
}

let bad_data = &[
r#"normalize-stderr-32bit "something (32 bits)" -> "something ($WORD bits)""#,
r#"normalize-stderr-16bit: something (16 bits) -> something ($WORD bits)"#,
r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)"#,
r#"normalize-stderr-32bit: "something (32 bits) -> something ($WORD bits)"#,
Expand Down

0 comments on commit 5d099f8

Please sign in to comment.