Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle-cli/tests: `fn program_reports_version`
Lorenz Leutgeb committed 7 months ago
commit c4d13976481b09bb216b6d6860e5b7cfc827ddb9
parent 210159b8569304f9eaae3134ac0e482632858462
1 file changed +32 -15
modified crates/radicle-cli/tests/commands.rs
@@ -1,3 +1,4 @@
+
use core::panic;
use std::path::Path;
use std::str::FromStr;
use std::{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();
@@ -97,21 +124,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();