#!/hint/bash # Copyright © Tavian Barnes # SPDX-License-Identifier: 0BSD ## Argument parsing # Print usage information usage() { local pad=$(printf "%*s" ${#0} "") color <&2 usage >&2 exit 1 ;; *) PATTERNS+=("$arg") ;; esac done # Try to resolve the path to $BFS before we cd, while also supporting # --bfs="./bin/bfs -S ids" read -a BFS <<<"${BFS:-$BIN/bfs}" BFS[0]=$(_realpath "$(command -v "${BFS[0]}")") if ((${#PATTERNS[@]} == 0)); then PATTERNS=("*") fi TEST_CASES=() ALL_TESTS=($(cd "$TESTS" && quote {posix,common,bsd,gnu,bfs}/*.sh)) for TEST in "${ALL_TESTS[@]}"; do TEST="${TEST%.sh}" for PATTERN in "${PATTERNS[@]}"; do if [[ $TEST == $PATTERN ]]; then TEST_CASES+=("$TEST") break fi done done if ((${#TEST_CASES[@]} == 0)); then cprintf "${RED}error:${RST} No tests matched" >&2 cprintf " ${BLD}%s${RST}" "${PATTERNS[@]}" >&2 cprintf ".\n\n" >&2 usage >&2 exit 1 fi }