Files
sausage/userland/brush/source/brush-shell/tests/cases/compat/builtins/exit.yaml
T
2026-11-11 22:04:16 +00:00

121 lines
2.7 KiB
YAML

name: "Builtins: exit"
cases:
- name: "Exit without code"
stdin: |
exit
- name: "Exit with code"
stdin: |
exit 10
- name: "Exit with i64 max"
stdin: |
exit 9223372036854775807
- name: "Exit with i64 min"
stdin: |
exit -9223372036854775808
- name: "Exit in for loop"
stdin: |
for i in 1 2 3; do
exit 42
echo "Got past exit in loop"
done
echo "Got past loop"
- name: "Exit in arithmetic for loop body"
stdin: |
for ((i = 0; i < 10; i++)); do
exit 42
echo "Got past exit in loop"
done
echo "Got past loop"
- name: "Exit in while loop condition"
stdin: |
while exit 42; do
echo "In loop"
done
echo "Got past loop"
- name: "Exit in while loop body"
stdin: |
while true; do
exit 42
echo "Got past exit in body"
break
done
echo "Got past loop"
- name: "Exit in sequence"
stdin: |
exit 42; echo "Should not be printed"
- name: "Exit in function"
stdin: |
myfunc() {
exit 42
echo "Got past exit in function"
}
myfunc
echo "Got past function call"
- name: "Exit in subshell"
stdin: |
(exit 42)
echo "Got past subshell"
- name: "Exit in command substitution"
stdin: |
output=$(echo hi; exit 42; echo there)
echo "Got past command substitution"
- name: "Exit in and/or"
stdin: |
exit 42 || echo "Got past exit"
- name: "Exit in brace group"
stdin: |
{
exit 42
echo "Got past exit"
}
echo "Got past brace group"
- name: "exit with too many arguments abandons the rest of the line"
known_failure: true # TODO(builtins): a usage error only skips exit
ignore_stderr: true
stdin: |
exit 1 2; echo "same line: $?"
echo "next line: $?"
- name: "logout outside a login shell fails"
known_failure: true # TODO(logout): brush reports logout as unimplemented (status 99)
ignore_stderr: true
stdin: |
logout
echo "logout: $?"
logout -Z
echo "logout -Z: $?"
- name: "exit in an rc file ends the shell"
known_failure: true # TODO(startup): an exit in a startup file doesn't end the shell
removed_default_args: ["--norc"]
ignore_stderr: true # an interactive shell prompts on stderr
args: ["--rcfile", "exitrc", "-i"]
test_files:
- path: "exitrc"
contents: |
echo "in rc"
exit 3
echo "after exit"
stdin: |
echo "not run"
- name: "exit takes -- and a negative status"
stdin: |
(exit -- 4); echo "a=$?"
(exit -1); echo "b=$?"