diff --git a/crates/radicle-cli/tests/commands.rs b/crates/radicle-cli/tests/commands.rs index 4a09df05..90237014 100644 --- a/crates/radicle-cli/tests/commands.rs +++ b/crates/radicle-cli/tests/commands.rs @@ -1,3 +1,4 @@ +use core::panic; use std::path::Path; use std::str::FromStr; use std::{fs, net, thread, time}; @@ -50,6 +51,32 @@ pub(crate) fn test<'a>( Ok(()) } +/// A utility to check that some program can be executed with a `--version` +/// argument and exits successfully. +/// +/// # Panics +/// +/// If there is an error executing the program other than the program not being +/// found, or the program does not exit successfully. +fn program_reports_version(program: &str) -> bool { + use std::io::ErrorKind; + use std::process::{Command, Stdio}; + + match Command::new(program) + .arg("--version") + .stdout(Stdio::null()) + .status() + { + Err(e) if e.kind() == ErrorKind::NotFound => { + log::warn!(target: "test", "`{program}` not found."); + false + } + Err(e) => panic!("failure to execute `{program}`: {e}"), + Ok(status) if status.success() => true, + Ok(status) => panic!("executing `{program}` resulted in status {status}"), + } +} + #[test] fn rad_auth() { test("examples/rad-auth.md", Path::new("."), None, []).unwrap(); @@ -111,21 +138,11 @@ fn rad_cob_update_identity() { #[test] fn rad_cob_multiset() { - { - // `rad-cob-multiset` is a `jq` script, which requires `jq` to be installed. - // We test whether `jq` is installed, and have this test succeed if it is not. - // Programmatic skipping of tests is not supported as of 2024-08. - use std::io::ErrorKind; - use std::process::{Command, Stdio}; - - match Command::new("jq").arg("-V").stdout(Stdio::null()).status() { - Err(e) if e.kind() == ErrorKind::NotFound => { - log::warn!(target: "test", "`jq` not found. Succeeding prematurely."); - return; - } - Err(e) => panic!("while checking for jq: {e}"), - Ok(_) => {} - } + // `rad-cob-multiset` is a `jq` script, which requires `jq` to be installed. + // We test whether `jq` is installed, and have this test succeed if it is not. + // Programmatic skipping of tests is not supported as of 2024-08. + if !program_reports_version("jq") { + return; } let mut environment = Environment::new();