25 lines
543 B
Bash
25 lines
543 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
fail() { echo "ASSERTION FAILED: $*" >&2; return 1; }
|
|
|
|
assert_eq() {
|
|
local expected="$1" actual="$2"; shift 2
|
|
if [ "$expected" != "$actual" ]; then
|
|
fail "expected='$expected' actual='$actual' $*"
|
|
fi
|
|
}
|
|
|
|
assert_contains() {
|
|
local haystack="$1" needle="$2"; shift 2
|
|
if ! grep -Fq -- "$needle" <<<"$haystack"; then
|
|
fail "did not find '$needle' in output"
|
|
fi
|
|
}
|
|
|
|
run_cmd() {
|
|
local out err rc
|
|
out="$({ err=$( { "$@"; } 2>&1 1>&3 ); rc=$?; echo "$err" >&2; echo $rc >&4; } 3>&1 4>&1)"
|
|
}
|
|
|