#!/bin/bash set -euo pipefail cd "$(dirname "$0")/.." lane=${1:?Choose unit, native-host, bench, or inventory.} shift unset PARCEL_E2E PARCEL_E2E_PREFLIGHT_ONLY PARCEL_BENCH PARCEL_BENCH_SMOKE PARCEL_REALITY case "$lane" in unit|inventory) unset PARCEL_NATIVE_HOST PARCEL_LOCALIZATION_LANGUAGE PARCEL_LOCALIZATION_SCREENSHOTS parallel=--parallel; check='check-unit' ;; native-host) [[ ${PARCEL_NATIVE_HOST:-0} == 1 ]] || { printf 'Native-host tests require PARCEL_NATIVE_HOST=1.\n' >&2; exit 2; } parallel=--no-parallel; check='check-native' ;; bench) unset PARCEL_NATIVE_HOST PARCEL_LOCALIZATION_LANGUAGE PARCEL_LOCALIZATION_SCREENSHOTS export PARCEL_BENCH_SMOKE=1 parallel=--no-parallel; check='check-bench' ;; *) printf 'Unknown test lane: %s\n' "$lane" >&2; exit 2 ;; esac skip_build=${PARCEL_TEST_SKIP_BUILD:-0} report=${PARCEL_TEST_XUNIT_OUTPUT:-build/junit.xml} if [[ $lane == native-host ]]; then report=${PARCEL_TEST_XUNIT_OUTPUT:-build/junit-native-host.xml}; fi if [[ $lane == bench ]]; then report=${PARCEL_TEST_XUNIT_OUTPUT:-build/junit-bench.xml}; fi filter= while (( $# )); do case "$1" in --skip-build) skip_build=1; shift ;; --parallel|--no-parallel) parallel=$1; shift ;; --filter|--xunit-output) [[ $# -ge 2 && -n $2 ]] || { printf 'Missing value for %s\n' "$1" >&2; exit 2; } if [[ $1 == --filter ]]; then filter=$2; else report=$2; fi shift 2 ;; *) printf 'Unsupported lane argument: %s\n' "$1" >&2; exit 2 ;; esac done if [[ $lane == inventory ]]; then [[ -z $filter ]] || { printf 'Inventory cannot narrow the lane partition.\n' >&2; exit 2; } skip_build=0 elif [[ $lane != unit && $parallel != --no-parallel ]]; then printf 'Native-host and benchmark tests must run serially.\n' >&2 exit 2 fi if [[ $lane != inventory ]]; then mkdir -p "$(dirname "$report")" rm -f "$report" fi work=$(mktemp -d "${TMPDIR:-/tmp}/parcel-test-lane.XXXXXX") trap 'rm -rf "$work"' EXIT if [[ $skip_build != 1 ]]; then Scripts/swift-build.sh --build-tests; fi bin=$(swift build --show-bin-path) swift test list --skip-build > "$work/discovered" manifest="Tests/Lanes/$lane.txt" if [[ $lane == inventory ]]; then "$bin/ParcelTestSelection" inventory Tests/Lanes/unit.txt "$work/discovered" '' '' exit fi selection=$("$bin/ParcelTestSelection" select "$manifest" "$work/discovered" "$filter" "$report") status=0 if [[ $lane == native-host && ( -n ${PARCEL_LOCALIZATION_LANGUAGE:-} || ${PARCEL_PSEUDO_LOCALIZATION:-0} == 1 ) ]]; then bash Scripts/test-native-runner.sh "$bin" "$parallel" --filter "$selection" --xunit-output "$work/results.xml" || status=$? else swift test --skip-build --disable-xctest "$parallel" --filter "$selection" --xunit-output "$work/results.xml" || status=$? fi if [[ -f $work/results.xml ]]; then cp "$work/results.xml" "$report"; fi (( status == 0 )) || exit "$status" "$bin/ParcelTestSelection" "$check" "$manifest" "$work/discovered" "$filter" "$work/results.xml"