use std::process::Command;

#[test]
fn rpki_bin_help_exits_success_and_prints_usage() {
    // This also increases coverage for `src/bin/rpki.rs` because it executes the binary.
    let exe = env!("CARGO_BIN_EXE_rpki");
    let out = Command::new(exe)
        .arg("--help")
        .output()
        .expect("run rpki --help");

    assert!(out.status.success(), "status={}", out.status);
    let stdout = String::from_utf8_lossy(&out.stdout);
    // `cli::usage()` contains "Usage:".
    assert!(
        stdout.contains("Usage:") || stdout.contains("USAGE:"),
        "stdout={stdout}"
    );
}

#[test]
fn rpki_bin_without_args_exits_2_and_prints_error() {
    let exe = env!("CARGO_BIN_EXE_rpki");
    let out = Command::new(exe).output().expect("run rpki");

    assert_eq!(out.status.code(), Some(2), "status={}", out.status);
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        !stderr.trim().is_empty(),
        "expected non-empty stderr, got empty"
    );
}
