| name | shell-tdd |
| description | Shell-based TDD test harness patterns — pass/fail counters, common assertions, set -e gotchas, and exit code conventions for bash test scripts |
| type | reference |
| version | 1.0.0 |
| category | development |
| capabilities | ["shell_test_harness","bash_assertions","tdd_shell_patterns"] |
| tools | ["Bash","Read","Edit"] |
| related_skills | ["tdd-obra","gitignore-scaffold","testing-tdd-london"] |
| requires | [] |
| see_also | [] |
| tags | [] |
Shell TDD Test Harness
Quick Start
Shell TDD scripts follow a simple pattern: counter functions, if-block assertions,
and exit $FAIL for CI integration. The critical rule is never use (( var++ ))
with set -e — use var=$((var + 1)) instead.
Template
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
PASS=0
FAIL=0
pass() { PASS=$((PASS + 1)); echo " PASS: $1"; }
fail() { FAIL=$((FAIL + 1)); echo " FAIL: $1"; }
echo "=== Suite: <name> ==="
echo ""
echo "--- AC1: <description> ---"
if <check>; then
pass "<what passed>"
else
fail "<what failed>"
fi
echo ""
echo "=== Results: $PASS passed, $FAIL failed ==="
exit $FAIL
Common Assertions
if [ -f ]; pass ; fail ;
[ -d ]; pass ; fail ;
grep -q ; pass ; fail ;
git check-ignore -q ; pass ; fail ;
command_here; pass ; fail ;
[ = ]; pass ; fail ;
[ -s ]; pass ; fail ;
[ -n ]; pass ; fail ;