test,cli: wire pkh test into the CLI

Argument wiring only, per the report ports: the live view carries
phases and the outcome, the per-test report renders after the run
(text or --json) and decides the exit code; runtime errors exit 2.
--list-tests prints the parsed debian/tests/control and exits without
booting a testbed.
This commit is contained in:
2026-09-27 21:04:03 +02:00
parent 299b5c28c3
commit 2a9287d942
2 changed files with 241 additions and 0 deletions
+28
View File
@@ -536,6 +536,34 @@ fn create_run_dir(package: &str, series: &str, arch: &str) -> std::io::Result<Pa
Ok(dir)
}
/// Render the tests declared in the tree's `debian/tests/control`, one
/// block per test (`pkh test --list-tests`).
pub fn list_tests(tree: &Path) -> Result<String, Box<dyn std::error::Error>> {
let tests_control = TestsControl::parse(&tree.join("debian/tests/control"))
.map_err(|e| format!("cannot parse debian/tests/control: {e}"))?;
let mut out = String::new();
for test in &tests_control.tests {
out.push_str(&test.name);
out.push('\n');
if let Some(command) = &test.command {
out.push_str(&format!(" Test-Command: {command}\n"));
}
if !test.restrictions.is_empty() {
out.push_str(&format!(
" Restrictions: {}\n",
test.restrictions.join(" ")
));
}
if let Some(depends) = &test.depends {
out.push_str(&format!(" Depends: {depends}\n"));
}
if let Some(directory) = &test.tests_directory {
out.push_str(&format!(" Tests-Directory: {directory}\n"));
}
}
Ok(out)
}
/// The binary package name of a staged .deb file name.
fn deb_binary_name(path: &Path) -> Option<String> {
let name = path.file_name()?.to_string_lossy();