#![allow(dead_code)]
pub(crate) const CHILD_MARKER: &str = "RELIAR_STORE_POSTGRES_TEST_CHILD";
pub(crate) fn run_scenario_in_child(
test_name: &str,
envs: &[(&str, &str)],
) -> std::io::Result<bool> {
let exe = std::env::current_exe()?;
let mut command = std::process::Command::new(exe);
command.arg("--exact").arg(test_name).env(CHILD_MARKER, "1");
for (key, value) in envs {
command.env(key, value);
}
let output = command.output()?;
let stdout = String::from_utf8_lossy(&output.stdout);
let ran_exactly_the_one_scenario = stdout.contains("1 passed; 0 failed");
if !output.status.success() || !ran_exactly_the_one_scenario {
eprintln!(
"child scenario `{test_name}` did not cleanly report `1 passed; 0 failed`:\n{stdout}"
);
}
Ok(output.status.success() && ran_exactly_the_one_scenario)
}
pub(crate) fn is_child() -> bool {
std::env::var_os(CHILD_MARKER).is_some()
}