Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/t.sh4# Description: Runs the tests of SP Vault and prints only verdict lines (failures + the summary).5#6# Usage: Scripts/t.sh kit [filter] SharedVaultKit: `swift test` (starts its own server on 8771)7# Scripts/t.sh mac [xcodebuild args] unit tests of the macOS app (SPVaultTests, hosted by "SP Vault Dev")8# Scripts/t.sh ios [xcodebuild args] unit tests on the simulator "SPVault iPhone" (SPVaultTests-iOS)9# Scripts/t.sh ui-mac [args] UI tests of "SP Vault Dev" on macOS (SPVaultUITests)10# Scripts/t.sh ui-ios [args] UI tests on "SPVault iPhone" (SPVaultUITests-iOS)11# Scripts/t.sh ui-ipad [args] the same on "SPVault iPad"12# extra arguments go to xcodebuild, e.g. Scripts/t.sh ui-ios -only-testing:SPVaultUITests-iOS/JourneyTests/testJoin13# UI tests drive the Dev variant against the real local server: Scripts/dev-server.sh up is called first.14# SPV_DD overrides the DerivedData root, SPV_LINES the number of lines printed, SPV_TIMEOUT the limit in seconds.15set -uo pipefail16export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"17cd "$(dirname "$0")/.."18WHAT="${1:-kit}"; shift || true19DD="${SPV_DD:-$HOME/Library/Developer/SPVault/DerivedData}"; LINES_MAX="${SPV_LINES:-40}"; LIMIT="${SPV_TIMEOUT:-1800}"20mkdir -p build/logs "$DD"21sim() { xcrun simctl list devices | grep -F "$1 (" | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/'; }22report() { # log → failures + summary23 sed 's/\x1b\[[0-9;]*m//g' "$1" | grep -E "error:|: error|failed|Executed [0-9]+ tests?|TIMEOUT|Fatal|\*\* TEST|Test run with|Testing failed|BUILD FAILED" \24 | grep -vE "^Test Suite .* (started|passed)|appintentsmetadataprocessor|Process Instance Registry|' passed|^ *\|" | sed -E "s#$PWD/##" | cut -c1-400 | awk '!seen[$0]++' | tail -"$LINES_MAX"25}26xc() { # scheme, destination, target-to-test, log, extra args…27 local scheme="$1" dest="$2" only="$3" log="$4"; shift 428 xcodegen generate --quiet || exit 129 local args=("$@"); local has_only=030 for a in ${args[@]+"${args[@]}"}; do [[ "$a" == -only-testing:* ]] && has_only=1; done31 [[ $has_only -eq 1 ]] || args+=("-only-testing:$only")32 perl -e 'alarm shift; exec @ARGV' "$LIMIT" xcodebuild -project SPVault.xcodeproj -scheme "$scheme" -configuration Debug -destination "$dest" \33 -derivedDataPath "$DD" test "${args[@]}" > "$log" 2>&134 local status=$?35 [[ $status -eq 142 ]] && echo "TIMEOUT after ${LIMIT}s" >> "$log"36 report "$log"; echo "log: $log"37 return $status38}39ios_dest() { local u; u="$(sim "$1")"; [[ -n "$u" ]] || { echo "simulator \"$1\" missing: run Scripts/build.sh ios once" >&2; exit 1; }; echo "platform=iOS Simulator,id=$u"; }40case "$WHAT" in41 kit) LOG="$PWD/build/logs/test-kit.log"42 ( cd SharedVaultKit && perl -e 'alarm shift; exec @ARGV' "$LIMIT" swift test ${1:+--filter "$1"} > "$LOG" 2>&1 ); STATUS=$?43 [[ $STATUS -eq 142 ]] && echo "TIMEOUT after ${LIMIT}s" >> "$LOG"44 report "$LOG"; echo "log: $LOG"; exit $STATUS ;;45 mac) xc SPVault "platform=macOS" SPVaultTests build/logs/test-mac.log "$@" ;;46 ios) xc SPVault-iOS "$(ios_dest "SPVault iPhone")" SPVaultTests-iOS build/logs/test-ios.log "$@" ;;47 ui-mac) Scripts/dev-server.sh up || exit 1; xc SPVault "platform=macOS" SPVaultUITests build/logs/test-ui-mac.log "$@" ;;48 ui-ios) Scripts/dev-server.sh up || exit 1; xc SPVault-iOS "$(ios_dest "SPVault iPhone")" SPVaultUITests-iOS build/logs/test-ui-ios.log "$@" ;;49 ui-ipad) Scripts/dev-server.sh up || exit 1; xc SPVault-iOS "$(ios_dest "SPVault iPad")" SPVaultUITests-iOS build/logs/test-ui-ipad.log "$@" ;;50 *) echo "usage: $0 kit [filter] | mac | ios | ui-mac | ui-ios | ui-ipad [xcodebuild args]"; exit 2 ;;51esac52