2024-09-03 19:18:32 -05:00
|
|
|
#![cfg(all(test, not(any(target_os = "emscripten", target_os = "wasi", target_env = "sgx"))))]
|
2023-02-20 07:57:07 -06:00
|
|
|
|
2023-02-19 03:48:50 -06:00
|
|
|
//! Note that this test changes the current directory so
|
|
|
|
//! should not be in the same process as other tests.
|
2024-06-19 14:04:30 -05:00
|
|
|
|
2023-02-19 03:48:50 -06:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use std::{env, fs};
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
// On some platforms, setting the current directory will prevent deleting it.
|
|
|
|
// So this helper ensures the current directory is reset.
|
|
|
|
struct CurrentDir(PathBuf);
|
|
|
|
impl CurrentDir {
|
|
|
|
fn new() -> Self {
|
|
|
|
Self(env::current_dir().unwrap())
|
|
|
|
}
|
|
|
|
fn set(&self, path: &Path) {
|
|
|
|
env::set_current_dir(path).unwrap();
|
|
|
|
}
|
|
|
|
fn with(path: &Path, f: impl FnOnce()) {
|
|
|
|
let current_dir = Self::new();
|
|
|
|
current_dir.set(path);
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Drop for CurrentDir {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
env::set_current_dir(&self.0).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-04-15 03:15:14 -05:00
|
|
|
#[cfg_attr(all(miri, windows), ignore)] // File system access on Windows not supported by Miri
|
2023-02-19 03:48:50 -06:00
|
|
|
fn create_dir_all_bare() {
|
|
|
|
let tmpdir = common::tmpdir();
|
|
|
|
CurrentDir::with(tmpdir.path(), || {
|
|
|
|
fs::create_dir_all("create-dir-all-bare").unwrap();
|
|
|
|
});
|
|
|
|
}
|