#!/usr/bin/env bash # Run the test suite and report the JUnit XML, not just the exit code. # # A green `test` task does not prove tests ran (see AGENTS.md), so this always # prints tests/failures/errors per suite and dumps failure messages. # # A repository-wide lock serializes Gradle/test runs. Without it, an editor or # another agent can delete build/test-results while this process is writing JUnit # XML, producing EOFException or a missing in-progress-results bin. # # A `--tests` filter STICKS: Gradle reuses the configuration cache entry from the # previous run, so a later unfiltered `./jaitest` silently re-runs just that one # class and reports OK. Unfiltered runs therefore disable the configuration cache, # which is the only reliable way to get the whole suite back. # # Usage: ./jaitest [gradle args...] e.g. ./jaitest --tests '*Lexer*' set -uo pipefail cd "$(dirname "$0")" || exit 1 source ./gradle-lock.sh jai_gradle_lock_acquire trap jai_gradle_lock_release EXIT trap 'exit 130' INT trap 'exit 143' TERM extra=() if [[ " $* " != *" --tests "* ]]; then extra+=(--no-configuration-cache) fi run_gradle() { rm -rf build/reports/tests/test # Bash 3.2 (the macOS system shell) treats an empty array expansion as an # unset variable under `set -u`. Keep the no-extra-args invocation separate # so the wrapper works both with and without a test filter. if ((${#extra[@]})); then ./jaigradle cleanTest test "${extra[@]}" "$@" 2>&1 | grep -vE '^\[[0-9.]+s\]\[warning\]\[cds\]' else ./jaigradle cleanTest test "$@" 2>&1 | grep -vE '^\[[0-9.]+s\]\[warning\]\[cds\]' fi return "${PIPESTATUS[0]}" } run_gradle "$@" gradle_status=$? shopt -s nullglob xml=(build/test-results/test/*.xml) if [ "$gradle_status" -ne 0 ] && [ ${#xml[@]} -eq 0 ]; then echo echo "!!! no test XML and a failed build — retrying once (concurrent Gradle run?)" sleep 3 run_gradle "$@" gradle_status=$? xml=(build/test-results/test/*.xml) fi echo echo "=== JUnit XML ===" if [ ${#xml[@]} -eq 0 ]; then echo "NO TEST XML PRODUCED — tests did not run." echo echo "If Gradle reported ':test NO-SOURCE' while the sources clearly exist, the" echo "build cache holds a poisoned entry with empty compileTestKotlin outputs" echo "(a concurrent build had its outputs deleted mid-run). Recover with:" echo echo " ./jaigradle --stop" echo " rm -rf build .gradle ~/.gradle/caches/build-cache-1" echo " ./jaitest" exit 1 fi total=0 bad=0 for f in "${xml[@]}"; do line=$(sed -n '2p' "$f") name=$(sed -nE 's/^