Skip to content

Commit ec28d38

Browse files
committed
Auto merge of #3516 - RalfJung:pathbuf, r=RalfJung
add smoke tests for basic PathBuf interactions I wrote these while debugging [this](https://github.com/rust-lang/miri-test-libstd/actions/runs/8849912635/job/24302962983); it turns out the issue is [more complicated](rust-lang/rust#124409) but these tests still seemed worth keeping.
2 parents 09a5b7c + 79198ae commit ec28d38

File tree

2 files changed

+60
-37
lines changed

2 files changed

+60
-37
lines changed

tests/pass/path.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//@compile-flags: -Zmiri-disable-isolation
2+
use std::path::{absolute, Path, PathBuf};
3+
4+
#[path = "../utils/mod.rs"]
5+
mod utils;
6+
7+
#[track_caller]
8+
fn assert_absolute_eq(in_: &str, out: &str) {
9+
assert_eq!(absolute(in_).unwrap().as_os_str(), Path::new(out).as_os_str());
10+
}
11+
12+
fn test_absolute() {
13+
if cfg!(unix) {
14+
assert_absolute_eq("/a/b/c", "/a/b/c");
15+
assert_absolute_eq("/a/b/c", "/a/b/c");
16+
assert_absolute_eq("/a//b/c", "/a/b/c");
17+
assert_absolute_eq("//a/b/c", "//a/b/c");
18+
assert_absolute_eq("///a/b/c", "/a/b/c");
19+
assert_absolute_eq("/a/b/c/", "/a/b/c/");
20+
assert_absolute_eq("/a/./b/../c/.././..", "/a/b/../c/../..");
21+
} else if cfg!(windows) {
22+
// Test that all these are unchanged
23+
assert_absolute_eq(r"C:\path\to\file", r"C:\path\to\file");
24+
assert_absolute_eq(r"C:\path\to\file\", r"C:\path\to\file\");
25+
assert_absolute_eq(r"\\server\share\to\file", r"\\server\share\to\file");
26+
assert_absolute_eq(r"\\server.\share.\to\file", r"\\server.\share.\to\file");
27+
assert_absolute_eq(r"\\.\PIPE\name", r"\\.\PIPE\name");
28+
assert_absolute_eq(r"\\.\C:\path\to\COM1", r"\\.\C:\path\to\COM1");
29+
assert_absolute_eq(r"\\?\C:\path\to\file", r"\\?\C:\path\to\file");
30+
assert_absolute_eq(r"\\?\UNC\server\share\to\file", r"\\?\UNC\server\share\to\file");
31+
assert_absolute_eq(r"\\?\PIPE\name", r"\\?\PIPE\name");
32+
// Verbatim paths are always unchanged, no matter what.
33+
assert_absolute_eq(r"\\?\path.\to/file..", r"\\?\path.\to/file..");
34+
35+
assert_absolute_eq(r"C:\path..\to.\file.", r"C:\path..\to\file");
36+
assert_absolute_eq(r"COM1", r"\\.\COM1");
37+
} else {
38+
panic!("unsupported OS");
39+
}
40+
}
41+
42+
fn buf_smoke(mut p: PathBuf) {
43+
for _c in p.components() {}
44+
45+
p.push("hello");
46+
for _c in p.components() {}
47+
48+
if cfg!(windows) {
49+
p.push(r"C:\mydir");
50+
} else {
51+
p.push(r"/mydir");
52+
}
53+
for _c in p.components() {}
54+
}
55+
56+
fn main() {
57+
buf_smoke(PathBuf::new());
58+
buf_smoke(utils::tmp());
59+
test_absolute();
60+
}

tests/pass/shims/path.rs

-37
This file was deleted.

0 commit comments

Comments
 (0)