Skip to content

Commit 6f37281

Browse files
committed
Auto merge of #126777 - Zalathar:normalize-colon, r=lcnr
Require a colon in `//@ normalize-*:` test headers The previous parser for `//@ normalize-*` headers (before #126370) was so lax that it did not require `:` after the header name. As a result, the test suite contained a mix of with-colon and without-colon normalize headers, both numbering in the hundreds. This PR updates the without-colon headers to add a colon (matching the style used by other headers), and then updates the parser to make the colon mandatory. (Because the normalization parser only runs *after* the header system identifies a normalize header, this will detect and issue an error for relevant headers that lack the colon.) Addresses one of the points of #126372.
2 parents 8c39ac9 + b677359 commit 6f37281

File tree

134 files changed

+235
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+235
-245
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,13 +1121,11 @@ fn expand_variables(mut value: String, config: &Config) -> String {
11211121
/// normalize-*: "REGEX" -> "REPLACEMENT"
11221122
/// ```
11231123
fn parse_normalize_rule(header: &str) -> Option<(String, String)> {
1124-
// FIXME(#126370): A colon after the header name should be mandatory, but
1125-
// currently is not, and there are many tests that lack the colon.
11261124
// FIXME: Support escaped double-quotes in strings.
11271125
let captures = static_regex!(
11281126
r#"(?x) # (verbose mode regex)
11291127
^
1130-
[^:\s]+:?\s* # (header name followed by optional colon)
1128+
[^:\s]+:\s* # (header name followed by colon)
11311129
"(?<regex>[^"]*)" # "REGEX"
11321130
\s+->\s+ # ->
11331131
"(?<replacement>[^"]*)" # "REPLACEMENT"

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,11 @@ fn make_test_description<R: Read>(
3333

3434
#[test]
3535
fn test_parse_normalize_rule() {
36-
let good_data = &[
37-
(
38-
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)""#,
39-
"something (32 bits)",
40-
"something ($WORD bits)",
41-
),
42-
// FIXME(#126370): A colon after the header name should be mandatory,
43-
// but currently is not, and there are many tests that lack the colon.
44-
(
45-
r#"normalize-stderr-32bit "something (32 bits)" -> "something ($WORD bits)""#,
46-
"something (32 bits)",
47-
"something ($WORD bits)",
48-
),
49-
];
36+
let good_data = &[(
37+
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)""#,
38+
"something (32 bits)",
39+
"something ($WORD bits)",
40+
)];
5041

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

5849
let bad_data = &[
50+
r#"normalize-stderr-32bit "something (32 bits)" -> "something ($WORD bits)""#,
5951
r#"normalize-stderr-16bit: something (16 bits) -> something ($WORD bits)"#,
6052
r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)"#,
6153
r#"normalize-stderr-32bit: "something (32 bits) -> something ($WORD bits)"#,

tests/rustdoc-ui/doctest/block-doc-comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ check-pass
22
//@ compile-flags:--test
3-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
3+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
44

55
// This test ensures that no code block is detected in the doc comments.
66

tests/rustdoc-ui/doctest/cfg-test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ check-pass
22
//@ compile-flags:--test --test-args --test-threads=1
33
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
4-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
4+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
55

66
// Crates like core have doctests gated on `cfg(not(test))` so we need to make
77
// sure `cfg(test)` is not active when running `rustdoc --test`.

tests/rustdoc-ui/doctest/check-cfg-test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ compile-flags: --test --nocapture --check-cfg=cfg(feature,values("test")) -Z unstable-options
33
//@ normalize-stderr-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
44
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
5-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
5+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
66

77
/// The doctest will produce a warning because feature invalid is unexpected
88
/// ```

tests/rustdoc-ui/doctest/display-output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ edition:2018
55
//@ compile-flags:--test --test-args=--show-output
66
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
7-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
7+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
88

99
/// ```
1010
/// #![warn(unused)]

tests/rustdoc-ui/doctest/doc-comment-multi-line-attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Regression test for #97440: Multiline inner attribute triggers ICE during doctest
22
//@ compile-flags:--test
33
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
4-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
4+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
55
//@ check-pass
66

77
//! ```rust

tests/rustdoc-ui/doctest/doc-comment-multi-line-cfg-attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ compile-flags:--test
22
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
3-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
3+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
44
//@ check-pass
55

66
/// ```

tests/rustdoc-ui/doctest/doc-test-doctest-feature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ check-pass
22
//@ compile-flags:--test
33
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
4-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
4+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
55

66
// Make sure `cfg(doctest)` is set when finding doctests but not inside
77
// the doctests.

tests/rustdoc-ui/doctest/doc-test-rustdoc-feature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ check-pass
22
//@ compile-flags:--test
33
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
4-
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
4+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
55

66
#![feature(doc_cfg)]
77

0 commit comments

Comments
 (0)