#!/bin/sh # tests/run.sh - test runner for stupidtools (skeleton). # # Grows with the project; today it proves the toolchain works end to end: # the binary must exist, run, and report its version. # # POSIX sh only (dash/bash/zsh safe). Fails fast on the first failed check. TOP_DIR=$(cd "$(dirname "$0")/.." && pwd) || { echo "FAIL: cannot resolve project root" >&2 exit 1 } BIN="$TOP_DIR/src/stupidtools" TESTS_RUN=0 TESTS_FAILED=0 pass() { TESTS_RUN=$((TESTS_RUN + 1)) printf 'ok %d - %s\n' "$TESTS_RUN" "$1" } fail() { TESTS_RUN=$((TESTS_RUN + 1)) TESTS_FAILED=$((TESTS_FAILED + 1)) printf 'not ok %d - %s\n' "$TESTS_RUN" "$1" >&2 } # --- 1. the built binary must exist and be executable ------------------- if [ -x "$BIN" ]; then pass "binary exists and is executable: $BIN" else fail "binary missing: $BIN (run 'make' first)" printf 'FAILED: %d/%d checks failed\n' "$TESTS_FAILED" "$TESTS_RUN" >&2 exit 1 fi # --- 2. --version must exit 0 and print exactly 'stupidtools ' - version_out= if version_out=$("$BIN" --version 2>&1); then if [ "$version_out" = "stupidtools 1.0.0" ]; then pass "--version reports: $version_out" else fail "--version output unexpected: '$version_out' (want 'stupidtools 1.0.0')" fi else rc=$? fail "--version exited non-zero (rc=$rc): $version_out" fi # --- summary ------------------------------------------------------------- if [ "$TESTS_FAILED" -ne 0 ]; then printf 'FAILED: %d/%d checks failed\n' "$TESTS_FAILED" "$TESTS_RUN" >&2 exit 1 fi printf 'All %d checks passed.\n' "$TESTS_RUN"