← All repositories

listless

A simple list app for Apple platforms

git clone https://code.inqk.net/listless.git


Scripts/test-unit.sh (2611B)

1#!/bin/bash
2set -euo pipefail
3
4PLATFORM="${1:-macos}"
5REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6
7case "$PLATFORM" in
8  macos)
9    SECRETS="$REPO_ROOT/.asc/secrets.sh"
10
11    if [[ ! -f "$SECRETS" ]]; then
12      echo "Error: $SECRETS not found. See Scripts/secrets.sh.example for the required format."
13      exit 1
14    fi
15
16    source "$SECRETS"
17
18    DEV_P12="$REPO_ROOT/.asc/dev.p12"
19    TMP_KEYCHAIN="$REPO_ROOT/.asc/build.keychain-db"
20
21    echo "==> Setting up temporary keychain..."
22    security delete-keychain "$TMP_KEYCHAIN" 2>/dev/null || true
23    security create-keychain -p "$TMP_KEYCHAIN_PASS" "$TMP_KEYCHAIN"
24    security unlock-keychain -p "$TMP_KEYCHAIN_PASS" "$TMP_KEYCHAIN"
25    security set-keychain-settings -lut 21600 "$TMP_KEYCHAIN"
26    security import "$DEV_P12" -k "$TMP_KEYCHAIN" -P "$DEV_P12_PASS" \
27        -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild
28    security set-key-partition-list -S apple-tool:,apple:,codesign:,productbuild: \
29        -s -k "$TMP_KEYCHAIN_PASS" "$TMP_KEYCHAIN"
30    security list-keychains -d user -s "$TMP_KEYCHAIN" ~/Library/Keychains/login.keychain-db
31
32    cleanup_keychain() {
33        echo "==> Restoring keychain search list..."
34        security list-keychains -d user -s ~/Library/Keychains/login.keychain-db
35        security default-keychain -d user -s ~/Library/Keychains/login.keychain-db
36        security delete-keychain "$TMP_KEYCHAIN" 2>/dev/null || true
37    }
38    trap cleanup_keychain EXIT
39
40    echo "==> Running macOS unit tests..."
41    xcodebuild test \
42      -scheme "Listless macOS" \
43      -destination 'platform=macOS' \
44      -only-testing:"Listless macOS Unit Tests" \
45      2>&1
46    ;;
47  ios)
48    MAJOR="${2:-26}"
49    RUNTIME=$(xcrun simctl list runtimes available \
50      | grep "iOS ${MAJOR}\." \
51      | sed 's/.*iOS \([0-9.]*\).*/\1/' \
52      | sort -t. -k1,1n -k2,2n \
53      | tail -1)
54
55    if [ -z "$RUNTIME" ]; then
56      echo "No available iOS ${MAJOR}.x simulator runtime found." >&2
57      exit 1
58    fi
59
60    DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
61      | grep "iPhone" \
62      | head -1 \
63      | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/')
64
65    if [ -z "$DEVICE" ]; then
66      echo "No available iPhone simulator found for iOS ${RUNTIME}." >&2
67      exit 1
68    fi
69
70    echo "Using ${DEVICE}, iOS ${RUNTIME}"
71    xcodebuild test \
72      -scheme "Listless iOS" \
73      -destination "platform=iOS Simulator,name=${DEVICE},OS=${RUNTIME}" \
74      -only-testing:"Listless iOS Unit Tests" \
75      2>&1
76    ;;
77  *)
78    echo "Usage: $0 [macos|ios] [ios-major-version]" >&2
79    exit 1
80    ;;
81esac