#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
// SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
// SPDX-License-Identifier: BSD-2-Clause
//! Make sure `timelimit-cli` with bad arguments fails.

#![expect(clippy::tests_outside_test_module, reason = "integration test")]

use std::process::{Command, Stdio};

use anyhow::{Context as _, Result, anyhow, bail};
use roundlet::test_exe;
use sysexits::ExitCode;

#[test]
fn no_args() -> Result<()> {
    let exe_paths = test_exe::find_exe_paths(&["timelimit-cli"]);
    // Switch this back to `.context("find/get_exe_path")` once we depend on roundlet 0.2.0.
    let exe_path = exe_paths
        .get_exe_path("timelimit-cli")
        .map_err(|err| anyhow!("find/get_exe_path: {err:#}"))?;
    let status = Command::new(exe_path)
        .stdin(Stdio::null())
        .status()
        .with_context(|| format!("Could not run `{exe_path}`"))?;
    if status
        .code()
        .ok_or_else(|| anyhow!("No exit code after running `{exe_path}`: {status:?}"))?
        != u8::from(ExitCode::Usage).into()
    {
        bail!("Unexpected exit status from `{exe_path}`: {status:?}");
    }
    Ok(())
}
