mod common;
use predicates::prelude::*;
#[test]
fn a_return_is_exit_zero_even_when_the_value_says_it_failed() {
let dir = tempfile::tempdir().expect("tempdir");
let result = dir.path().join("out.json");
common::agent_block_cmd()
.args([
"-s",
&common::fixture("exit_returns_failure.lua"),
"--result",
result.to_str().expect("utf-8"),
])
.assert()
.code(0);
let written = std::fs::read_to_string(&result).expect("the value was written");
let value: serde_json::Value = serde_json::from_str(&written).expect("json");
assert_eq!(
value["ok"], false,
"the failure is in the value, not the exit code: {written}"
);
}
#[test]
fn a_raise_is_exit_one_and_writes_no_result() {
let dir = tempfile::tempdir().expect("tempdir");
let result = dir.path().join("out.json");
common::agent_block_cmd()
.args([
"-s",
&common::fixture("exit_raises.lua"),
"--result",
result.to_str().expect("utf-8"),
])
.assert()
.code(1)
.stderr(predicate::str::contains("the endpoint answered nonsense"));
assert!(
!result.exists(),
"a run that raised wrote {} anyway",
result.display()
);
}
#[test]
fn a_defer_is_exit_seventy_five_and_writes_no_result() {
let dir = tempfile::tempdir().expect("tempdir");
let result = dir.path().join("out.json");
common::agent_block_cmd()
.args([
"-s",
&common::fixture("exit_defers.lua"),
"--result",
result.to_str().expect("utf-8"),
])
.assert()
.code(75)
.stderr(predicate::str::contains("no pod"));
assert!(
!result.exists(),
"a run that never started wrote {} anyway",
result.display()
);
}
#[test]
fn a_command_line_that_does_not_parse_is_exit_two() {
common::agent_block_cmd()
.args(["--nonesuch"])
.assert()
.code(2);
}
#[test]
fn naming_no_script_is_exit_one() {
common::agent_block_cmd()
.assert()
.code(1)
.stderr(predicate::str::contains("no script given"));
}