Skip to content

Commit 1faf402

Browse files
authored
fix: rename test modules to avoid case-insensitive path collisions (#6849)
Cloning the repo on case-insensitive filesystems (e.g. Windows, macOS) produces git warnings because the following directories collide: tests/{source,target}/reorder_modules/ABCD vs abcd tests/{source,target}/reorder_modules/ZYXW vs zyxw tests/{source,target}/reorder_modules_2027/ABCD vs abcd tests/{source,target}/reorder_modules_2027/ZYXW vs zyxw These were added in 2d049af (#6368) to test case-sensitive module sorting across style editions. The collision on case-insensitive filesystems was not considered. Rename the lowercase variants (abcd -> abcde, zyxw -> zyxwv) to eliminate collisions while preserving the test intent. Also add a unit test (no_case_insensitive_path_collisions) to prevent future collisions
1 parent f9ff702 commit 1faf402

23 files changed

Lines changed: 76 additions & 20 deletions

src/test/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,58 @@ fn verify_config_test_names() {
166166
}
167167
}
168168

169+
// Collects all file and directory paths under `root` (relative to `root`).
170+
fn collect_paths(root: &Path) -> Vec<PathBuf> {
171+
let mut paths = Vec::new();
172+
let mut stack = vec![root.to_path_buf()];
173+
while let Some(dir) = stack.pop() {
174+
for entry in fs::read_dir(&dir).expect(&format!("couldn't read {}", dir.display())) {
175+
let entry = entry.expect("couldn't get DirEntry");
176+
let path = entry.path();
177+
paths.push(path.strip_prefix(root).unwrap().to_path_buf());
178+
if path.is_dir() {
179+
stack.push(path);
180+
}
181+
}
182+
}
183+
paths
184+
}
185+
186+
#[test]
187+
fn no_case_insensitive_path_collisions() {
188+
// Ensure no two paths in test directories differ only by case,
189+
// which causes warnings when cloning on case-insensitive filesystems
190+
// (e.g. Windows, macOS).
191+
let test_dirs = [Path::new("tests/source"), Path::new("tests/target")];
192+
let mut collisions = Vec::new();
193+
194+
for root in &test_dirs {
195+
let mut seen: HashMap<String, PathBuf> = HashMap::new();
196+
for path in collect_paths(root) {
197+
let key = path.to_string_lossy().to_lowercase();
198+
if let Some(existing) = seen.get(&key) {
199+
if *existing != path {
200+
collisions.push(format!(
201+
"{}/{} collides with {}/{}",
202+
root.display(),
203+
existing.display(),
204+
root.display(),
205+
path.display(),
206+
));
207+
}
208+
} else {
209+
seen.insert(key, path);
210+
}
211+
}
212+
}
213+
214+
assert!(
215+
collisions.is_empty(),
216+
"Case-insensitive path collisions found (these cause warnings on Windows/macOS):\n {}",
217+
collisions.join("\n ")
218+
);
219+
}
220+
169221
// This writes to the terminal using the same approach (via `term::stdout` or
170222
// `println!`) that is used by `rustfmt::rustfmt_diff::print_diff`. Writing
171223
// using only one or the other will cause the output order to differ when

tests/source/reorder_modules/disabled_style_edition_2024.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod x86;
55
mod v0s;
66
mod v001;
77
mod x87;
8-
mod zyxw;
8+
mod zyxwv;
99
mod A2;
1010
mod ZYXW;
1111
mod w5s009t;
@@ -36,7 +36,7 @@ mod _abcd;
3636
mod ABCD;
3737
mod Z_YXW;
3838
mod u64;
39-
mod abcd;
39+
mod abcde;
4040
mod ZYXW_;
4141
mod u16;
4242
mod uz;

tests/source/reorder_modules/enabled_style_edition_2015.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod x86;
55
mod v0s;
66
mod v001;
77
mod x87;
8-
mod zyxw;
8+
mod zyxwv;
99
mod A2;
1010
mod ZYXW;
1111
mod w5s009t;
@@ -36,7 +36,7 @@ mod _abcd;
3636
mod ABCD;
3737
mod Z_YXW;
3838
mod u64;
39-
mod abcd;
39+
mod abcde;
4040
mod ZYXW_;
4141
mod u16;
4242
mod uz;

tests/source/reorder_modules/enabled_style_edition_2024.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod x86;
55
mod v0s;
66
mod v001;
77
mod x87;
8-
mod zyxw;
8+
mod zyxwv;
99
mod A2;
1010
mod ZYXW;
1111
mod w5s009t;
@@ -36,7 +36,7 @@ mod _abcd;
3636
mod ABCD;
3737
mod Z_YXW;
3838
mod u64;
39-
mod abcd;
39+
mod abcde;
4040
mod ZYXW_;
4141
mod u16;
4242
mod uz;

tests/source/reorder_modules_2027/abcd/mod.rs

Whitespace-only changes.
File renamed without changes.

tests/source/reorder_modules_2027/disabled_style_edition_2027.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod x86;
55
mod v0s;
66
mod v001;
77
mod x87;
8-
mod zyxw;
8+
mod zyxwv;
99
mod A2;
1010
mod ZYXW;
1111
mod w5s009t;
@@ -36,7 +36,7 @@ mod _abcd;
3636
mod ABCD;
3737
mod Z_YXW;
3838
mod u64;
39-
mod abcd;
39+
mod abcde;
4040
mod ZYXW_;
4141
mod u16;
4242
mod uz;

tests/source/reorder_modules_2027/enabled_style_edition_2027.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod x86;
55
mod v0s;
66
mod v001;
77
mod x87;
8-
mod zyxw;
8+
mod zyxwv;
99
mod A2;
1010
mod ZYXW;
1111
mod w5s009t;
@@ -36,7 +36,7 @@ mod _abcd;
3636
mod ABCD;
3737
mod Z_YXW;
3838
mod u64;
39-
mod abcd;
39+
mod abcde;
4040
mod ZYXW_;
4141
mod u16;
4242
mod uz;

0 commit comments

Comments
 (0)