From 5aca9bf16aff8323009b11137c4e998315128d1e Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 16 Feb 2026 18:52:34 +0100 Subject: [PATCH] cli-test: Refactor Path Handling In the previous refactoring in commit `4894657b`, the order of entries in `$PATH` was changed unintentionally. Revisit the order and use nicer APIs to handle paths. --- crates/radicle-cli-test/src/lib.rs | 31 +++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/crates/radicle-cli-test/src/lib.rs b/crates/radicle-cli-test/src/lib.rs index df15c842..e6e9298a 100644 --- a/crates/radicle-cli-test/src/lib.rs +++ b/crates/radicle-cli-test/src/lib.rs @@ -4,17 +4,12 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync; -use std::{env, ffi, fs, io, mem}; +use std::{env, fs, io, mem}; use snapbox::cmd::{Command, OutputAssert}; use snapbox::{Assert, Substitutions}; use thiserror::Error; -#[cfg(windows)] -const PATH_SEPARATOR: char = ';'; -#[cfg(not(windows))] -const PATH_SEPARATOR: char = ':'; - /// Used to ensure the build task is only run once. static BUILD: sync::Once = sync::Once::new(); @@ -462,11 +457,7 @@ impl TestFormula { vec![] }; - let bins = bins(self.cwd.clone()) - .iter() - .map(|p| p.as_os_str()) - .collect::>() - .join(ffi::OsStr::new(&PATH_SEPARATOR.to_string())); + let bins = std::env::join_paths(bins(self.cwd.clone())).unwrap(); let command = Command::new(cmd.clone()) .env_clear() @@ -531,12 +522,14 @@ impl TestFormula { } } -/// Get the list of binary paths to use as `PATH` for the tests, +/// Get the list of binary paths to use as `$PATH` for the tests, /// starting with the current working directory. fn bins(cwd: PathBuf) -> Vec { - let mut bins: Vec = env::var("PATH") - .map(|env_path| env_path.split(PATH_SEPARATOR).map(PathBuf::from).collect()) - .unwrap_or_default(); + let mut bins: Vec = Vec::new(); + + // Add current working directory to `$PATH`, + // this makes it more convenient to execute scripts during testing. + bins.push(cwd); if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") { let profile = cfg!(debug_assertions) @@ -551,6 +544,11 @@ fn bins(cwd: PathBuf) -> Vec { ) } + // Add the "real" `$PATH`. + if let Ok(path) = env::var("PATH") { + bins.extend(env::split_paths(&path)); + } + #[cfg(windows)] { // Radicle CLI tests rely on various Unix coreutils @@ -562,9 +560,6 @@ fn bins(cwd: PathBuf) -> Vec { bins.push(PathBuf::from(r#"C:\Program Files\Git\usr\bin"#)); } - // Add current working directory to `$PATH`, - // this makes it more convenient to execute scripts during testing. - bins.push(cwd); bins }