cli-test: Deduplicate populating `bins`
This commit is contained in:
parent
44f52f4c18
commit
25d1974c60
|
|
@ -169,7 +169,8 @@ pub struct TestFormula {
|
||||||
tests: Vec<Test>,
|
tests: Vec<Test>,
|
||||||
/// Output substitutions.
|
/// Output substitutions.
|
||||||
subs: Substitutions,
|
subs: Substitutions,
|
||||||
/// Binaries path.
|
/// List of paths to directories to be searched for binaries.
|
||||||
|
/// This is used to construct the `PATH` environment variable for the tests.
|
||||||
bins: Vec<PathBuf>,
|
bins: Vec<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,16 +182,7 @@ impl TestFormula {
|
||||||
homes: HashMap::new(),
|
homes: HashMap::new(),
|
||||||
tests: Vec::new(),
|
tests: Vec::new(),
|
||||||
subs: Substitutions::new(),
|
subs: Substitutions::new(),
|
||||||
bins: env::var("PATH")
|
bins: bins(cwd),
|
||||||
.map(|env_path| {
|
|
||||||
let mut bins: Vec<PathBuf> =
|
|
||||||
env_path.split(PATH_SEPARATOR).map(PathBuf::from).collect();
|
|
||||||
// Add current working directory to `$PATH`,
|
|
||||||
// this makes it more convenient to execute scripts during testing.
|
|
||||||
bins.push(cwd);
|
|
||||||
bins
|
|
||||||
})
|
|
||||||
.unwrap_or_default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -540,6 +532,19 @@ impl TestFormula {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the list of binary paths to use as `PATH` for the tests,
|
||||||
|
/// starting with the current working directory.
|
||||||
|
fn bins(cwd: PathBuf) -> Vec<PathBuf> {
|
||||||
|
let mut bins: Vec<PathBuf> = env::var("PATH")
|
||||||
|
.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);
|
||||||
|
bins
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -581,15 +586,7 @@ $ rad sync
|
||||||
cwd: cwd.clone(),
|
cwd: cwd.clone(),
|
||||||
env: HashMap::new(),
|
env: HashMap::new(),
|
||||||
subs: Substitutions::new(),
|
subs: Substitutions::new(),
|
||||||
bins: {
|
bins: bins(cwd),
|
||||||
let mut bins: Vec<_> = env::var("PATH")
|
|
||||||
.unwrap_or_default()
|
|
||||||
.split(PATH_SEPARATOR)
|
|
||||||
.map(PathBuf::from)
|
|
||||||
.collect();
|
|
||||||
bins.push(cwd);
|
|
||||||
bins
|
|
||||||
},
|
|
||||||
tests: vec![
|
tests: vec![
|
||||||
Test {
|
Test {
|
||||||
context: vec![String::from("Let's try to track @dave and @sean:")],
|
context: vec![String::from("Let's try to track @dave and @sean:")],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue