Skip to content

Commit c7beecf

Browse files
committed
Auto merge of rust-lang#121992 - jieyouxu:fix-tidy-unpaired-revision, r=onur-ozkan
tidy: split dots in filename not the entire path when checking for stray stdout/stderr files I committed a path crime by splitting the entire path on `.`, when I meant to split on the filename. This means that any parent folders which contain `.` will cause tidy failure. Added a regression test so that doesn't happen again. ### Follow-up - [ ] Adjust rustc-dev-guide to document assert on test name not containing dots. rust-lang/rustc-dev-guide#1927 Fixes rust-lang#121986.
2 parents bdde2a8 + 247a080 commit c7beecf

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ pub fn check(tests_path: impl AsRef<Path>, bad: &mut bool) {
8484
}
8585
});
8686

87-
let Some((test_name, _)) = test.to_str().map(|s| s.split_once('.')).flatten() else {
87+
let Some(test_name) = test.file_stem().map(OsStr::to_str).flatten() else {
8888
continue;
8989
};
9090

91+
assert!(
92+
!test_name.contains('.'),
93+
"test name cannot contain dots '.': `{}`",
94+
test.display()
95+
);
96+
9197
test_info.insert(test_name.to_string(), (test, expected_revisions));
9298
}
9399

@@ -98,14 +104,20 @@ pub fn check(tests_path: impl AsRef<Path>, bad: &mut bool) {
98104
for sibling in files_under_inspection.iter().filter(|f| {
99105
f.extension().map(OsStr::to_str).flatten().is_some_and(|ext| EXTENSIONS.contains(&ext))
100106
}) {
101-
let filename_components = sibling.to_str().unwrap().split('.').collect::<Vec<_>>();
102-
let file_prefix = filename_components[0];
107+
let Some(filename) = sibling.file_name().map(OsStr::to_str).flatten() else {
108+
continue;
109+
};
110+
111+
let filename_components = filename.split('.').collect::<Vec<_>>();
112+
let [file_prefix, ..] = &filename_components[..] else {
113+
continue;
114+
};
103115

104-
let Some((test_path, expected_revisions)) = test_info.get(file_prefix) else {
116+
let Some((test_path, expected_revisions)) = test_info.get(*file_prefix) else {
105117
continue;
106118
};
107119

108-
match filename_components[..] {
120+
match &filename_components[..] {
109121
// Cannot have a revision component, skip.
110122
[] | [_] => return,
111123
[_, _] if !expected_revisions.is_empty() => {
@@ -120,9 +132,9 @@ pub fn check(tests_path: impl AsRef<Path>, bad: &mut bool) {
120132
[_, _] => return,
121133
[_, found_revision, .., extension] => {
122134
if !IGNORES.contains(&found_revision)
123-
&& !expected_revisions.contains(found_revision)
135+
&& !expected_revisions.contains(*found_revision)
124136
// This is from `//@ stderr-per-bitwidth`
125-
&& !(extension == "stderr" && ["32bit", "64bit"].contains(&found_revision))
137+
&& !(*extension == "stderr" && ["32bit", "64bit"].contains(&found_revision))
126138
{
127139
// Found some unexpected revision-esque component that is not a known
128140
// compare-mode or expected revision.
File renamed without changes.

tests/ui/command/need-crate-arg-ignore-tidy.x.stderr tests/ui/command/need-crate-arg-ignore-tidy$x.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: invalid character `'.'` in crate name: `need_crate_arg_ignore_tidy.x`
1+
error: invalid character `'$'` in crate name: `need_crate_arg_ignore_tidy$x`
22
|
33
= help: you can either pass `--crate-name` on the command line or add `#![crate_name="…"]` to set the crate name
44

tests/ui/meta/dir.with.dots/test.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/121986>.
2+
// Check that `tests_revision_unpaired_stdout_stderr` don't accidentally get confused by
3+
// paths containing periods.
4+
5+
//@ check-pass
6+
7+
fn main() {}

0 commit comments

Comments
 (0)