Testing Shell Scripts
Test Summary
Choose an Exit Plan
A test script usually summarizes passed and failed checks before deciding whether the run should be green or red.
Program
Play the script to choose a failure count and see the resulting status summary.
test_summary.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
failed=1
passed=3
total=$((passed + failed))
if [[ "$failed" -eq 0 ]]; then
status="green"
else
status="red"
fi
echo "tests=$total failed=$failed status=$status"
#!/usr/bin/env bash
failed=0
passed=3
total=$((passed + failed))
if [[ "$failed" -eq 0 ]]; then
status="green"
else
status="red"
fi
echo "tests=$total failed=$failed status=$status"
#!/usr/bin/env bash
failed=2
passed=3
total=$((passed + failed))
if [[ "$failed" -eq 0 ]]; then
status="green"
else
status="red"
fi
echo "tests=$total failed=$failed status=$status"
failed ← 1
3failed=14passed=3values this step1failedpassed ← 3
3failed=14passed=35total=$((passed + failed))values this step3passedtotal ← 4
4passed=35total=$((passed + failed))6if [[ "$failed" -eq 0 ]]; thenvalues this step4total3passed1failedif [[ "$failed" -eq 0 ]]; then
5total=$((passed + failed))6if [[ "$failed" -eq 0 ]]; then7 status="green"values this step1failedstatus ← red
8else9 status="red"10fivalues this stepredstatusecho "tests=$total failed=$failed status=$status"
10fi11echo "tests=$total failed=$failed status=$status"outputtests=4 failed=1 status=redvalues this step4total1failedredstatus
failed ← 0
3failed=04passed=3values this step0failedpassed ← 3
3failed=04passed=35total=$((passed + failed))values this step3passedtotal ← 3
4passed=35total=$((passed + failed))6if [[ "$failed" -eq 0 ]]; thenvalues this step3total3passed0failedif [[ "$failed" -eq 0 ]]; then
5total=$((passed + failed))6if [[ "$failed" -eq 0 ]]; then7 status="green"values this step0failedstatus ← green
6if [[ "$failed" -eq 0 ]]; then7 status="green"8elsevalues this stepgreenstatusecho "tests=$total failed=$failed status=$status"
10fi11echo "tests=$total failed=$failed status=$status"outputtests=3 failed=0 status=greenvalues this step3total0failedgreenstatus
failed ← 2
3failed=24passed=3values this step2failedpassed ← 3
3failed=24passed=35total=$((passed + failed))values this step3passedtotal ← 5
4passed=35total=$((passed + failed))6if [[ "$failed" -eq 0 ]]; thenvalues this step5total3passed2failedif [[ "$failed" -eq 0 ]]; then
5total=$((passed + failed))6if [[ "$failed" -eq 0 ]]; then7 status="green"values this step2failedstatus ← red
8else9 status="red"10fivalues this stepredstatusecho "tests=$total failed=$failed status=$status"
10fi11echo "tests=$total failed=$failed status=$status"outputtests=5 failed=2 status=redvalues this step5total2failedredstatus
summary
A summary line gives humans and automation one compact result.
exit plan
This example models the status decision without exiting the browser replay.
green/red result
Zero failures produce green; any failure keeps the run red.