#!/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_env VAR=val ... -- args (env prefix, without leaking into the test shell) sb_env() { local -a envs=() while (($#)) && [[ "$1" != -* && "$1" == *=* ]]; do envs+=("$1"); shift; done OUT="$(env "${envs[@]}" "$AISB" "$@" 2>&1)" && RC=0 || RC=$? return 0 } assert_rc() { # assert_rc