#![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 eyre::{Result, WrapErr as _, bail, eyre};
use roundlet::test_exe;
use sysexits::ExitCode;

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