Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338#!/bin/bashset -euo pipefailcd "$(dirname "$0")/../.."unset PARCEL_TEST_SKIP_BUILD PARCEL_TEST_XUNIT_OUTPUTwork=$(mktemp -d "${TMPDIR:-/tmp}/test-runner.XXXXXX")trap 'rm -rf "$work"' EXITmkdir -p "$work/project/Scripts" "$work/project/Tests/Lanes" "$work/bin"cp Scripts/test.sh Scripts/test-unit.sh Scripts/test-lane.sh Scripts/test-native-host.sh Scripts/test-native-runner.sh Scripts/NativeTestHost.plist "$work/project/Scripts/"cp Tests/Lanes/*.txt "$work/project/Tests/Lanes/"selector=${PARCEL_TEST_SELECTION_BINARY:-$(swift build --show-bin-path)/ParcelTestSelection}cp "$selector" "$work/bin/"cat > "$work/project/Scripts/swift-build.sh" <<'MOCK'#!/bin/shset -euexec swift build "$@"MOCKchmod +x "$work/project/Scripts/swift-build.sh"export TEST_BIN="$work/bin" TEST_EVENTS="$work/events" TEST_ENVIRONMENT="$work/environment"export TEST_DISCOVERY="$work/discovered" TEST_REPORT="$work/report.xml"python3 -I - "$work/project/Tests/Lanes/unit.txt" "$TEST_DISCOVERY" "$TEST_REPORT" <<'PY'import sysfrom pathlib import Pathfrom xml.etree.ElementTree import Element, SubElement, ElementTreesuites = [s for s in Path(sys.argv[1]).read_text().splitlines() if s and not s.startswith('#')]other = [s for lane in ['native-host', 'bench'] for s in Path(sys.argv[1]).with_name(lane + '.txt').read_text().splitlines() if s and not s.startswith('#')]Path(sys.argv[2]).write_text('\n'.join(s if s.endswith(')') else s + '/example()' for s in suites + other) + '\n')root = Element('testsuites')for suite in suites: if suite.endswith(')'): classname, name = suite.split('.', 1) else: classname, name = suite.replace('/', '.'), 'example()' SubElement(root, 'testcase', classname=classname, name=name)ElementTree(root).write(sys.argv[3])PYcat > "$work/bin/swift" <<'MOCK'#!/bin/bashset -euo pipefailprintf '%s\n' "$*" >> "$TEST_EVENTS"if [[ $* == 'build --show-bin-path' ]]; then printf '%s\n' "$TEST_BIN"; exit; fiif [[ $* == 'build --build-tests' ]]; then exit "${TEST_BUILD_STATUS:-0}"; fiif [[ $* == 'test list --skip-build' ]]; then printf '%s\n' "$(< "$TEST_DISCOVERY")" exit "${TEST_LIST_STATUS:-0}"fiprintf '%s|%s|%s|%s|%s\n' "${PARCEL_NATIVE_HOST:-unset}" "${PARCEL_E2E:-unset}" "${PARCEL_BENCH:-unset}" "${PARCEL_BENCH_SMOKE:-unset}" "${PARCEL_LOCALIZATION_SCREENSHOTS:-unset}" > "$TEST_ENVIRONMENT"previous=for arg in "$@"; do if [[ $previous == --xunit-output && ${TEST_NO_REPORT:-0} != 1 ]]; then cp "$TEST_REPORT" "$arg"; fi previous=$argdoneexit "${TEST_SWIFT_STATUS:-0}"MOCKchmod +x "$work/bin/swift"export PATH="$work/bin:$PATH"count=0check() { "$@" || { printf 'Test runner check failed: %s\n' "$*" >&2; exit 1; }; count=$((count + 1)); }fails_with() { local expected=$1 status=0 shift "$@" > "$work/failure.log" 2>&1 || status=$? [[ $status == "$expected" ]]}runner="$work/project/Scripts/test.sh"check env PARCEL_NATIVE_HOST=1 PARCEL_E2E=1 PARCEL_BENCH=1 PARCEL_BENCH_SMOKE=1 PARCEL_LOCALIZATION_SCREENSHOTS=/private/captures bash "$runner"printf 'unset|unset|unset|unset|unset\n' > "$work/expected"check cmp "$work/expected" "$TEST_ENVIRONMENT"check test -f "$work/project/build/junit.xml"check grep -q '^build --build-tests$' "$TEST_EVENTS"check grep -q '^test list --skip-build$' "$TEST_EVENTS"check grep -q '^test --skip-build --disable-xctest --parallel --filter \^' "$TEST_EVENTS": > "$TEST_EVENTS"check env PARCEL_TEST_SKIP_BUILD=1 PARCEL_TEST_XUNIT_OUTPUT="$work/custom.xml" bash "$runner" --no-parallelcheck test -f "$work/custom.xml"check test "$(grep -c '^build --build-tests$' "$TEST_EVENTS" || true)" == 0check grep -q '^test --skip-build --disable-xctest --no-parallel --filter ' "$TEST_EVENTS"check bash "$runner" --skip-build --xunit-output "$work/argument.xml"check test -f "$work/argument.xml"check fails_with 2 bash "$runner" --package-path /othercheck fails_with 2 bash "$runner" --filtercheck fails_with 2 bash "$runner" --skip unsafecheck fails_with 1 bash "$runner" --filter 'NoSuchTest'check fails_with 1 bash "$runner" --filter 'AppKitTestSuite|ParcelPerformanceTests'check bash "$runner" --skip-buildcheck fails_with 17 env TEST_BUILD_STATUS=17 bash "$runner"check test ! -e "$work/project/build/junit.xml"check fails_with 19 env TEST_LIST_STATUS=19 bash "$runner" --skip-buildcheck fails_with 7 env TEST_SWIFT_STATUS=7 bash "$runner" --skip-build --xunit-output "$work/failed.xml"check test -f "$work/failed.xml"check fails_with 1 env TEST_NO_REPORT=1 bash "$runner" --skip-buildcheck test ! -e "$work/project/build/junit.xml"check bash "$runner" --skip-buildcheck fails_with 19 env TEST_LIST_STATUS=19 bash "$runner" --skip-buildcheck test ! -e "$work/project/build/junit.xml"cp "$TEST_DISCOVERY" "$work/saved-discovery"for identifier in 'ParcelE2ETests.NewScreenFreeTests/escape()' 'ParcelPerformanceTests.NewBenchmarkTests/escape()'; do printf '%s\n' "$identifier" >> "$TEST_DISCOVERY" check fails_with 1 bash "$runner" --skip-build cp "$work/saved-discovery" "$TEST_DISCOVERY"donecp "$work/project/Tests/Lanes/unit.txt" "$work/saved-unit"printf 'ParcelPerformanceTests.PerformanceTestSuite\n' >> "$work/project/Tests/Lanes/unit.txt"check fails_with 1 bash "$runner" --skip-buildcp "$work/saved-unit" "$work/project/Tests/Lanes/unit.txt""$TEST_BIN/ParcelTestSelection" select "$work/project/Tests/Lanes/bench.txt" "$TEST_DISCOVERY" '' "$TEST_REPORT" > "$work/bench-filter"check grep -Fq 'ParcelPerformanceTests\.PerformanceTestSuite' "$work/bench-filter": > "$TEST_EVENTS"check env PARCEL_TEST_SKIP_BUILD=1 bash "$work/project/Scripts/test-lane.sh" inventorycheck grep -q '^build --build-tests$' "$TEST_EVENTS"check test "$(grep -c '^test --skip-build ' "$TEST_EVENTS" || true)" == 0check fails_with 2 bash "$work/project/Scripts/test-lane.sh" inventory --filter 'Geometry'printf 'NewTests.Unclassified/test()\n' >> "$TEST_DISCOVERY"check fails_with 1 bash "$work/project/Scripts/test-lane.sh" inventorycp "$work/saved-discovery" "$TEST_DISCOVERY"check grep -Fq 'ParcelE2ETests.FixtureReplyTests' "$work/project/Tests/Lanes/unit.txt": > "$TEST_DISCOVERY"check fails_with 1 bash "$runner" --skip-buildcp "$work/saved-discovery" "$TEST_DISCOVERY"python3 -I - "$TEST_DISCOVERY" <<'PY'import sysfrom pathlib import Pathp = Path(sys.argv[1]); p.write_text('\n'.join(p.read_text().splitlines()[1:]) + '\n')PYcheck fails_with 1 bash "$runner" --skip-buildcp "$work/saved-discovery" "$TEST_DISCOVERY"cp "$TEST_REPORT" "$work/saved-report"printf '<testsuites/>\n' > "$TEST_REPORT"check fails_with 1 bash "$runner" --skip-buildpython3 -I - "$work/saved-report" "$TEST_REPORT" <<'PY'import sysfrom xml.etree.ElementTree import parse, SubElementreport = parse(sys.argv[1])report.getroot().remove(report.getroot()[0])report.write(sys.argv[2])PYcheck fails_with 1 bash "$runner" --skip-buildpython3 -I - "$work/saved-report" "$TEST_REPORT" <<'PY'import sysfrom xml.etree.ElementTree import parse, SubElementreport = parse(sys.argv[1])SubElement(report.getroot()[0], 'skipped')report.write(sys.argv[2])PYcheck fails_with 1 bash "$runner" --skip-buildcp "$work/saved-report" "$TEST_REPORT"printf 'UnexpectedTests.NewSuite/escape()\n' >> "$TEST_DISCOVERY"check fails_with 1 bash "$runner" --skip-buildcp "$work/saved-discovery" "$TEST_DISCOVERY"python3 -I - "$work/saved-report" "$TEST_REPORT" <<'PY'import sysfrom xml.etree.ElementTree import parse, SubElementreport = parse(sys.argv[1])SubElement(report.getroot(), 'testcase', classname='UnexpectedTests.NewSuite', name='escape()')report.write(sys.argv[2])PYcheck fails_with 1 bash "$runner" --skip-buildprintf '<not-a-report/>\n' > "$TEST_REPORT"check fails_with 1 bash "$runner" --skip-buildfor mode in missing-global skipped-global unexpected-global; do python3 -I - "$work/saved-report" "$TEST_REPORT" "$mode" <<'PY'import sysfrom xml.etree.ElementTree import parse, SubElementreport = parse(sys.argv[1])case = next(c for c in report.getroot() if '.' not in c.attrib['classname'])if sys.argv[3] == 'missing-global': report.getroot().remove(case)elif sys.argv[3] == 'skipped-global': SubElement(case, 'skipped')else: SubElement(report.getroot(), 'testcase', classname=case.attrib['classname'], name='unexpectedGlobal()')report.write(sys.argv[2])PY check fails_with 1 bash "$runner" --skip-builddonecp "$work/saved-report" "$TEST_REPORT"printf 'UnexpectedTests.globalEscape()\n' >> "$TEST_DISCOVERY"check fails_with 1 bash "$runner" --skip-buildcp "$work/saved-discovery" "$TEST_DISCOVERY"python3 -I - "$work/saved-report" "$TEST_REPORT" "$work/global-filter" <<'PY'import re, sysfrom pathlib import Pathfrom xml.etree.ElementTree import parse, Element, ElementTreereport = parse(sys.argv[1])case = next(c for c in report.getroot() if '.' not in c.attrib['classname'])root = Element('testsuites'); root.append(case)ElementTree(root).write(sys.argv[2])Path(sys.argv[3]).write_text('^' + re.escape(case.attrib['classname'] + '.' + case.attrib['name']) + '$')PYcheck bash "$runner" --skip-build --filter "$(< "$work/global-filter")"python3 -I - "$work/project/Tests/Lanes/bench.txt" "$TEST_REPORT" <<'PY'import sysfrom pathlib import Pathfrom xml.etree.ElementTree import Element, SubElement, ElementTreeroot = Element('testsuites')for suite in Path(sys.argv[1]).read_text().splitlines(): if suite and not suite.startswith('#'): SubElement(root, 'testcase', classname=suite.replace('/', '.'), name='example()')ElementTree(root).write(sys.argv[2])PY: > "$TEST_EVENTS"check env PARCEL_NATIVE_HOST=1 PARCEL_E2E=1 PARCEL_BENCH=1 PARCEL_LOCALIZATION_SCREENSHOTS=/private/captures bash "$work/project/Scripts/test-lane.sh" bench --skip-buildprintf 'unset|unset|unset|1|unset\n' > "$work/expected"check cmp "$work/expected" "$TEST_ENVIRONMENT"check test -f "$work/project/build/junit-bench.xml"check grep -q '^test --skip-build --disable-xctest --no-parallel --filter ' "$TEST_EVENTS"check fails_with 2 bash "$work/project/Scripts/test-lane.sh" bench --parallelcheck fails_with 1 bash "$work/project/Scripts/test-lane.sh" bench --skip-build --filter 'SettingsTests'cp "$TEST_REPORT" "$work/bench-report"for mode in missing-suite skipped-suite unexpected-suite empty; do python3 -I - "$work/bench-report" "$TEST_REPORT" "$mode" <<'PY'import sysfrom xml.etree.ElementTree import parse, SubElementreport = parse(sys.argv[1]); root = report.getroot()if sys.argv[3] == 'missing-suite': root.remove(root[0])elif sys.argv[3] == 'skipped-suite': SubElement(root[0], 'skipped')elif sys.argv[3] == 'unexpected-suite': SubElement(root, 'testcase', classname='UnexpectedTests.Suite', name='escape()')else: root.clear()report.write(sys.argv[2])PY check fails_with 1 bash "$work/project/Scripts/test-lane.sh" bench --skip-builddonepython3 -I - "$work/saved-discovery" "$TEST_DISCOVERY" "$work/bench-report" "$TEST_REPORT" <<'PY'import sysfrom pathlib import Pathfrom xml.etree.ElementTree import parse, SubElementparent = 'ParcelPerformanceTests.EngineCorePerformanceTests'text = Path(sys.argv[1]).read_text()old = parent + '/example()'assert text.count(old) == 1Path(sys.argv[2]).write_text(text.replace(old, parent + '/Counters/counter()\n' + parent + '/Workloads/workload()'))report = parse(sys.argv[3]); root = report.getroot()case = next(c for c in root if c.attrib['classname'] == parent)root.remove(case)SubElement(root, 'testcase', classname=parent + '.Counters', name='counter()')SubElement(root, 'testcase', classname=parent + '.Workloads', name='workload()')report.write(sys.argv[4])PYcheck bash "$work/project/Scripts/test-lane.sh" bench --skip-buildcp "$TEST_REPORT" "$work/nested-bench-report"for child in Counters Workloads; do python3 -I - "$work/nested-bench-report" "$TEST_REPORT" "$child" <<'PY'import sysfrom xml.etree.ElementTree import parse, SubElementreport = parse(sys.argv[1])case = next(c for c in report.getroot() if c.attrib['classname'].endswith('.' + sys.argv[3]))SubElement(case, 'skipped')report.write(sys.argv[2])PY check fails_with 1 bash "$work/project/Scripts/test-lane.sh" bench --skip-build check grep -q 'Required suite did not execute' "$work/failure.log"donecp "$work/saved-discovery" "$TEST_DISCOVERY"cp "$work/bench-report" "$TEST_REPORT"mkdir -p "$work/toolchain/usr/bin" "$work/toolchain/usr/libexec/swift/pm" "$work/sdk/Developer/Library/Frameworks" "$TEST_BIN/ParcelPackageTests.xctest/Contents/MacOS": > "$TEST_BIN/ParcelPackageTests.xctest/Contents/MacOS/ParcelPackageTests"export TEST_TOOLCHAIN="$work/toolchain" TEST_SDK="$work/sdk"export TEST_NATIVE_ARGUMENTS="$work/native-arguments" TEST_HOST_INFO="$work/host.plist"cat > "$work/bin/xcrun" <<'MOCK'#!/bin/bashset -euo pipefailcase "$*" in '--find swift') printf '%s\n' "$TEST_TOOLCHAIN/usr/bin/swift" ;; '--show-sdk-platform-path') printf '%s\n' "$TEST_SDK" ;; *) exit 2 ;;esacMOCKcat > "$work/toolchain/usr/libexec/swift/pm/swiftpm-testing-helper" <<'MOCK'#!/bin/bashset -euo pipefailcp "$(dirname "$0")/../Info.plist" "$TEST_HOST_INFO"printf '%s\n' "$@" > "$TEST_NATIVE_ARGUMENTS"exec "$TEST_BIN/swift" test "$@"MOCKchmod +x "$work/bin/xcrun" "$work/toolchain/usr/libexec/swift/pm/swiftpm-testing-helper"python3 -I - "$work/project/Tests/Lanes/native-host.txt" "$TEST_REPORT" <<'PY'import sysfrom pathlib import Pathfrom xml.etree.ElementTree import Element, SubElement, ElementTreeroot = Element('testsuites')for suite in Path(sys.argv[1]).read_text().splitlines(): if suite and not suite.startswith('#'): SubElement(root, 'testcase', classname=suite.replace('/', '.'), name='example()')ElementTree(root).write(sys.argv[2])PYcheck env PARCEL_NATIVE_HOST=1 PARCEL_LOCALIZATION_LANGUAGE=de bash "$work/project/Scripts/test-lane.sh" native-host --skip-buildcheck grep -q '^--no-parallel$' "$TEST_NATIVE_ARGUMENTS"check grep -q '^-AppleLanguages$' "$TEST_NATIVE_ARGUMENTS"check grep -q '^(de)$' "$TEST_NATIVE_ARGUMENTS"check test "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleAllowMixedLocalizations' "$TEST_HOST_INFO")" == truecheck test "$(find "$work/project/.build" -name 'native-test-host.*' -print | wc -l | tr -d ' ')" == 0check env PARCEL_NATIVE_HOST=1 PARCEL_PSEUDO_LOCALIZATION=1 PARCEL_LOCALIZATION_LANGUAGE=de bash "$work/project/Scripts/test-lane.sh" native-host --skip-buildcheck grep -q '^(en-XA)$' "$TEST_NATIVE_ARGUMENTS"check fails_with 2 env PARCEL_NATIVE_HOST=1 PARCEL_LOCALIZATION_LANGUAGE=invalid bash "$work/project/Scripts/test-lane.sh" native-host --skip-buildfor mode in all-skipped permission-skipped; do python3 -I - "$work/project/Tests/Lanes/native-host.txt" "$TEST_REPORT" "$mode" <<'PY'import sysfrom pathlib import Pathfrom xml.etree.ElementTree import Element, SubElement, ElementTreesuites = [s for s in Path(sys.argv[1]).read_text().splitlines() if s and not s.startswith('#')]root = Element('testsuites')for suite in suites: case = SubElement(root, 'testcase', classname=suite.replace('/', '.'), name='example()') if sys.argv[3] == 'all-skipped' or suite.endswith('/InputPermissionTests'): SubElement(case, 'skipped', message='Accessibility is not granted')ElementTree(root).write(sys.argv[2])PY if [[ $mode == all-skipped ]]; then check fails_with 1 "$TEST_BIN/ParcelTestSelection" check-native "$work/project/Tests/Lanes/native-host.txt" "$TEST_DISCOVERY" '' "$TEST_REPORT" else check "$TEST_BIN/ParcelTestSelection" check-native "$work/project/Tests/Lanes/native-host.txt" "$TEST_DISCOVERY" '' "$TEST_REPORT" fidonecheck fails_with 2 env PARCEL_NATIVE_HOST=0 bash "$work/project/Scripts/test-native-host.sh"cat > "$work/project/Scripts/screen-lock.sh" <<'MOCK'#!/bin/bashset -euo pipefailprintf '%s\n' "${PARCEL_SCREEN_OWNER:-}" > "$TEST_LOCK_OWNER"exit 29MOCKchmod +x "$work/project/Scripts/screen-lock.sh"check fails_with 29 env PARCEL_NATIVE_HOST=1 TEST_LOCK_OWNER="$work/owner" bash "$work/project/Scripts/test-native-host.sh"printf 'native-host\n' > "$work/expected"check cmp "$work/expected" "$work/owner"for target in test test-serial test-scripts; do make --no-print-directory --dry-run "$target" > "$work/actual" case "$target" in test) printf '%s\n' 'mise run test' > "$work/expected" ;; test-serial) printf '%s\n' 'mise run test:serial' > "$work/expected" ;; test-scripts) printf '%s\n' 'mise run test:scripts' > "$work/expected" ;; esac check cmp "$work/expected" "$work/actual"doneprintf 'Test runner checks passed: %s\n' "$count"