#!/usr/bin/env bash # Compiles the project and runs every example, writing each program's real output # to docs/output/.txt. Everything checked into docs/output was produced # by this script — nothing is hand-written. set -u cd "$(dirname "$0")" mvn -B -q clean compile || { echo "compile failed"; exit 1; } CP="target/classes:$(mvn -B -q dependency:build-classpath -Dmdep.outputFile=/dev/stdout -DincludeScope=runtime 2>/dev/null | tail -1)" mkdir -p docs/output FAILED=0 for f in $(find src/main/java -name '*.java' | sort); do CLASS=$(echo "$f" | sed 's|src/main/java/||; s|\.java$||; s|/|.|g') grep -q 'public static void main' "$f" || continue SHORT="${CLASS##*.}" printf '%-52s' "$SHORT" if java -cp "$CP" "$CLASS" > "docs/output/$SHORT.txt" 2>&1; then echo "ok" else echo "FAILED"; FAILED=1 fi done echo if [ "$FAILED" -eq 0 ]; then echo "All examples ran successfully."; else echo "Some examples failed."; fi exit $FAILED