#!/usr/bin/env bash # tests/lib.sh -- tiny assertion helpers for the ai-sandbox test suite. # # Every test file gets: AISB (path to the script), WORK (scratch dir), and uses # sb() to run the sandbox with fully redirected XDG dirs so nothing touches the # real machine. PASS=0 FAIL=0 FAILED_NAMES=() _current="" t_name() { _current="$1"; printf '\n\033[1m# %s\033[0m\n' "$1"; } _ok() { PASS=$((PASS + 1)); printf ' \033[32mok\033[0m %s\n' "$1"; } _bad() { FAIL=$((FAIL + 1)); FAILED_NAMES+=("$_current :: $1"); printf ' \033[31mFAIL\033[0m %s\n' "$1"; shift || true; [[ -n "${1:-}" ]] && printf ' %s\n' "$1"; return 0; } # sb [args...] -> sets RC, OUT (stdout+stderr) sb() { OUT="$("$AISB" "$@" 2>&1)" && RC=0 || RC=$? return 0 } # sb_timeout [args...] -- like sb, but bounded. Use it when a test expects # the script to refuse: the refusal happens before podman, and the timeout is there in # case a regression turns "refused instantly" into "hung forever". sb_timeout() { local t="$1"; shift OUT="$(timeout "$t" "$AISB" "$@" 2>&1 &1)" && RC=0 || RC=$? return 0 } assert_rc() { # assert_rc