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

132 lines
2.8 KiB
YAML

name: "Status tests"
cases:
- name: "Basic status"
stdin: |
cat /non/existent >/dev/null
echo "[1] Status: $?; pipe status: ${PIPESTATUS[@]}"
- name: "Parse error status"
ignore_stderr: true
stdin: |
# Generate parse error
for f done
echo "[2] Status: $?; pipe status: ${PIPESTATUS[@]}"
- name: "Pipeline status"
stdin: |
/non/existent/program 2>/dev/null | cat
echo "Status: $?; pipe status: ${PIPESTATUS[@]}"
- name: "Command substitution status"
stdin: |
x=$(echo hi | wc -l)
echo "[1] Status: $?; pipe status: ${PIPESTATUS[@]}"
x=$(cat /non/existent 2>/dev/null)
echo "[2] Status: $?; pipe status: ${PIPESTATUS[@]}"
- name: "Subshell status"
stdin: |
(echo hi | wc -l)
echo "[1] Status: $?; pipe status: ${PIPESTATUS[@]}"
(cat /non/existent 2>/dev/null)
echo "[2] Status: $?; pipe status: ${PIPESTATUS[@]}"
- name: "Stored status"
stdin: |
false
status=$?
echo "Stored status from false: $status"
true
status=$?
echo "Stored status from true: $status"
- name: "Status from assignment"
stdin: |
false
false_status=$?
assign_status=$?
echo "Status after assignment: $assign_status"
- name: "Status from assignment with xtrace"
stdin: |
set -x
false
scalar=value
echo "Status after scalar assignment: $?"
false
arr=(1 2)
echo "Status after array assignment: $?"
false
appended+=more
echo "Status after appending assignment: $?"
false
first=1 second=2
echo "Status after multiple assignments: $?"
false
expanded=${undefined:-fallback}
echo "Status after expanded assignment: $?"
- name: "Status from assignment with command substitution and xtrace"
stdin: |
set -x
f() {
echo "out$1"
return $1
}
captured=$(f 42)
echo "Status after substitution assignment: $?"
true
captured=$(f 42)
echo "Status after substitution assignment: $?"
- name: "Status within assignments"
stdin: |
f() {
return $1
}
x=$(f 42) y=0 z=$? w=$?
echo "x: $x; y: $y; z: $z; w: $w"
- name: "Status in for loop"
stdin: |
function ret() {
return $1
}
for f in a b; do
echo "Loop entry: $?"
ret 1
echo "Loop 1: $?"
ret 2
echo "Loop 2: $?"
done
echo "After loop: $?"
- name: "Status in arithmetic for loop"
stdin: |
function ret() {
return $1
}
for ((i = 0; i < 2; i++)); do
echo "Loop entry: $?"
ret 1
echo "Loop 1: $?"
ret 2
echo "Loop 2: $?"
done
echo "After loop: $?"