Repository Public
1#!/bin/bash2# Runs `swift test` in every package (or the ones given) and writes docs/reports/tests.json + a table.3# The on-device model evaluation (minutes long) is skipped here: run `swift test` in Packages/SheetIntelligence for it.4# Each package is run sequentially; a failing package does not stop the others.5set -uo pipefail6cd "$(dirname "$0")/.."7mkdir -p docs/reports build/test-logs8PKGS=("$@")9if [[ ${#PKGS[@]} -eq 0 ]]; then10 PKGS=(SheetCore SheetFormat FunctionsNumeric FunctionsText FunctionsLookup SheetEngine SheetIO SheetCharts SheetData SheetAnalytics SheetPython SheetIntelligence SheetAutomation SheetTemplates SheetUI FeatureAudit FeatureCharts FeatureData FeatureAnalysis FeaturePython FeatureIntelligence FeatureAutomation)11fi12total=0; failed=0; rows=()13for p in "${PKGS[@]}"; do14 [[ -f "Packages/$p/Package.swift" ]] || continue15 log="build/test-logs/$p.log"16 start=$(date +%s)17 (cd "Packages/$p" && ORIX_AI_EVAL=0 swift test 2>&1 | sed 's/\x1b\[[0-9;]*m//g' > "../../$log")18 secs=$(( $(date +%s) - start ))19 # a package may have several test targets: every "Test run with N tests" line counts20 n=$(grep -E "Test run with [0-9]+ tests?" "$log" | sed -E 's/.*Test run with ([0-9]+) tests?.*/\1/' | awk '{s+=$1} END {print s+0}')21 xct=$(grep -E "Executed [0-9]+ tests" "$log" | tail -1 | sed -E 's/.*Executed ([0-9]+) tests.*/\1/')22 [[ "$xct" =~ ^[0-9]+$ ]] && n=$(( n + xct ))23 runs=$(grep -cE "Test run with [0-9]+ tests?" "$log")24 ok=$(grep -cE "Test run with [0-9]+ tests?.* passed" "$log")25 if [[ $runs -gt 0 && $runs -eq $ok ]] && ! grep -qE "error: |signal code" "$log"; then status=passed; else status=FAILED; failed=$((failed+1)); fi26 total=$(( total + n ))27 rows+=("{\"package\":\"$p\",\"tests\":$n,\"status\":\"$status\",\"seconds\":$secs}")28 printf "%-22s %5s tests %-7s %4ss\n" "$p" "$n" "$status" "$secs"29done30printf "%-22s %5s tests %s failed package(s)\n" "TOTAL" "$total" "$failed"31( IFS=,; echo "{\"date\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"total\":$total,\"failedPackages\":$failed,\"packages\":[${rows[*]}]}" ) > docs/reports/tests.json32exit $(( failed > 0 ))33