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
#!/usr/bin/env bash
failed=
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=
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=
passed=3
total=$((passed + failed))
if [[ "$failed" -eq 0 ]]; then
status="green"
else
status="red"
fi
echo "tests=$total failed=$failed status=$status"
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.