Run the unit suite on the floor and current runtimes !10
4 files changed, +165 −38
Layout: unified · split
README.org +12
| @@ -44,6 +44,18 @@ xcodebuild -project DomainDig.xcodeproj -scheme DomainDig \ | |||
| 44 | * tests | 44 | * tests |
| 45 | deterministic core coverage lives in DomainDigTests: | 45 | deterministic core coverage lives in DomainDigTests: |
| 46 | 46 | ||
| 47 | #+begin_src sh | ||
| 48 | ./Scripts/test.sh # oldest supported + newest | ||
| 49 | ./Scripts/test.sh current # newest only | ||
| 50 | #+end_src | ||
| 51 | |||
| 52 | both tiers matter. releasing a main-actor-isolated object aborts the runner | ||
| 53 | under ios 18.6 — a swift runtime bug in MarkerItem::create, fixed by 26.5 — so | ||
| 54 | a test can pass on one runtime and die on the other. pinning one destination | ||
| 55 | hides whichever direction it is pinned away from. | ||
| 56 | |||
| 57 | a one-off run against a specific simulator: | ||
| 58 | |||
| 47 | #+begin_src sh | 59 | #+begin_src sh |
| 48 | xcodebuild test -project DomainDig.xcodeproj -scheme DomainDig \ | 60 | xcodebuild test -project DomainDig.xcodeproj -scheme DomainDig \ |
| 49 | -destination 'platform=iOS Simulator,name=iPhone 16' \ | 61 | -destination 'platform=iOS Simulator,name=iPhone 16' \ |
Scripts/audit-a11y.sh +7 −38
| @@ -14,6 +14,8 @@ | |||
| 14 | # only iOS 26.x runtimes, so it structurally cannot cover the floor. This machine | 14 | # only iOS 26.x runtimes, so it structurally cannot cover the floor. This machine |
| 15 | # can. | 15 | # can. |
| 16 | # | 16 | # |
| 17 | # Scripts/test.sh does the same for the unit suite, for its own reasons. | ||
| 18 | # | ||
| 17 | # CI covers "current" on a clean checkout (which a local run cannot, since it | 19 | # CI covers "current" on a clean checkout (which a local run cannot, since it |
| 18 | # would miss an uncommitted file). This script covers "floor" (which CI cannot). | 20 | # would miss an uncommitted file). This script covers "floor" (which CI cannot). |
| 19 | # Together they cover both; neither duplicates the other. | 21 | # Together they cover both; neither duplicates the other. |
| @@ -29,6 +31,9 @@ PROJECT="DomainDig.xcodeproj" | |||
| 29 | SCHEME="DomainDig" | 31 | SCHEME="DomainDig" |
| 30 | TIER="${1:-both}" | 32 | TIER="${1:-both}" |
| 31 | 33 | ||
| 34 | # shellcheck source=lib/simulators.sh | ||
| 35 | source "$(dirname "$0")/lib/simulators.sh" | ||
| 36 | |||
| 32 | case "$TIER" in | 37 | case "$TIER" in |
| 33 | floor | current | both) ;; | 38 | floor | current | both) ;; |
| 34 | *) | 39 | *) |
| @@ -38,45 +43,9 @@ case "$TIER" in | |||
| 38 | esac | 43 | esac |
| 39 | 44 | ||
| 40 | echo "==> Reading deployment target from $PROJECT" | 45 | echo "==> Reading deployment target from $PROJECT" |
| 41 | DEPLOYMENT_TARGET=$( | 46 | read_deployment_target |
| 42 | xcodebuild -project "$PROJECT" -scheme "$SCHEME" -showBuildSettings 2>/dev/null \ | ||
| 43 | | awk -F' = ' '/ IPHONEOS_DEPLOYMENT_TARGET = /{print $2; exit}' | ||
| 44 | ) | ||
| 45 | |||
| 46 | if [[ -z "${DEPLOYMENT_TARGET:-}" ]]; then | ||
| 47 | echo "error: could not read IPHONEOS_DEPLOYMENT_TARGET" >&2 | ||
| 48 | exit 1 | ||
| 49 | fi | ||
| 50 | |||
| 51 | DT_MAJOR="${DEPLOYMENT_TARGET%%.*}" | ||
| 52 | DT_MINOR="${DEPLOYMENT_TARGET##*.}" | ||
| 53 | [[ "$DT_MINOR" = "$DEPLOYMENT_TARGET" ]] && DT_MINOR=0 | ||
| 54 | FLOOR_RANK=$(( DT_MAJOR * 1000 + DT_MINOR )) | ||
| 55 | |||
| 56 | echo " deployment target: $DEPLOYMENT_TARGET (rank $FLOOR_RANK)" | 47 | echo " deployment target: $DEPLOYMENT_TARGET (rank $FLOOR_RANK)" |
| 57 | 48 | ||
| 58 | # Pick an iPhone simulator at or above the deployment target. A runtime BELOW it | ||
| 59 | # is useless — the app cannot install there — which is why this filters rather | ||
| 60 | # than just taking the oldest installed runtime. | ||
| 61 | select_sim() { | ||
| 62 | local which="$1" | ||
| 63 | xcrun simctl list devices available --json \ | ||
| 64 | | jq -c --argjson floor "$FLOOR_RANK" --arg which "$which" ' | ||
| 65 | [ .devices | to_entries[] | ||
| 66 | | (.key | capture("SimRuntime\\.iOS-(?<maj>[0-9]+)-(?<min>[0-9]+)$")) as $v | ||
| 67 | | (($v.maj | tonumber) * 1000 + ($v.min | tonumber)) as $rank | ||
| 68 | | select($rank >= $floor) | ||
| 69 | | .value[] | ||
| 70 | | select(.name | startswith("iPhone")) | ||
| 71 | | { rank: $rank, udid: .udid, name: .name, os: "\($v.maj).\($v.min)" } | ||
| 72 | ] | ||
| 73 | | sort_by(.rank, .name) | ||
| 74 | | if length == 0 then empty | ||
| 75 | elif $which == "floor" then first | ||
| 76 | else last end | ||
| 77 | ' | ||
| 78 | } | ||
| 79 | |||
| 80 | run_tier() { | 49 | run_tier() { |
| 81 | local which="$1" | 50 | local which="$1" |
| 82 | local sim udid label | 51 | local sim udid label |
| @@ -94,7 +63,7 @@ run_tier() { | |||
| 94 | echo | 63 | echo |
| 95 | echo "==> $which: $label" | 64 | echo "==> $which: $label" |
| 96 | 65 | ||
| 97 | if [[ "$which" = "floor" ]] && [[ "$(echo "$sim" | jq -r .rank)" -ge $(( (DT_MAJOR + 1) * 1000 )) ]]; then | 66 | if [[ "$which" = "floor" ]] && floor_is_approximate "$sim"; then |
| 98 | echo " NOTE: nearest installed runtime is a major version above the $DEPLOYMENT_TARGET" | 67 | echo " NOTE: nearest installed runtime is a major version above the $DEPLOYMENT_TARGET" |
| 99 | echo " deployment target, so this is not true floor coverage." | 68 | echo " deployment target, so this is not true floor coverage." |
| 100 | fi | 69 | fi |
Scripts/lib/simulators.sh added +59
| @@ -0,0 +1,59 @@ | |||
| 1 | # Simulator selection shared by the test scripts. Sourced, not executed. | ||
| 2 | # | ||
| 3 | # The caller sets PROJECT and SCHEME first, then calls | ||
| 4 | # read_deployment_target once and select_sim per tier. | ||
| 5 | # | ||
| 6 | # Runtime coverage is not nested: a result on one iOS version does not imply | ||
| 7 | # the same result on another, in either direction. Scripts/audit-a11y.sh | ||
| 8 | # documents the measured accessibility differences; the unit suite has its own | ||
| 9 | # case, a Swift runtime bug in MarkerItem::create that aborts on releasing a | ||
| 10 | # main-actor-isolated object under iOS 18.6 and is fixed by iOS 26.5. Both are | ||
| 11 | # reasons to run floor and current rather than whichever simulator is handy. | ||
| 12 | |||
| 13 | # Sets DEPLOYMENT_TARGET, DT_MAJOR, DT_MINOR and FLOOR_RANK from the project, | ||
| 14 | # so the floor cannot drift away from the build setting. | ||
| 15 | read_deployment_target() { | ||
| 16 | DEPLOYMENT_TARGET=$( | ||
| 17 | xcodebuild -project "$PROJECT" -scheme "$SCHEME" -showBuildSettings 2>/dev/null \ | ||
| 18 | | awk -F' = ' '/ IPHONEOS_DEPLOYMENT_TARGET = /{print $2; exit}' | ||
| 19 | ) | ||
| 20 | |||
| 21 | if [[ -z "${DEPLOYMENT_TARGET:-}" ]]; then | ||
| 22 | echo "error: could not read IPHONEOS_DEPLOYMENT_TARGET" >&2 | ||
| 23 | return 1 | ||
| 24 | fi | ||
| 25 | |||
| 26 | DT_MAJOR="${DEPLOYMENT_TARGET%%.*}" | ||
| 27 | DT_MINOR="${DEPLOYMENT_TARGET##*.}" | ||
| 28 | [[ "$DT_MINOR" = "$DEPLOYMENT_TARGET" ]] && DT_MINOR=0 | ||
| 29 | FLOOR_RANK=$(( DT_MAJOR * 1000 + DT_MINOR )) | ||
| 30 | } | ||
| 31 | |||
| 32 | # Pick an iPhone simulator at or above the deployment target. A runtime BELOW it | ||
| 33 | # is useless — the app cannot install there — which is why this filters rather | ||
| 34 | # than just taking the oldest installed runtime. | ||
| 35 | select_sim() { | ||
| 36 | local which="$1" | ||
| 37 | xcrun simctl list devices available --json \ | ||
| 38 | | jq -c --argjson floor "$FLOOR_RANK" --arg which "$which" ' | ||
| 39 | [ .devices | to_entries[] | ||
| 40 | | (.key | capture("SimRuntime\\.iOS-(?<maj>[0-9]+)-(?<min>[0-9]+)$")) as $v | ||
| 41 | | (($v.maj | tonumber) * 1000 + ($v.min | tonumber)) as $rank | ||
| 42 | | select($rank >= $floor) | ||
| 43 | | .value[] | ||
| 44 | | select(.name | startswith("iPhone")) | ||
| 45 | | { rank: $rank, udid: .udid, name: .name, os: "\($v.maj).\($v.min)" } | ||
| 46 | ] | ||
| 47 | | sort_by(.rank, .name) | ||
| 48 | | if length == 0 then empty | ||
| 49 | elif $which == "floor" then first | ||
| 50 | else last end | ||
| 51 | ' | ||
| 52 | } | ||
| 53 | |||
| 54 | # True when the chosen "floor" simulator is a major version above the | ||
| 55 | # deployment target, i.e. the floor is not actually covered. | ||
| 56 | floor_is_approximate() { | ||
| 57 | local sim="$1" | ||
| 58 | [[ "$(echo "$sim" | jq -r .rank)" -ge $(( (DT_MAJOR + 1) * 1000 )) ]] | ||
| 59 | } | ||
Scripts/test.sh added +87
| @@ -0,0 +1,87 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # Run the deterministic unit suite against real simulator runtimes. | ||
| 4 | # | ||
| 5 | # ./Scripts/test.sh # floor + current | ||
| 6 | # ./Scripts/test.sh floor # oldest supported runtime only | ||
| 7 | # ./Scripts/test.sh current # newest installed runtime only | ||
| 8 | # | ||
| 9 | # Why both rather than one simulator: the suite's result is not runtime | ||
| 10 | # independent. Releasing a main-actor-isolated object aborts the test runner | ||
| 11 | # under iOS 18.6 with "pointer being freed was not allocated" — a Swift runtime | ||
| 12 | # bug in MarkerItem::create, fixed by iOS 26.5 — so a test that constructs and | ||
| 13 | # releases a view model passes on current and dies on floor. Pinning one | ||
| 14 | # destination hides whichever direction it is pinned away from. | ||
| 15 | # | ||
| 16 | # This covers DomainDigTests only. Scripts/audit-a11y.sh covers the | ||
| 17 | # accessibility suite, which has its own reason for running both tiers. | ||
| 18 | |||
| 19 | set -euo pipefail | ||
| 20 | |||
| 21 | cd "$(dirname "$0")/.." | ||
| 22 | |||
| 23 | PROJECT="DomainDig.xcodeproj" | ||
| 24 | SCHEME="DomainDig" | ||
| 25 | TIER="${1:-both}" | ||
| 26 | |||
| 27 | # shellcheck source=lib/simulators.sh | ||
| 28 | source "$(dirname "$0")/lib/simulators.sh" | ||
| 29 | |||
| 30 | case "$TIER" in | ||
| 31 | floor | current | both) ;; | ||
| 32 | *) | ||
| 33 | echo "usage: $0 [floor|current|both]" >&2 | ||
| 34 | exit 2 | ||
| 35 | ;; | ||
| 36 | esac | ||
| 37 | |||
| 38 | echo "==> Reading deployment target from $PROJECT" | ||
| 39 | read_deployment_target | ||
| 40 | echo " deployment target: $DEPLOYMENT_TARGET (rank $FLOOR_RANK)" | ||
| 41 | |||
| 42 | run_tier() { | ||
| 43 | local which="$1" | ||
| 44 | local sim udid label | ||
| 45 | |||
| 46 | sim=$(select_sim "$which") | ||
| 47 | if [[ -z "$sim" ]]; then | ||
| 48 | echo "error: no iPhone simulator at or above iOS $DEPLOYMENT_TARGET installed" >&2 | ||
| 49 | echo "hint: install one with 'xcodebuild -downloadPlatform iOS'" >&2 | ||
| 50 | return 1 | ||
| 51 | fi | ||
| 52 | |||
| 53 | udid=$(echo "$sim" | jq -r .udid) | ||
| 54 | label=$(echo "$sim" | jq -r '"\(.name) (iOS \(.os))"') | ||
| 55 | |||
| 56 | echo | ||
| 57 | echo "==> $which: $label" | ||
| 58 | |||
| 59 | if [[ "$which" = "floor" ]] && floor_is_approximate "$sim"; then | ||
| 60 | echo " NOTE: nearest installed runtime is a major version above the $DEPLOYMENT_TARGET" | ||
| 61 | echo " deployment target, so this is not true floor coverage." | ||
| 62 | fi | ||
| 63 | |||
| 64 | set -o pipefail | ||
| 65 | xcodebuild test \ | ||
| 66 | -project "$PROJECT" \ | ||
| 67 | -scheme "$SCHEME" \ | ||
| 68 | -destination "id=$udid" \ | ||
| 69 | -only-testing:DomainDigTests 2>&1 \ | ||
| 70 | | grep -E 'Executed [0-9]+ test|\*\* TEST (SUCCEEDED|FAILED)|error:|malloc: \*\*\*|^Test Case .* failed' | ||
| 71 | } | ||
| 72 | |||
| 73 | status=0 | ||
| 74 | if [[ "$TIER" = "both" ]]; then | ||
| 75 | run_tier floor || status=1 | ||
| 76 | run_tier current || status=1 | ||
| 77 | else | ||
| 78 | run_tier "$TIER" || status=1 | ||
| 79 | fi | ||
| 80 | |||
| 81 | echo | ||
| 82 | if [[ "$status" -eq 0 ]]; then | ||
| 83 | echo "==> Done. Green on every tier run." | ||
| 84 | else | ||
| 85 | echo "==> At least one tier failed." | ||
| 86 | fi | ||
| 87 | exit "$status" | ||