#![allow(dead_code)]
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
pub fn sonda_bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_sonda"))
}
pub fn cli_fixtures_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/cli")
}
pub fn sonda_command(scenario_dir: Option<&Path>, pack_dir: Option<&Path>) -> Command {
let mut cmd = Command::new(sonda_bin());
cmd.env_remove("SONDA_SCENARIO_PATH");
cmd.env_remove("SONDA_PACK_PATH");
if let Some(p) = scenario_dir {
cmd.arg("--scenario-path").arg(p);
}
if let Some(p) = pack_dir {
cmd.arg("--pack-path").arg(p);
}
cmd
}
pub fn run_and_check(mut cmd: Command, expect_success: bool) -> Output {
let output = cmd.output().expect("must spawn sonda binary");
let succeeded = output.status.success();
if succeeded != expect_success {
panic!(
"unexpected exit: success={succeeded}\nstatus: {:?}\nstdout:\n{}\nstderr:\n{}",
output.status.code(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
}
output
}
pub fn sonda_ok(args: &[&str]) -> Output {
let mut cmd = Command::new(sonda_bin());
cmd.env_remove("SONDA_SCENARIO_PATH");
cmd.env_remove("SONDA_PACK_PATH");
cmd.args(args);
run_and_check(cmd, true)
}