SPB Git

Repository Public

test.sh 2.9 KB 60 lines shellscript

1#!/bin/bash2# Runs the tests of the macOS app.3#   Scripts/test.sh unit        view-model / logic tests (XCTest, hosted by the Debug app; no backend needed)4#   Scripts/test.sh ui          XCUITest against a REAL local control-api and a throwaway PostgreSQL database5#   Scripts/test.sh all         both6# The UI tests use the Debug-only software authenticator (system passkeys cannot target localhost); nothing on the7# server is bypassed. Environment: MCC_DERIVED_DATA (default /tmp/mcc-swift/DerivedData; keep it outside ~/Desktop).8set -euo pipefail9cd "$(dirname "$0")/.."10ROOT="$PWD"11MODE="${1:-all}"12DD="${MCC_DERIVED_DATA:-/tmp/mcc-swift/DerivedData}"13PROJ="$DD.project"14BACKEND="$ROOT/../../packages/swift-core/Scripts/local-backend.sh"15PSQL_BIN="$(command -v psql || echo /opt/homebrew/bin/psql)"16mkdir -p "$PROJ"17xcodegen generate --quiet --spec project.yml --project "$PROJ" --project-root .1819run() { # $1 = -only-testing target, $2 = log name20  set +e21  xcodebuild -project "$PROJ/MCC.xcodeproj" -scheme MCC -configuration Debug -derivedDataPath "$DD" -destination 'platform=macOS,arch=arm64' \22    -skipPackagePluginValidation -skipMacroValidation MCC_ROOT="$ROOT" -only-testing:"$1" test > "$DD.$2.log" 2>&123  local rc=$?24  set -e25  grep -E "\.swift:[0-9]+: error|^error:|Test Case .* (passed|failed)|Executed [0-9]+ tests|\*\* TEST" "$DD.$2.log" | sed -E "s|$ROOT/||" | sort -u | tail -8026  return $rc27}2829status=030if [ "$MODE" = unit ] || [ "$MODE" = all ]; then31  echo "== string catalogs"32  python3 "$ROOT/../../packages/swift-core/Scripts/strings.py" check "$ROOT/../../packages/swift-core/Sources/MCCCore/Resources/Localizable.xcstrings" \33    "$ROOT"/Resources/*.xcstrings --sources "$ROOT/../../packages/swift-core/Sources/MCCCore" "$ROOT/Sources" || status=134  echo "== unit tests"; run MCCTests unit || status=135fi36if [ "$MODE" = ui ] || [ "$MODE" = all ]; then37  echo "== UI tests"38  DB="mcc_swift_uitest_$(openssl rand -hex 4)"39  CONTROL_PORT="${MCC_UI_CONTROL_PORT:-8766}"40  "$BACKEND" build41  CONTROL_PID=""42  cleanup() {43    [ -n "$CONTROL_PID" ] && kill "$CONTROL_PID" 2>/dev/null || true44    "$BACKEND" stop || true45    "$PSQL_BIN" -X -q -d postgres -c "drop database if exists \"$DB\" with (force)" || true46  }47  trap cleanup EXIT48  "$BACKEND" start "$DB"49  # The test runner is sandboxed: it drives the backend (stop / start) and saves screenshots through this helper.50  python3 "$ROOT/Scripts/ui-test-control.py" "$CONTROL_PORT" "$BACKEND" "$DB" "${MCC_UI_SCREENSHOTS:-}" &51  CONTROL_PID=$!52  # The one-time owner invitation goes to the test runner through its environment (never on a command line).53  export TEST_RUNNER_MCC_UI_SETUP_TOKEN="$("$BACKEND" owner "$DB" owner-ui "Owner UI")"54  export TEST_RUNNER_MCC_UI_ORIGIN="http://localhost:${MCC_LOCAL_PORT:-8760}"55  export TEST_RUNNER_MCC_UI_CONTROL_PORT="$CONTROL_PORT"56  export TEST_RUNNER_MCC_UI_SCREENSHOTS="${MCC_UI_SCREENSHOTS:+1}"57  run MCCUITests ui || status=158fi59exit $status60
Files main
Menu

Theme