Skip to content

Commit

Permalink
Merge pull request #46 from epage/mac
Browse files Browse the repository at this point in the history
test: Don't fail if troff is missing
  • Loading branch information
epage committed Jul 8, 2024
2 parents 3fcf366 + 669bde7 commit 47b08e2
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/testsuite/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use pretty_assertions::assert_eq;
fn demo() {
use roff::*;

if !has_command("troff") {
return;
}

let page = Roff::new()
.control("TH", ["CORRUPT", "1"])
.control("SH", ["NAME"])
Expand Down Expand Up @@ -63,3 +67,52 @@ fn roff_to_ascii(input: &str) -> String {
.read()
.unwrap()
}

pub(crate) fn has_command(command: &str) -> bool {
let output = match std::process::Command::new(command)
.arg("--version")
.output()
{
Ok(output) => output,
Err(e) => {
// CI is expected to support all of the commands
if is_ci() && cfg!(target_os = "linux") {
panic!(
"expected command `{}` to be somewhere in PATH: {}",
command, e
);
}
return false;
}
};
if !output.status.success() {
panic!(
"expected command `{}` to be runnable, got error {}:\n\
stderr:{}\n\
stdout:{}\n",
command,
output.status,
String::from_utf8_lossy(&output.stderr),
String::from_utf8_lossy(&output.stdout)
);
}
let stdout = String::from_utf8_lossy(&output.stdout);
println!(
"$ {command} --version
{}",
stdout
);
if cfg!(target_os = "macos") && stdout.starts_with("GNU bash, version 3") {
return false;
}

true
}

/// Whether or not this running in a Continuous Integration environment.
fn is_ci() -> bool {
// Consider using `tracked_env` instead of option_env! when it is stabilized.
// `tracked_env` will handle changes, but not require rebuilding the macro
// itself like option_env does.
option_env!("CI").is_some() || option_env!("TF_BUILD").is_some()
}

0 comments on commit 47b08e2

Please sign in to comment.