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](https://github.com/rust-lang/rust/issues/124409) but these tests still seemed worth keeping.
This commit is contained in:
commit
d7c89cfbf8
60
src/tools/miri/tests/pass/path.rs
Normal file
60
src/tools/miri/tests/pass/path.rs
Normal file
@ -0,0 +1,60 @@
|
||||
//@compile-flags: -Zmiri-disable-isolation
|
||||
use std::path::{absolute, Path, PathBuf};
|
||||
|
||||
#[path = "../utils/mod.rs"]
|
||||
mod utils;
|
||||
|
||||
#[track_caller]
|
||||
fn assert_absolute_eq(in_: &str, out: &str) {
|
||||
assert_eq!(absolute(in_).unwrap().as_os_str(), Path::new(out).as_os_str());
|
||||
}
|
||||
|
||||
fn test_absolute() {
|
||||
if cfg!(unix) {
|
||||
assert_absolute_eq("/a/b/c", "/a/b/c");
|
||||
assert_absolute_eq("/a/b/c", "/a/b/c");
|
||||
assert_absolute_eq("/a//b/c", "/a/b/c");
|
||||
assert_absolute_eq("//a/b/c", "//a/b/c");
|
||||
assert_absolute_eq("///a/b/c", "/a/b/c");
|
||||
assert_absolute_eq("/a/b/c/", "/a/b/c/");
|
||||
assert_absolute_eq("/a/./b/../c/.././..", "/a/b/../c/../..");
|
||||
} else if cfg!(windows) {
|
||||
// Test that all these are unchanged
|
||||
assert_absolute_eq(r"C:\path\to\file", r"C:\path\to\file");
|
||||
assert_absolute_eq(r"C:\path\to\file\", r"C:\path\to\file\");
|
||||
assert_absolute_eq(r"\\server\share\to\file", r"\\server\share\to\file");
|
||||
assert_absolute_eq(r"\\server.\share.\to\file", r"\\server.\share.\to\file");
|
||||
assert_absolute_eq(r"\\.\PIPE\name", r"\\.\PIPE\name");
|
||||
assert_absolute_eq(r"\\.\C:\path\to\COM1", r"\\.\C:\path\to\COM1");
|
||||
assert_absolute_eq(r"\\?\C:\path\to\file", r"\\?\C:\path\to\file");
|
||||
assert_absolute_eq(r"\\?\UNC\server\share\to\file", r"\\?\UNC\server\share\to\file");
|
||||
assert_absolute_eq(r"\\?\PIPE\name", r"\\?\PIPE\name");
|
||||
// Verbatim paths are always unchanged, no matter what.
|
||||
assert_absolute_eq(r"\\?\path.\to/file..", r"\\?\path.\to/file..");
|
||||
|
||||
assert_absolute_eq(r"C:\path..\to.\file.", r"C:\path..\to\file");
|
||||
assert_absolute_eq(r"COM1", r"\\.\COM1");
|
||||
} else {
|
||||
panic!("unsupported OS");
|
||||
}
|
||||
}
|
||||
|
||||
fn buf_smoke(mut p: PathBuf) {
|
||||
for _c in p.components() {}
|
||||
|
||||
p.push("hello");
|
||||
for _c in p.components() {}
|
||||
|
||||
if cfg!(windows) {
|
||||
p.push(r"C:\mydir");
|
||||
} else {
|
||||
p.push(r"/mydir");
|
||||
}
|
||||
for _c in p.components() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
buf_smoke(PathBuf::new());
|
||||
buf_smoke(utils::tmp());
|
||||
test_absolute();
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
//@compile-flags: -Zmiri-disable-isolation
|
||||
use std::path::{absolute, Path};
|
||||
|
||||
#[track_caller]
|
||||
fn test_absolute(in_: &str, out: &str) {
|
||||
assert_eq!(absolute(in_).unwrap().as_os_str(), Path::new(out).as_os_str());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if cfg!(unix) {
|
||||
test_absolute("/a/b/c", "/a/b/c");
|
||||
test_absolute("/a/b/c", "/a/b/c");
|
||||
test_absolute("/a//b/c", "/a/b/c");
|
||||
test_absolute("//a/b/c", "//a/b/c");
|
||||
test_absolute("///a/b/c", "/a/b/c");
|
||||
test_absolute("/a/b/c/", "/a/b/c/");
|
||||
test_absolute("/a/./b/../c/.././..", "/a/b/../c/../..");
|
||||
} else if cfg!(windows) {
|
||||
// Test that all these are unchanged
|
||||
test_absolute(r"C:\path\to\file", r"C:\path\to\file");
|
||||
test_absolute(r"C:\path\to\file\", r"C:\path\to\file\");
|
||||
test_absolute(r"\\server\share\to\file", r"\\server\share\to\file");
|
||||
test_absolute(r"\\server.\share.\to\file", r"\\server.\share.\to\file");
|
||||
test_absolute(r"\\.\PIPE\name", r"\\.\PIPE\name");
|
||||
test_absolute(r"\\.\C:\path\to\COM1", r"\\.\C:\path\to\COM1");
|
||||
test_absolute(r"\\?\C:\path\to\file", r"\\?\C:\path\to\file");
|
||||
test_absolute(r"\\?\UNC\server\share\to\file", r"\\?\UNC\server\share\to\file");
|
||||
test_absolute(r"\\?\PIPE\name", r"\\?\PIPE\name");
|
||||
// Verbatim paths are always unchanged, no matter what.
|
||||
test_absolute(r"\\?\path.\to/file..", r"\\?\path.\to/file..");
|
||||
|
||||
test_absolute(r"C:\path..\to.\file.", r"C:\path..\to\file");
|
||||
test_absolute(r"COM1", r"\\.\COM1");
|
||||
} else {
|
||||
panic!("unsupported OS");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user