#!/bin/sh
# script/test: run the test suite. Quiet on success; on failure, rerun
# with -v for full diagnostic output (and still fail — the first run
# already proved the tests are broken).
set -eu

ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"

main() {
    cd "$ROOT"
    # -count=1 disables the test result cache. Without it a repeat run on
    # an unchanged tree reports every package `ok ... (cached)` and exits
    # 0 having executed nothing — a gate that cannot fail.
    go test -count=1 -timeout 90s -race -cover ./... || {
        echo "--- Rerunning with -v for details ---"
        go test -count=1 -timeout 90s -race -v ./...
        exit 1
    }
}

main "$@"
