|
| 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 | +} |
0 commit comments