SPB Git

Repository Public

test.sh 5.2 KB 102 lines shellscript

1#!/bin/bash2# Runs the tests of the iOS app on simulators.3#   Scripts/test.sh unit [iphone|ipad]   view-model / logic tests (hosted by the Debug app; no backend needed)4#   Scripts/test.sh ui   [iphone|ipad|both]   XCUITest against a REAL local control-api + orchestrator and a throwaway5#                                        PostgreSQL database seeded with synthetic nodes (Scripts/seed.sql)6#   Scripts/test.sh all                  unit (iphone) + ui (both)7# The UI tests use the Debug-only software authenticator (system passkeys cannot target localhost); nothing on the8# server is bypassed. Environment:9#   MCC_DERIVED_DATA     default /tmp/mcc-ios/DerivedData (keep it outside ~/Desktop)10#   MCC_SIM_IPHONE / MCC_SIM_IPAD   simulator UDIDs; by default dedicated devices "MCC iPhone 17 Pro" (iPhone 17 Pro)11#                        and "MCC iPad Pro 13" (iPad Pro 13-inch (M5)) are created once and reused12#   MCC_UI_SCREENSHOTS   directory: the screenshot test saves its PNGs there (suffix -iphone / -ipad)13#   MCC_UI_ONLY          run only some UI test methods (comma separated; 01 creates the session the others need),14#                        e.g. MCC_UI_ONLY=test01_SetupFromInvitationLink,test03_OverviewAndNodes15set -euo pipefail16cd "$(dirname "$0")/.."17ROOT="$PWD"18MODE="${1:-all}"19WHICH="${2:-}"20DD="${MCC_DERIVED_DATA:-/tmp/mcc-ios/DerivedData}"21PROJ="$DD.project"22BACKEND="$ROOT/Scripts/local-backend.sh"23PSQL_BIN="$(command -v psql || echo /opt/homebrew/bin/psql)"24mkdir -p "$PROJ" /tmp/mcc-ios25xcodegen generate --quiet --spec project.yml --project "$PROJ" --project-root .2627sim() { # $1 = iphone|ipad → UDID of the dedicated simulator (created on first use)28  local var name type file29  if [ "$1" = iphone ]; then var="${MCC_SIM_IPHONE:-}"; name="MCC iPhone 17 Pro"; type="iPhone 17 Pro"; else var="${MCC_SIM_IPAD:-}"; name="MCC iPad Pro 13"; type="iPad Pro 13-inch (M5)"; fi30  if [ -n "$var" ]; then echo "$var"; return; fi31  local udid32  udid="$(xcrun simctl list devices available | sed -n "s/^ *$name (\([0-9A-F-]*\)).*/\1/p" | head -1)"33  [ -n "$udid" ] || udid="$(xcrun simctl create "$name" "$type")"34  echo "$udid"35}3637run() { # $1 = -only-testing target(s), comma separated, $2 = log name, $3 = simulator udid38  local only=() t39  for t in ${1//,/ }; do only+=("-only-testing:$t"); done40  set +e41  xcodebuild -project "$PROJ/MCCiOS.xcodeproj" -scheme MCCiOS -configuration Debug -derivedDataPath "$DD" -destination "platform=iOS Simulator,id=$3" \42    -skipPackagePluginValidation -skipMacroValidation -parallel-testing-enabled NO MCC_ROOT="$ROOT" "${only[@]}" test > "$DD.$2.log" 2>&143  local rc=$?44  set -e45  grep -E "\.swift:[0-9]+: error|^error:|Test Case .* (passed|failed)|Test case .* (passed|failed)|✔|✘|Executed [0-9]+ tests|Test run with|\*\* TEST" "$DD.$2.log" | sed -E "s|$ROOT/||" | awk '!seen[$0]++' | tail -12046  return $rc47}4849ui() { # $1 = iphone|ipad50  local kind="$1" udid db control_port control_pid=""51  udid="$(sim "$kind")"52  db="mcc_ios_test_$(openssl rand -hex 4)"53  control_port="${MCC_UI_CONTROL_PORT:-8786}"54  echo "== UI tests on $kind ($udid), database $db"55  xcrun simctl bootstatus "$udid" -b >/dev/null56  # Reduce flakiness: no keyboard tutorial, hardware keyboard off so that the software keyboard behaves as on a device.57  "$BACKEND" build58  cleanup() {59    [ -n "$control_pid" ] && kill "$control_pid" 2>/dev/null || true60    "$BACKEND" stop || true61    "$PSQL_BIN" -X -q -d postgres -c "drop database if exists \"$db\" with (force)" || true62  }63  trap cleanup EXIT64  "$BACKEND" start "$db"65  "$PSQL_BIN" -X -q -d "$db" -f "$ROOT/Scripts/seed.sql"66  local shots=""67  [ -n "${MCC_UI_SCREENSHOTS:-}" ] && shots="$MCC_UI_SCREENSHOTS"68  python3 "$ROOT/Scripts/ui-test-control.py" "$control_port" "$BACKEND" "$db" "$udid" "$shots" &69  control_pid=$!70  # The one-time owner invitation goes to the test runner through its environment (never on a command line).71  export TEST_RUNNER_MCC_UI_SETUP_TOKEN="$("$BACKEND" owner "$db" owner-ui "Owner UI")"72  export TEST_RUNNER_MCC_UI_ORIGIN="http://localhost:${MCC_LOCAL_PORT:-8780}"73  export TEST_RUNNER_MCC_UI_CONTROL_PORT="$control_port"74  export TEST_RUNNER_MCC_UI_SCREENSHOTS="${shots:+1}"75  export TEST_RUNNER_MCC_UI_KIND="$kind"76  local target="MCCiOSUITests"77  if [ -n "${MCC_UI_ONLY:-}" ]; then target=""; for t in ${MCC_UI_ONLY//,/ }; do target="${target:+$target,}MCCiOSUITests/MCCiOSUITests/$t"; done; fi78  local rc=079  run "$target" "ui-$kind" "$udid" || rc=180  cleanup81  trap - EXIT82  return $rc83}8485status=086if [ "$MODE" = unit ] || [ "$MODE" = all ]; then87  echo "== string catalogs"88  python3 "$ROOT/../../packages/swift-core/Scripts/strings.py" check "$ROOT/../../packages/swift-core/Sources/MCCCore/Resources/Localizable.xcstrings" \89    "$ROOT"/Resources/*.xcstrings --sources "$ROOT/../../packages/swift-core/Sources/MCCCore" "$ROOT/Sources" || status=190  kind="${WHICH:-iphone}"; [ "$kind" = both ] && kind=iphone91  udid="$(sim "$kind")"92  echo "== unit tests on $kind ($udid)"; run MCCiOSTests "unit-$kind" "$udid" || status=193fi94if [ "$MODE" = ui ] || [ "$MODE" = all ]; then95  case "${WHICH:-both}" in96    iphone) ui iphone || status=1 ;;97    ipad) ui ipad || status=1 ;;98    *) ui iphone || status=1; ui ipad || status=1 ;;99  esac100fi101exit $status102
Files main
Menu

Theme