cli-test: Simplify cargo path handling

This commit is contained in:
Lorenz Leutgeb 2026-02-14 16:01:45 +01:00 committed by Fintan Halpenny
parent 25d1974c60
commit 4894657bcb
1 changed files with 13 additions and 17 deletions

View File

@ -187,21 +187,6 @@ impl TestFormula {
}
pub fn build(&mut self, binaries: &[(&str, &str)]) -> &mut Self {
let manifest = env::var("CARGO_MANIFEST_DIR").expect(
"TestFormula::build: cannot build binaries: variable `CARGO_MANIFEST_DIR` is not set",
);
let profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
let manifest = Path::new(manifest.as_str());
let bins = manifest.join(&target_dir).join(profile);
// Add the target dir to the beginning of the list we will use as `PATH`.
self.bins.insert(0, bins);
// We don't need to re-build every time the `build` function is called. Once is enough.
BUILD.call_once(|| {
use escargot::format::Message;
@ -220,8 +205,6 @@ impl TestFormula {
let results = escargot::CargoBuild::new()
.package(package)
.bin(binary)
.manifest_path(manifest.join("Cargo.toml"))
.target_dir(&target_dir)
.exec()
.unwrap();
@ -539,6 +522,19 @@ fn bins(cwd: PathBuf) -> Vec<PathBuf> {
.map(|env_path| env_path.split(PATH_SEPARATOR).map(PathBuf::from).collect())
.unwrap_or_default();
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
let profile = cfg!(debug_assertions)
.then_some("debug")
.unwrap_or("release");
let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
bins.push(
PathBuf::from(manifest_dir.as_str())
.join(&target_dir)
.join(profile),
)
}
// Add current working directory to `$PATH`,
// this makes it more convenient to execute scripts during testing.
bins.push(cwd);