use bash_interop::rig::ExitStatus;
use crate::{behind, report, script};
#[tokio::test]
async fn a_signalled_subject_is_reported_and_loses_nothing() {
let ran = script(
r#"
BC_INSTR KEEP say REC before
kill -TERM $$
BC_INSTR KEEP say REC never
"#,
)
.await;
assert_eq!(ran.subject, ExitStatus::Signal(15));
assert_eq!(
ran.subject.shell_code(),
143,
"128 + signal, the shell convention"
);
assert_eq!(
behind(&ran.shells, "REC"),
[["before"]],
"{}",
report(&ran.shells)
);
}
#[tokio::test]
async fn a_clients_own_trap_and_ifs_are_untouched() {
let ran = script(
r#"
trap 'echo mine' EXIT
IFS=,
BC_INSTR KEEP say REC one two
"#,
)
.await;
assert_eq!(
behind(&ran.shells, "REC"),
[["one", "two"]],
"{}",
report(&ran.shells)
);
assert!(
ran.shells[0].shell.bash.version.at_least(4, 4, 0),
"the version is an array, and it read back{}",
report(&ran.shells)
);
}
#[tokio::test]
async fn a_clients_own_locale_is_untouched_by_a_wide_message() {
let ran = script(
r#"
export LC_ALL=C.UTF-8
wide="ä"
BC_INSTR KEEP say REC before "${#wide}" "$LC_ALL"
BC_INSTR KEEP say REC "$(printf 'x%.0s' {1..9000})"
BC_INSTR KEEP say REC after "${#wide}" "$LC_ALL"
"#,
)
.await;
let said = behind(&ran.shells, "REC");
assert_eq!(
said[0],
["before", "1", "C.UTF-8"],
"{}",
report(&ran.shells)
);
assert_eq!(
said[2],
["after", "1", "C.UTF-8"],
"{}",
report(&ran.shells)
);
}