43 lines
1.5 KiB
Rust
43 lines
1.5 KiB
Rust
#![allow(clippy::expect_used)]
|
|
#![doc = "Black-box CLI framing and exit-status tests."]
|
|
|
|
use std::process::Command;
|
|
|
|
#[test]
|
|
fn unimplemented_operation_is_a_typed_json_runtime_failure() {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_ghidr"))
|
|
.arg("doctor")
|
|
.output()
|
|
.expect("run ghidr");
|
|
assert_eq!(output.status.code(), Some(1));
|
|
assert!(output.stdout.is_empty());
|
|
let error: serde_json::Value =
|
|
serde_json::from_slice(&output.stderr).expect("valid JSON error");
|
|
assert_eq!(error["error"]["code"], "internal_not_implemented");
|
|
assert_eq!(error["error"]["details"]["operation"], "doctor");
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_invocation_is_one_json_document_on_stderr() {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_ghidr"))
|
|
.args(["functions", "sample", "--limit", "0"])
|
|
.output()
|
|
.expect("run ghidr");
|
|
assert_eq!(output.status.code(), Some(2));
|
|
assert!(output.stdout.is_empty());
|
|
let error: serde_json::Value =
|
|
serde_json::from_slice(&output.stderr).expect("valid JSON error");
|
|
assert_eq!(error["error"]["code"], "invalid_arguments");
|
|
assert_eq!(output.stderr.last(), Some(&b'\n'));
|
|
}
|
|
|
|
#[test]
|
|
fn explicit_human_parse_failure_is_not_json() {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_ghidr"))
|
|
.args(["--format", "human", "decompile", "sample"])
|
|
.output()
|
|
.expect("run ghidr");
|
|
assert_eq!(output.status.code(), Some(2));
|
|
assert!(output.stdout.is_empty());
|
|
assert!(serde_json::from_slice::<serde_json::Value>(&output.stderr).is_err());
|
|
}
|