From b4936133bb781676070d5189362823ef058e0041 Mon Sep 17 00:00:00 2001 From: "许杰友 Jieyou Xu (Joe)" Date: Mon, 4 Mar 2024 19:30:53 +0000 Subject: Split dots in filename, not the entire path --- .../src/tests_revision_unpaired_stdout_stderr.rs | 22 +++++++++++++++------- tests/ui/meta/dir.with.dots/test.rs | 7 +++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 tests/ui/meta/dir.with.dots/test.rs diff --git a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs index 394f95e9144..87dbb0026d4 100644 --- a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs +++ b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs @@ -84,7 +84,9 @@ pub fn check(tests_path: impl AsRef, bad: &mut bool) { } }); - let Some((test_name, _)) = test.to_str().map(|s| s.split_once('.')).flatten() else { + let Some((test_name, _)) = + test.file_name().map(OsStr::to_str).flatten().map(|n| n.split_once('.')).flatten() + else { continue; }; @@ -98,14 +100,20 @@ pub fn check(tests_path: impl AsRef, bad: &mut bool) { for sibling in files_under_inspection.iter().filter(|f| { f.extension().map(OsStr::to_str).flatten().is_some_and(|ext| EXTENSIONS.contains(&ext)) }) { - let filename_components = sibling.to_str().unwrap().split('.').collect::>(); - let file_prefix = filename_components[0]; + let Some(filename) = sibling.file_name().map(OsStr::to_str).flatten() else { + continue; + }; + + let filename_components = filename.split('.').collect::>(); + let [file_prefix, ..] = &filename_components[..] else { + continue; + }; - let Some((test_path, expected_revisions)) = test_info.get(file_prefix) else { + let Some((test_path, expected_revisions)) = test_info.get(*file_prefix) else { continue; }; - match filename_components[..] { + match &filename_components[..] { // Cannot have a revision component, skip. [] | [_] => return, [_, _] if !expected_revisions.is_empty() => { @@ -120,9 +128,9 @@ pub fn check(tests_path: impl AsRef, bad: &mut bool) { [_, _] => return, [_, found_revision, .., extension] => { if !IGNORES.contains(&found_revision) - && !expected_revisions.contains(found_revision) + && !expected_revisions.contains(*found_revision) // This is from `//@ stderr-per-bitwidth` - && !(extension == "stderr" && ["32bit", "64bit"].contains(&found_revision)) + && !(*extension == "stderr" && ["32bit", "64bit"].contains(&found_revision)) { // Found some unexpected revision-esque component that is not a known // compare-mode or expected revision. diff --git a/tests/ui/meta/dir.with.dots/test.rs b/tests/ui/meta/dir.with.dots/test.rs new file mode 100644 index 00000000000..4d663e994f5 --- /dev/null +++ b/tests/ui/meta/dir.with.dots/test.rs @@ -0,0 +1,7 @@ +// Regression test for . +// Check that `tests_revision_unpaired_stdout_stderr` don't accidentally get confused by +// paths containing periods. + +//@ check-pass + +fn main() {} -- cgit 1.4.1-3-g733a5 From 9bebbf14c57c027138fd4bb335acaf9b83aa68b6 Mon Sep 17 00:00:00 2001 From: "许杰友 Jieyou Xu (Joe)" Date: Mon, 4 Mar 2024 20:07:39 +0000 Subject: Use Path::file_stem instead --- src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs index 87dbb0026d4..98b47b6ef66 100644 --- a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs +++ b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs @@ -84,9 +84,7 @@ pub fn check(tests_path: impl AsRef, bad: &mut bool) { } }); - let Some((test_name, _)) = - test.file_name().map(OsStr::to_str).flatten().map(|n| n.split_once('.')).flatten() - else { + let Some(test_name) = test.file_stem().map(OsStr::to_str).flatten() else { continue; }; -- cgit 1.4.1-3-g733a5 From 53f48ddbc7f6a42c2e67f8b16f5868f483821744 Mon Sep 17 00:00:00 2001 From: "许杰友 Jieyou Xu (Joe)" Date: Tue, 5 Mar 2024 08:11:27 +0000 Subject: Assert that test names cannot contain dots This is so that we can catch stray test output files, since test names without dots can form predictable patterns we can match on. --- src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs index 98b47b6ef66..a0773c85bef 100644 --- a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs +++ b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs @@ -88,6 +88,12 @@ pub fn check(tests_path: impl AsRef, bad: &mut bool) { continue; }; + assert!( + !test_name.contains('.'), + "test name cannot contain dots '.': `{}`", + test.display() + ); + test_info.insert(test_name.to_string(), (test, expected_revisions)); } -- cgit 1.4.1-3-g733a5 From 247a080b9852e3ab176cca63f5695c8a6b2202cd Mon Sep 17 00:00:00 2001 From: "许杰友 Jieyou Xu (Joe)" Date: Tue, 5 Mar 2024 09:02:33 +0000 Subject: Update test names to not have dots --- tests/rustdoc/invalid$crate$name.rs | 3 +++ tests/rustdoc/invalid.crate.name.rs | 3 --- tests/ui/command/need-crate-arg-ignore-tidy$x.rs | 2 ++ tests/ui/command/need-crate-arg-ignore-tidy$x.stderr | 6 ++++++ tests/ui/command/need-crate-arg-ignore-tidy.x.rs | 2 -- tests/ui/command/need-crate-arg-ignore-tidy.x.stderr | 6 ------ 6 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 tests/rustdoc/invalid$crate$name.rs delete mode 100644 tests/rustdoc/invalid.crate.name.rs create mode 100644 tests/ui/command/need-crate-arg-ignore-tidy$x.rs create mode 100644 tests/ui/command/need-crate-arg-ignore-tidy$x.stderr delete mode 100644 tests/ui/command/need-crate-arg-ignore-tidy.x.rs delete mode 100644 tests/ui/command/need-crate-arg-ignore-tidy.x.stderr diff --git a/tests/rustdoc/invalid$crate$name.rs b/tests/rustdoc/invalid$crate$name.rs new file mode 100644 index 00000000000..189a6c92124 --- /dev/null +++ b/tests/rustdoc/invalid$crate$name.rs @@ -0,0 +1,3 @@ +//@ compile-flags: --crate-name foo + +pub fn foo() {} diff --git a/tests/rustdoc/invalid.crate.name.rs b/tests/rustdoc/invalid.crate.name.rs deleted file mode 100644 index 189a6c92124..00000000000 --- a/tests/rustdoc/invalid.crate.name.rs +++ /dev/null @@ -1,3 +0,0 @@ -//@ compile-flags: --crate-name foo - -pub fn foo() {} diff --git a/tests/ui/command/need-crate-arg-ignore-tidy$x.rs b/tests/ui/command/need-crate-arg-ignore-tidy$x.rs new file mode 100644 index 00000000000..b1ac4a4ae21 --- /dev/null +++ b/tests/ui/command/need-crate-arg-ignore-tidy$x.rs @@ -0,0 +1,2 @@ +// issue: 113981 +pub fn main() {} diff --git a/tests/ui/command/need-crate-arg-ignore-tidy$x.stderr b/tests/ui/command/need-crate-arg-ignore-tidy$x.stderr new file mode 100644 index 00000000000..28f6d31b1ce --- /dev/null +++ b/tests/ui/command/need-crate-arg-ignore-tidy$x.stderr @@ -0,0 +1,6 @@ +error: invalid character `'$'` in crate name: `need_crate_arg_ignore_tidy$x` + | + = help: you can either pass `--crate-name` on the command line or add `#![crate_name="…"]` to set the crate name + +error: aborting due to 1 previous error + diff --git a/tests/ui/command/need-crate-arg-ignore-tidy.x.rs b/tests/ui/command/need-crate-arg-ignore-tidy.x.rs deleted file mode 100644 index b1ac4a4ae21..00000000000 --- a/tests/ui/command/need-crate-arg-ignore-tidy.x.rs +++ /dev/null @@ -1,2 +0,0 @@ -// issue: 113981 -pub fn main() {} diff --git a/tests/ui/command/need-crate-arg-ignore-tidy.x.stderr b/tests/ui/command/need-crate-arg-ignore-tidy.x.stderr deleted file mode 100644 index 89f7210c048..00000000000 --- a/tests/ui/command/need-crate-arg-ignore-tidy.x.stderr +++ /dev/null @@ -1,6 +0,0 @@ -error: invalid character `'.'` in crate name: `need_crate_arg_ignore_tidy.x` - | - = help: you can either pass `--crate-name` on the command line or add `#![crate_name="…"]` to set the crate name - -error: aborting due to 1 previous error - -- cgit 1.4.1-3-g733a5