59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
//! CLI-level regression tests for the `sys` entry paths.
|
|
//!
|
|
//! These exercise the real binary so the deterministic (manual) and JSON paths
|
|
//! are proven to fail closed on invalid input and to exit nonzero on failure.
|
|
//! They never mutate the system: the invalid cases are refused before any
|
|
//! command is built, and the read-only case targets a temporary root.
|
|
|
|
use std::process::Command;
|
|
|
|
fn sys() -> Command {
|
|
Command::new(env!("CARGO_BIN_EXE_sys"))
|
|
}
|
|
|
|
#[test]
|
|
fn natural_option_like_operand_is_rejected() {
|
|
// `--` stops clap option parsing, so the operand reaches the parser intact.
|
|
let out = sys()
|
|
.args(["--", "install", "--color=n"])
|
|
.output()
|
|
.expect("run sys");
|
|
assert!(!out.status.success());
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(
|
|
stderr.contains("could not parse") || stderr.contains("invalid"),
|
|
"stderr: {stderr}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn json_option_like_operand_is_rejected() {
|
|
let out = sys()
|
|
.args(["--action", r#"{"action":"install_package","atom":"-C"}"#])
|
|
.output()
|
|
.expect("run sys");
|
|
assert!(!out.status.success());
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(stderr.contains("invalid"), "stderr: {stderr}");
|
|
}
|
|
|
|
#[test]
|
|
fn read_only_history_succeeds_against_a_temporary_root() {
|
|
let root = tempfile::tempdir().expect("temp root");
|
|
let out = sys()
|
|
.arg("--root")
|
|
.arg(root.path())
|
|
.arg("history")
|
|
.output()
|
|
.expect("run sys");
|
|
assert!(
|
|
out.status.success(),
|
|
"stderr: {}",
|
|
String::from_utf8_lossy(&out.stderr)
|
|
);
|
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
|
assert!(
|
|
stdout.contains("no snapshot history") || stdout.contains("snapshots:"),
|
|
"stdout: {stdout}"
|
|
);
|
|
}
|