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.
This commit is contained in:
parent
d88ef3fa66
commit
5aca9bf16a
|
|
@ -4,17 +4,12 @@ use std::collections::HashMap;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync;
|
use std::sync;
|
||||||
use std::{env, ffi, fs, io, mem};
|
use std::{env, fs, io, mem};
|
||||||
|
|
||||||
use snapbox::cmd::{Command, OutputAssert};
|
use snapbox::cmd::{Command, OutputAssert};
|
||||||
use snapbox::{Assert, Substitutions};
|
use snapbox::{Assert, Substitutions};
|
||||||
use thiserror::Error;
|
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.
|
/// Used to ensure the build task is only run once.
|
||||||
static BUILD: sync::Once = sync::Once::new();
|
static BUILD: sync::Once = sync::Once::new();
|
||||||
|
|
||||||
|
|
@ -462,11 +457,7 @@ impl TestFormula {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
|
||||||
let bins = bins(self.cwd.clone())
|
let bins = std::env::join_paths(bins(self.cwd.clone())).unwrap();
|
||||||
.iter()
|
|
||||||
.map(|p| p.as_os_str())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(ffi::OsStr::new(&PATH_SEPARATOR.to_string()));
|
|
||||||
|
|
||||||
let command = Command::new(cmd.clone())
|
let command = Command::new(cmd.clone())
|
||||||
.env_clear()
|
.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.
|
/// starting with the current working directory.
|
||||||
fn bins(cwd: PathBuf) -> Vec<PathBuf> {
|
fn bins(cwd: PathBuf) -> Vec<PathBuf> {
|
||||||
let mut bins: Vec<PathBuf> = env::var("PATH")
|
let mut bins: Vec<PathBuf> = Vec::new();
|
||||||
.map(|env_path| env_path.split(PATH_SEPARATOR).map(PathBuf::from).collect())
|
|
||||||
.unwrap_or_default();
|
// 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") {
|
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
|
||||||
let profile = cfg!(debug_assertions)
|
let profile = cfg!(debug_assertions)
|
||||||
|
|
@ -551,6 +544,11 @@ fn bins(cwd: PathBuf) -> Vec<PathBuf> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the "real" `$PATH`.
|
||||||
|
if let Ok(path) = env::var("PATH") {
|
||||||
|
bins.extend(env::split_paths(&path));
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
// Radicle CLI tests rely on various Unix coreutils
|
// Radicle CLI tests rely on various Unix coreutils
|
||||||
|
|
@ -562,9 +560,6 @@ fn bins(cwd: PathBuf) -> Vec<PathBuf> {
|
||||||
bins.push(PathBuf::from(r#"C:\Program Files\Git\usr\bin"#));
|
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
|
bins
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue