#!/bin/sh
# script/test: run the test suite (vet first, verbose rerun on failure).
set -eu

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

main() {
    cd "$ROOT"
    # CGO is required (Makefile exports this too)
    export CGO_ENABLED=1
    go vet ./...
    # The rerun is diagnostic only: `exit 1` keeps the script failing
    # even if a flaky test passes on the second attempt.
    go test -timeout 30s -race -cover ./... || \
        { echo "--- Rerunning with -v for details ---"; \
          go test -timeout 30s -race -v ./...; exit 1; }
}

main "$@"
