This commit is contained in:
David Schroeder
2026-07-25 19:35:17 -05:00
parent f2da5b3062
commit 7102550f4e
12 changed files with 430 additions and 30 deletions
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
TEST_ASSERTIONS=0
TEST_FAILURES=0
test_fail() {
printf 'FAIL: %s\n' "$1" >&2
(( TEST_FAILURES += 1 ))
}
assert_equal() {
local expected="$1"
local actual="$2"
local label="$3"
(( TEST_ASSERTIONS += 1 ))
if [[ "$actual" != "$expected" ]]; then
test_fail "${label}: expected '${expected}', received '${actual}'"
fi
}
assert_success() {
local label="$1"
shift
(( TEST_ASSERTIONS += 1 ))
"$@" || test_fail "${label}: expected success"
}
assert_failure() {
local label="$1"
shift
(( TEST_ASSERTIONS += 1 ))
if "$@"; then
test_fail "${label}: expected failure"
fi
}
finish_tests() {
if (( TEST_FAILURES > 0 )); then
printf '%d assertion(s), %d failure(s)\n' \
"$TEST_ASSERTIONS" "$TEST_FAILURES" >&2
return 1
fi
printf '%d assertion(s) passed\n' "$TEST_ASSERTIONS"
}