#!/usr/bin/env zsh
# Minimal dependency-free test helpers. Source from *.test.zsh files.
typeset -gi T_RUN=0 T_FAIL=0
export DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
# child test shells aren't real ttys; give them a TERM so tput/zle stay quiet.
export TERM="${TERM:-xterm-256color}"
# never run startup eye-candy during tests (also TTY-guarded, this is belt+braces).
export ANIM_SPLASH=0 CROSS_SPLASH=0
# Run the new config in isolation and capture a snippet's stdout.
# Usage: out=$(zboot 'print -r -- $EDITOR')
zboot() { ZDOTDIR="$DOTFILES" zsh -ic "$1" 2>/dev/null }
assert_eq() { # desc expected actual
(( T_RUN++ ))
if [[ "$2" == "$3" ]]; then print -P "%F{green}ok%f $1"
else print -P "%F{red}FAIL%f $1\n expected: [$2]\n actual: [$3]"; (( T_FAIL++ )); fi
}
assert_contains() { # desc haystack needle
(( T_RUN++ ))
if [[ "$2" == *"$3"* ]]; then print -P "%F{green}ok%f $1"
else print -P "%F{red}FAIL%f $1 (missing: $3)"; (( T_FAIL++ )); fi
}
assert_ok() { # desc cmd...
(( T_RUN++ )); local d="$1"; shift
if "$@" >/dev/null 2>&1; then print -P "%F{green}ok%f $d"
else print -P "%F{red}FAIL%f $d (exit $?)"; (( T_FAIL++ )); fi
}
t_summary() {
print -P "\n%F{cyan}-- $((T_RUN-T_FAIL))/$T_RUN passed --%f"
(( T_FAIL == 0 ))
}