From bedc69dcf092dfeb7c327627855f85cbfeaa09e7 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 14 Mar 2026 14:12:30 +0100 Subject: [PATCH 1/7] Upgrade cargo_metadata --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6456a1a..587b874 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.76" [dependencies] anyhow = "1.0.20" backtrace = "0.3.55" -cargo_metadata = "0.14.0" +cargo_metadata = "0.23.0" once_cell = "1.5" sysinfo = { version = "0.26", default-features = false } whoami = "1" From 661573631ddf1c6c765cd6aa5576d1ccc5a33834 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 14 Mar 2026 14:32:04 +0100 Subject: [PATCH 2/7] Remove once_cell dependency and use newer std types instead --- .github/workflows/ci.yml | 2 +- Cargo.toml | 3 +-- src/lib.rs | 5 ++--- src/macros.rs | 8 ++++---- src/private.rs | 4 ++-- tests/macro.rs | 6 +++--- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9430b7..bdc3e8d 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.80" RUST_BACKTRACE: "1" RUSTFLAGS: "-Dwarnings" RUSTDOCFLAGS: "-Dwarnings" diff --git a/Cargo.toml b/Cargo.toml index 587b874..ccee52e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,12 @@ 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.80" [dependencies] anyhow = "1.0.20" backtrace = "0.3.55" cargo_metadata = "0.23.0" -once_cell = "1.5" sysinfo = { version = "0.26", default-features = false } whoami = "1" 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/private.rs b/src/private.rs index 556ce42..a63a754 100644 --- a/src/private.rs +++ b/src/private.rs @@ -8,8 +8,8 @@ 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}; 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"; 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() { From 174511b3377aea2cc65a2b6cd7583840531d2013 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 14 Mar 2026 14:38:12 +0100 Subject: [PATCH 3/7] bump whoami --- Cargo.toml | 2 +- src/builder.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ccee52e..f7b82db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ anyhow = "1.0.20" backtrace = "0.3.55" cargo_metadata = "0.23.0" sysinfo = { version = "0.26", default-features = false } -whoami = "1" +whoami = "2" # Force old version of cargo-platform before they bumped the MSRV cargo-platform = ">=0.1.2, <0.1.9" diff --git a/src/builder.rs b/src/builder.rs index 1f6ed47..a194857 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use anyhow::{Context, Error, Result}; -use crate::{NumberedDir, KEEP_DEFAULT, ROOT_DEFAULT}; +use crate::{KEEP_DEFAULT, NumberedDir, ROOT_DEFAULT}; /// Builder to create a [`NumberedDir`]. /// @@ -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 } From 787aa196f9bda5c22ac25e12146ea9702ba72793 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 14 Mar 2026 15:10:07 +0100 Subject: [PATCH 4/7] update sysinfo, fallback to process name if exe is unavailable This updates to the latest sysinfo. It also adds an expclicit fallback to the process name if the executable is not available, which can happen on linux. This used to be fairly silent before. AFAIK none of the test runners change their executable name currently so that is not really a concern. --- Cargo.toml | 2 +- src/private.rs | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f7b82db..7c9089f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ rust-version = "1.80" anyhow = "1.0.20" backtrace = "0.3.55" cargo_metadata = "0.23.0" -sysinfo = { version = "0.26", default-features = false } +sysinfo = { version = "0.38", default-features = false, features = ["system"] } whoami = "2" # Force old version of cargo-platform before they bumped the MSRV diff --git a/src/private.rs b/src/private.rs index a63a754..79be3e1 100644 --- a/src/private.rs +++ b/src/private.rs @@ -10,7 +10,7 @@ use std::fs; use std::path::Path; use std::sync::LazyLock; -use sysinfo::{Pid, ProcessExt, SystemExt}; +use sysinfo::Pid; pub use cargo_metadata; @@ -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 From 5b0da642561f092f42ebc2f678f643d1f70a336e Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 14 Mar 2026 15:15:11 +0100 Subject: [PATCH 5/7] update cargo-platform msrv is now 1.88 which is middle of last year... --- .github/workflows/ci.yml | 2 +- Cargo.toml | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdc3e8d..f25d028 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ concurrency: cancel-in-progress: true env: - MSRV: "1.80" + MSRV: "1.88" RUST_BACKTRACE: "1" RUSTFLAGS: "-Dwarnings" RUSTDOCFLAGS: "-Dwarnings" diff --git a/Cargo.toml b/Cargo.toml index 7c9089f..4c4bd17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,17 +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.80" +rust-version = "1.88" [dependencies] anyhow = "1.0.20" backtrace = "0.3.55" +cargo-platform = "0.3" cargo_metadata = "0.23.0" sysinfo = { version = "0.38", default-features = false, features = ["system"] } whoami = "2" -# Force old version of cargo-platform before they bumped the MSRV -cargo-platform = ">=0.1.2, <0.1.9" - [dev-dependencies] tempfile = "3" From 2b51161566343c9918a3623b74aa12180d9eb2e2 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 14 Mar 2026 15:20:35 +0100 Subject: [PATCH 6/7] bump ci, clippy --- .github/workflows/ci.yml | 16 ++++++++-------- src/numbered_dir.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f25d028..bf5294b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/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())); } } } From be8ac23b11d52e0c036c9be8c46f90fbfb4df4c6 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 14 Mar 2026 15:22:49 +0100 Subject: [PATCH 7/7] what's up with cargo fmt? --- src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index a194857..6f01b6e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use anyhow::{Context, Error, Result}; -use crate::{KEEP_DEFAULT, NumberedDir, ROOT_DEFAULT}; +use crate::{NumberedDir, KEEP_DEFAULT, ROOT_DEFAULT}; /// Builder to create a [`NumberedDir`]. ///