use std::process::Command;
fn domi_bin() -> &'static str {
env!("CARGO_BIN_EXE_domi")
}
fn run_domi(args: &[&str]) -> (String, String, i32) {
let out = Command::new(domi_bin())
.args(args)
.env("RUST_BACKTRACE", "0")
.output()
.expect("spawn domi");
let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
let code = out.status.code().unwrap_or(-1);
(stdout, stderr, code)
}
fn assert_contains_all(haystack: &str, needles: &[&str], context: &str) {
let mut missing: Vec<&str> = Vec::new();
for n in needles {
if !haystack.contains(n) {
missing.push(n);
}
}
assert!(
missing.is_empty(),
"{context}: expected help to contain {missing:?}\n--- actual output ---\n{haystack}"
);
}
#[test]
fn cli_help_lists_subcommands() {
let (stdout, _stderr, code) = run_domi(&["--help"]);
assert_eq!(code, 0, "`domi --help` should exit 0 (got {code})");
assert_contains_all(&stdout, &["tail", "replay", "push"], "domi --help");
}
#[test]
fn cli_tail_help_lists_follow() {
let (stdout, _stderr, code) = run_domi(&["tail", "--help"]);
assert_eq!(code, 0, "`domi tail --help` should exit 0 (got {code})");
assert_contains_all(
&stdout,
&["--follow", "--limit", "--doc", "--server"],
"domi tail --help",
);
}
#[test]
fn cli_push_help_requires_type() {
let (stdout, _stderr, code) = run_domi(&["push", "--help"]);
assert_eq!(code, 0, "`domi push --help` should exit 0 (got {code})");
assert_contains_all(
&stdout,
&["--type <TYPE>"],
"domi push --help (required --type placeholder)",
);
let (_stdout, _stderr, push_code) = run_domi(&["push"]);
assert_ne!(
push_code, 0,
"`domi push` without --type must fail (got exit 0)"
);
}
#[test]
fn cli_replay_help_lists_since() {
let (stdout, _stderr, code) = run_domi(&["replay", "--help"]);
assert_eq!(code, 0, "`domi replay --help` should exit 0 (got {code})");
assert_contains_all(
&stdout,
&["--since", "--doc", "--limit", "--server"],
"domi replay --help",
);
}