Files
pdfcraft/apps/pdfcraft-cli/tests/options.rs
T
27ce6f7584 CLI: audit rejects unknown options before reading the file (fixes #1332) (#1372)
`pdfcraft-cli audit` skipped option validation, so a misspelled
`--passwrod` fell through to a file-read error instead of naming the
bad option. Audit now runs `validate_options` first, like `info`, and
the options test covers it.

Co-authored-by: umesh429 <3474974+umesh429@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 06:25:06 -04:00

30 lines
1.3 KiB
Rust

//! Every command rejects misspelled long options before opening or writing a file.
use std::process::Command;
const BIN: &str = env!("CARGO_BIN_EXE_pdfcraft-cli");
#[test]
fn non_edit_commands_reject_unknown_options_before_io() {
for args in [
vec!["info", "missing.pdf", "--passwrod", "secret"],
vec!["text", "missing.pdf", "--pgae", "1"],
vec!["combine", "a.pdf", "b.pdf", "--ot", "out.pdf"],
vec!["extract", "missing.pdf", "--pgaes", "1", "--out", "out.pdf"],
vec!["split", "missing.pdf", "--ever", "2"],
vec!["render", "missing.pdf", "--dppi", "96", "--out", "out.png"],
vec!["check-one", "missing.pdf", "--edti"],
vec!["check", "missing.pdf", "--timout", "2"],
vec!["audit", "missing.pdf", "--passwrod", "x"],
vec!["audit", "missing.pdf", "--nonsense", "1"],
vec!["run", "doc_open", "--roto", "/tmp"],
vec!["ui", "--contro", "control.json", "state"],
] {
let unknown = args.iter().find(|arg| arg.starts_with("--")).expect("test option");
let out = Command::new(BIN).args(&args).output().expect("run cli");
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(!out.status.success(), "{args:?} unexpectedly succeeded");
assert!(stderr.contains("unknown option") && stderr.contains(unknown), "{args:?}: {stderr}");
}
}