diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9430b7..bf5294b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ concurrency: cancel-in-progress: true env: - MSRV: "1.76" + MSRV: "1.88" RUST_BACKTRACE: "1" RUSTFLAGS: "-Dwarnings" RUSTDOCFLAGS: "-Dwarnings" @@ -20,11 +20,11 @@ jobs: lints: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - - uses: mozilla-actions/sccache-action@v0.0.6 + - uses: mozilla-actions/sccache-action@v0.0.9 - run: cargo fmt --check - run: cargo clippy --no-deps - run: cargo doc --no-deps --document-private-items @@ -36,18 +36,18 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@stable - - uses: mozilla-actions/sccache-action@v0.0.6 + - uses: mozilla-actions/sccache-action@v0.0.9 - uses: taiki-e/install-action@nextest - run: cargo test - run: cargo nextest run minimal-crates: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@nightly - - uses: mozilla-actions/sccache-action@v0.0.6 + - uses: mozilla-actions/sccache-action@v0.0.9 - name: cargo check run: | rm -f Cargo.lock @@ -55,11 +55,11 @@ jobs: msrv: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.MSRV }} - - uses: mozilla-actions/sccache-action@v0.0.6 + - uses: mozilla-actions/sccache-action@v0.0.9 - name: Check MSRV run: | cargo +$MSRV check diff --git a/Cargo.toml b/Cargo.toml index 6456a1a..4c4bd17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,18 +11,15 @@ keywords = ["test", "temp", "temporary", "directory"] categories = ["development-tools::testing", "filesystem"] # Sadly this also needs to be updated in .github/workflows/ci.yml -rust-version = "1.76" +rust-version = "1.88" [dependencies] anyhow = "1.0.20" backtrace = "0.3.55" -cargo_metadata = "0.14.0" -once_cell = "1.5" -sysinfo = { version = "0.26", default-features = false } -whoami = "1" - -# Force old version of cargo-platform before they bumped the MSRV -cargo-platform = ">=0.1.2, <0.1.9" +cargo-platform = "0.3" +cargo_metadata = "0.23.0" +sysinfo = { version = "0.38", default-features = false, features = ["system"] } +whoami = "2" [dev-dependencies] tempfile = "3" diff --git a/src/builder.rs b/src/builder.rs index 1f6ed47..6f01b6e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -80,7 +80,11 @@ impl NumberedDirBuilder { if base.contains('/') || base.contains('\\') { panic!("base must not contain path separators"); } - let root = format!("{}-of-{}", ROOT_DEFAULT, whoami::username()); + let root = format!( + "{}-of-{}", + ROOT_DEFAULT, + whoami::username().unwrap_or("unknown".to_string()) + ); Self { parent: std::env::temp_dir().join(root), base, @@ -110,7 +114,11 @@ impl NumberedDirBuilder { /// temporary directory location as the parent direcotry for the [`NumberedDir`]. /// However it suffixes the username to the given `prefix` to use as *root*. pub fn user_root(&mut self, prefix: &str) -> &mut Self { - let root = format!("{}{}", prefix, whoami::username()); + let root = format!( + "{}{}", + prefix, + whoami::username().unwrap_or("unknown".to_string()) + ); self.parent.set_file_name(root); self } diff --git a/src/lib.rs b/src/lib.rs index ef5759b..4bece74 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,8 +53,7 @@ #![warn(missing_docs, missing_debug_implementations, clippy::all)] use std::num::NonZeroU8; - -use once_cell::sync::OnceCell; +use std::sync::OnceLock; mod builder; mod macros; @@ -77,7 +76,7 @@ pub const KEEP_DEFAULT: Option = NonZeroU8::new(8); /// /// Do not use this directly, use [`init_testdir!`] to initialise this. #[doc(hidden)] -pub static TESTDIR: OnceCell = OnceCell::new(); +pub static TESTDIR: OnceLock = OnceLock::new(); /// Executes a function passing the global [`NumberedDir`] instance. /// diff --git a/src/macros.rs b/src/macros.rs index 79f1072..8d7f3eb 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -60,14 +60,14 @@ /// ``` /// These constructs can also be used in a doctest. /// -/// The module path is valid in any scope, so can be used together with [once_cell] (or -/// [lazy_static]) to share a common directory between different tests. +/// The module path is valid in any scope, so can be used together with +/// e.g. [`std::sync::LazyLock`] to share a common directory between different tests. /// ```no_run +/// use std::sync::LazyLock; /// use std::path::PathBuf; -/// use once_cell::sync::Lazy; /// use testdir::testdir; /// -/// static TDIR: Lazy = Lazy::new(|| testdir!(ModuleScope)); +/// static TDIR: LazyLock = LazyLock::new(|| testdir!(ModuleScope)); /// /// #[test] /// fn test_module_scope() { diff --git a/src/numbered_dir.rs b/src/numbered_dir.rs index 7bc9a22..6e61102 100644 --- a/src/numbered_dir.rs +++ b/src/numbered_dir.rs @@ -143,7 +143,7 @@ fn remove_obsolete_dirs(dir: impl AsRef, base: &str, current: u16, keep: u Err(err) if err.kind() == ErrorKind::NotFound => (), Err(err) => { return Err(err) - .with_context(|| format!("Failed to remove {}", numdir.path().display())) + .with_context(|| format!("Failed to remove {}", numdir.path().display())); } } } diff --git a/src/private.rs b/src/private.rs index 556ce42..79be3e1 100644 --- a/src/private.rs +++ b/src/private.rs @@ -8,9 +8,9 @@ use std::ffi::OsStr; use std::fs; use std::path::Path; +use std::sync::LazyLock; -use once_cell::sync::Lazy; -use sysinfo::{Pid, ProcessExt, SystemExt}; +use sysinfo::Pid; pub use cargo_metadata; @@ -18,7 +18,7 @@ pub use cargo_metadata; const CARGO_PID_FILE_NAME: &str = "cargo-pid"; /// Whether we are a cargo sub-process. -static CARGO_PID: Lazy> = Lazy::new(cargo_pid); +static CARGO_PID: LazyLock> = LazyLock::new(cargo_pid); #[cfg(target_family = "unix")] const CARGO_NAME: &str = "cargo"; @@ -45,25 +45,30 @@ const NEXTEST_NAME: &str = "cargo-nextest.exe"; // assert!(pidfile.is_file()); // ``` fn cargo_pid() -> Option { - let mut sys = sysinfo::System::new(); let pid = sysinfo::get_current_pid().ok()?; - let what = sysinfo::ProcessRefreshKind::new(); - sys.refresh_process_specifics(pid, what); + + let mut sys = sysinfo::System::new(); + let what = sysinfo::ProcessRefreshKind::nothing().with_exe(sysinfo::UpdateKind::OnlyIfNotSet); + sys.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[pid]), false, what); let current = sys.process(pid)?; let ppid = current.parent()?; - sys.refresh_process_specifics(ppid, what); + sys.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[ppid]), false, what); let parent = sys.process(ppid)?; - let parent_exe = parent.exe(); - let parent_file_name = parent_exe.file_name()?; - if parent_file_name == OsStr::new(CARGO_NAME) || parent_file_name == OsStr::new(NEXTEST_NAME) { + let parent_name = parent + .exe() + .and_then(|exe| exe.file_name()) + .unwrap_or_else(|| parent.name()); + if parent_name == OsStr::new(CARGO_NAME) || parent_name == OsStr::new(NEXTEST_NAME) { Some(parent.pid()) - } else if parent_file_name == OsStr::new("rustdoc") { + } else if parent_name == OsStr::new("rustdoc") { let ppid = parent.parent()?; - sys.refresh_process_specifics(ppid, what); + sys.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[ppid]), false, what); let parent = sys.process(ppid)?; - let parent_exe = parent.exe(); - let parent_file_name = parent_exe.file_name()?; - if parent_file_name == OsStr::new("cargo") { + let parent_name = parent + .exe() + .and_then(|exe| exe.file_name()) + .unwrap_or_else(|| parent.name()); + if parent_name == OsStr::new("cargo") { Some(parent.pid()) } else { None diff --git a/tests/macro.rs b/tests/macro.rs index ae2a39f..ca75eca 100644 --- a/tests/macro.rs +++ b/tests/macro.rs @@ -1,9 +1,9 @@ use std::path::{Path, PathBuf}; +use std::sync::LazyLock; -use once_cell::sync::Lazy; use testdir::testdir; -static MOD_LEVEL: Lazy = Lazy::new(|| testdir!(ModuleScope)); +static MOD_LEVEL: LazyLock = LazyLock::new(|| testdir!(ModuleScope)); #[test] fn test_macro() { @@ -74,7 +74,7 @@ fn test_cargo_pid_created() { mod submodule { use super::*; - static SUB_MOD: Lazy = Lazy::new(|| testdir!(ModuleScope)); + static SUB_MOD: LazyLock = LazyLock::new(|| testdir!(ModuleScope)); #[test] fn test_test_scope() {