Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

tests: add example project fixtures (#301)

Kabir Oberaic635db2fbc04
diff --git a/Examples/.gitignore b/Examples/.gitignore
new file mode 100644
index 0000000..8d0b8f2
--- /dev/null
+++ b/Examples/.gitignore
@@ -0,0 +1,6 @@
+.DS_Store
+.build
+.swiftpm
+*/xtool
+*/.bsp
+/out
diff --git a/Examples/DemoDynamic/Package.swift b/Examples/DemoDynamic/Package.swift
new file mode 100644
index 0000000..6846900
--- /dev/null
+++ b/Examples/DemoDynamic/Package.swift
@@ -0,0 +1,29 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoDynamic",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoDynamic",
+ targets: ["DemoDynamic"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ ],
+ targets: [
+ .target(
+ name: "DemoDynamic",
+ dependencies: [
+ "ExampleSupport",
+ .product(name: "ExampleDynamicLibrary", package: "ExampleSupport"),
+ ]
+ ),
+ ]
+)
diff --git a/Examples/DemoDynamic/Sources/DemoDynamic/App.swift b/Examples/DemoDynamic/Sources/DemoDynamic/App.swift
new file mode 100644
index 0000000..4843d4c
--- /dev/null
+++ b/Examples/DemoDynamic/Sources/DemoDynamic/App.swift
@@ -0,0 +1,12 @@
+import ExampleDynamicLibrary
+import ExampleSupport
+import SwiftUI
+
+@main struct DemoApp: ExampleApp {
+ init() {
+ let message = exampleDynamicLibraryFunction()
+ guard message == "Hello from the dynamic library\n" else {
+ fatalError("Unexpected message from dynamic library: \(message)")
+ }
+ }
+}
diff --git a/Examples/DemoDynamic/xtool.yml b/Examples/DemoDynamic/xtool.yml
new file mode 100644
index 0000000..30b819b
--- /dev/null
+++ b/Examples/DemoDynamic/xtool.yml
@@ -0,0 +1,2 @@
+version: 1
+bundleID: sh.xtool.examples.DemoDynamic
diff --git a/Examples/DemoExtensions/Package.swift b/Examples/DemoExtensions/Package.swift
new file mode 100644
index 0000000..3319b5e
--- /dev/null
+++ b/Examples/DemoExtensions/Package.swift
@@ -0,0 +1,33 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoExtensions",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoExtensions",
+ targets: ["DemoExtensions"]
+ ),
+ .library(
+ name: "DemoExtensionsWidget",
+ targets: ["DemoExtensionsWidget"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ ],
+ targets: [
+ .target(
+ name: "DemoExtensions",
+ dependencies: [
+ "ExampleSupport",
+ ]
+ ),
+ .target(name: "DemoExtensionsWidget"),
+ ]
+)
diff --git a/Examples/DemoExtensions/Sources/DemoExtensions/App.swift b/Examples/DemoExtensions/Sources/DemoExtensions/App.swift
new file mode 100644
index 0000000..f9222ae
--- /dev/null
+++ b/Examples/DemoExtensions/Sources/DemoExtensions/App.swift
@@ -0,0 +1,4 @@
+import SwiftUI
+import ExampleSupport
+
+@main struct DemoApp: ExampleApp {}
diff --git a/Examples/DemoExtensions/Sources/DemoExtensionsWidget/Widget.swift b/Examples/DemoExtensions/Sources/DemoExtensionsWidget/Widget.swift
new file mode 100644
index 0000000..5a7233f
--- /dev/null
+++ b/Examples/DemoExtensions/Sources/DemoExtensionsWidget/Widget.swift
@@ -0,0 +1,51 @@
+import WidgetKit
+import SwiftUI
+
+@main struct Bundle: WidgetBundle {
+ var body: some Widget {
+ DemoWidget()
+ }
+}
+
+struct DemoWidget: Widget {
+ var body: some WidgetConfiguration {
+ StaticConfiguration(
+ kind: "DemoWidget",
+ provider: Provider()
+ ) { entry in
+ VStack {
+ Text(entry.date, style: .date)
+ }
+ .containerBackground(.fill.tertiary, for: .widget)
+ }
+ .configurationDisplayName("DemoWidget")
+ .description("This is an example widget.")
+ }
+
+ struct Entry: TimelineEntry {
+ var date = Date()
+ }
+
+ struct Provider: TimelineProvider {
+ func placeholder(in context: Context) -> Entry {
+ Entry()
+ }
+
+ func getSnapshot(
+ in context: Context,
+ completion: @escaping (Entry) -> Void
+ ) {
+ completion(Entry())
+ }
+
+ func getTimeline(
+ in context: Context,
+ completion: @escaping (Timeline<Entry>) -> Void
+ ) {
+ completion(Timeline(
+ entries: [Entry()],
+ policy: .after(.now + 3600)
+ ))
+ }
+ }
+}
diff --git a/Examples/DemoExtensions/Support/DemoExtensionsWidget-Info.plist b/Examples/DemoExtensions/Support/DemoExtensionsWidget-Info.plist
new file mode 100644
index 0000000..0f118fb
--- /dev/null
+++ b/Examples/DemoExtensions/Support/DemoExtensionsWidget-Info.plist
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>NSExtension</key>
+ <dict>
+ <key>NSExtensionPointIdentifier</key>
+ <string>com.apple.widgetkit-extension</string>
+ </dict>
+</dict>
+</plist>
diff --git a/Examples/DemoExtensions/xtool.yml b/Examples/DemoExtensions/xtool.yml
new file mode 100644
index 0000000..8a641a5
--- /dev/null
+++ b/Examples/DemoExtensions/xtool.yml
@@ -0,0 +1,6 @@
+version: 1
+bundleID: sh.xtool.examples.DemoExtensions
+product: DemoExtensions
+extensions:
+- product: DemoExtensionsWidget
+ infoPath: Support/DemoExtensionsWidget-Info.plist
diff --git a/Examples/DemoResources/Package.swift b/Examples/DemoResources/Package.swift
new file mode 100644
index 0000000..b927075
--- /dev/null
+++ b/Examples/DemoResources/Package.swift
@@ -0,0 +1,31 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoResources",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoResources",
+ targets: ["DemoResources"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ ],
+ targets: [
+ .target(
+ name: "DemoResources",
+ dependencies: [
+ "ExampleSupport",
+ ],
+ resources: [
+ .process("bundled.txt"),
+ ]
+ ),
+ ]
+)
diff --git a/Examples/DemoResources/Resources/top.txt b/Examples/DemoResources/Resources/top.txt
new file mode 100644
index 0000000..07dcd7e
--- /dev/null
+++ b/Examples/DemoResources/Resources/top.txt
@@ -0,0 +1 @@
+Top level resource
diff --git a/Examples/DemoResources/Sources/DemoResources/App.swift b/Examples/DemoResources/Sources/DemoResources/App.swift
new file mode 100644
index 0000000..89ac6b5
--- /dev/null
+++ b/Examples/DemoResources/Sources/DemoResources/App.swift
@@ -0,0 +1,34 @@
+import ExampleSupport
+import SwiftUI
+
+@main struct DemoApp: App {
+ var body: some Scene {
+ WindowGroup {
+ Text("Hello, world!")
+ .task {
+ guard let bundled = #bundle.url(forResource: "bundled", withExtension: "txt")
+ else { fatalError("Missing bundled.txt resource") }
+ assertContents(of: bundled, equal: "Bundled resource\n")
+
+ guard let top = Bundle.main.url(forResource: "top", withExtension: "txt")
+ else { fatalError("Missing top.txt resource") }
+ assertContents(of: top, equal: "Top level resource\n")
+
+ Example.pass()
+ }
+ }
+ }
+}
+
+private func assertContents(of url: URL, equal value: String) {
+ let name = url.lastPathComponent
+ let contents: String
+ do {
+ contents = try String(contentsOf: url, encoding: .utf8)
+ } catch {
+ fatalError("Failed to read \(name): \(error)")
+ }
+ guard contents == value else {
+ fatalError("\(name) had unexpected contents: \(contents)")
+ }
+}
diff --git a/Examples/DemoResources/Sources/DemoResources/bundled.txt b/Examples/DemoResources/Sources/DemoResources/bundled.txt
new file mode 100644
index 0000000..0212139
--- /dev/null
+++ b/Examples/DemoResources/Sources/DemoResources/bundled.txt
@@ -0,0 +1 @@
+Bundled resource
diff --git a/Examples/DemoResources/xtool.yml b/Examples/DemoResources/xtool.yml
new file mode 100644
index 0000000..c63c669
--- /dev/null
+++ b/Examples/DemoResources/xtool.yml
@@ -0,0 +1,4 @@
+version: 1
+bundleID: sh.xtool.examples.DemoResources
+resources:
+- Resources/top.txt
diff --git a/Examples/DemoSimple/Package.swift b/Examples/DemoSimple/Package.swift
new file mode 100644
index 0000000..961e79d
--- /dev/null
+++ b/Examples/DemoSimple/Package.swift
@@ -0,0 +1,28 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoSimple",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoSimple",
+ targets: ["DemoSimple"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ ],
+ targets: [
+ .target(
+ name: "DemoSimple",
+ dependencies: [
+ "ExampleSupport",
+ ]
+ ),
+ ]
+)
diff --git a/Examples/DemoSimple/Sources/DemoSimple/App.swift b/Examples/DemoSimple/Sources/DemoSimple/App.swift
new file mode 100644
index 0000000..1ecb12c
--- /dev/null
+++ b/Examples/DemoSimple/Sources/DemoSimple/App.swift
@@ -0,0 +1,4 @@
+import ExampleSupport
+import SwiftUI
+
+@main struct DemoApp: ExampleApp {}
diff --git a/Examples/DemoSimple/xtool.yml b/Examples/DemoSimple/xtool.yml
new file mode 100644
index 0000000..815fcc3
--- /dev/null
+++ b/Examples/DemoSimple/xtool.yml
@@ -0,0 +1,2 @@
+version: 1
+bundleID: sh.xtool.examples.DemoSimple
diff --git a/Examples/DemoTCA/Package.resolved b/Examples/DemoTCA/Package.resolved
new file mode 100644
index 0000000..5363383
--- /dev/null
+++ b/Examples/DemoTCA/Package.resolved
@@ -0,0 +1,132 @@
+{
+ "originHash" : "4a80ae2e9e4c4e1e4e29c32e93dc624202a42a942e44d358035684ec5e0746f7",
+ "pins" : [
+ {
+ "identity" : "combine-schedulers",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/combine-schedulers",
+ "state" : {
+ "revision" : "114354e8c1667a2edc4993700fb9fa4f90157b56",
+ "version" : "1.2.2"
+ }
+ },
+ {
+ "identity" : "swift-case-paths",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-case-paths",
+ "state" : {
+ "revision" : "cb4cba6a8a46a86db0d37dbe09935ead6b24c91a",
+ "version" : "1.10.0"
+ }
+ },
+ {
+ "identity" : "swift-clocks",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-clocks",
+ "state" : {
+ "revision" : "82440fa0a8b1c381a6d1e8e0fc7bbba53ec63204",
+ "version" : "1.1.1"
+ }
+ },
+ {
+ "identity" : "swift-collections",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/apple/swift-collections",
+ "state" : {
+ "revision" : "98ef3c98609a1e31b7e157b5b619579001a789d6",
+ "version" : "1.7.1"
+ }
+ },
+ {
+ "identity" : "swift-composable-architecture",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-composable-architecture.git",
+ "state" : {
+ "revision" : "377da4061db10d26337a71bb279c506bb951f50f",
+ "version" : "1.26.2"
+ }
+ },
+ {
+ "identity" : "swift-concurrency-extras",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-concurrency-extras",
+ "state" : {
+ "revision" : "5fa253428866f2360c3754e88537f700ed2656b5",
+ "version" : "1.4.1"
+ }
+ },
+ {
+ "identity" : "swift-custom-dump",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-custom-dump",
+ "state" : {
+ "revision" : "4fb9e7cbb4b8f5a7354005db39447f570d6b3e19",
+ "version" : "1.7.3"
+ }
+ },
+ {
+ "identity" : "swift-dependencies",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-dependencies",
+ "state" : {
+ "revision" : "b476cc5761057d8d857de063fe7ac8daecf5c06b",
+ "version" : "1.17.1"
+ }
+ },
+ {
+ "identity" : "swift-identified-collections",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-identified-collections",
+ "state" : {
+ "revision" : "322d9ffeeba85c9f7c4984b39422ec7cc3c56597",
+ "version" : "1.1.1"
+ }
+ },
+ {
+ "identity" : "swift-issue-reporting",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-issue-reporting",
+ "state" : {
+ "revision" : "75b000cea2ca6d7527a57e1b9cc0bdf21a9abe9f",
+ "version" : "2.1.1"
+ }
+ },
+ {
+ "identity" : "swift-navigation",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-navigation",
+ "state" : {
+ "revision" : "7e95e5e9ff0a64f6ad8bca59083f8d6ba381b6ff",
+ "version" : "2.11.2"
+ }
+ },
+ {
+ "identity" : "swift-perception",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-perception",
+ "state" : {
+ "revision" : "597afd46249f4a71885b95d26b26cc5b893daf32",
+ "version" : "2.0.12"
+ }
+ },
+ {
+ "identity" : "swift-sharing",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-sharing",
+ "state" : {
+ "revision" : "3552faf8a6c18ce896ec5a72bd8c34755f0f03e0",
+ "version" : "2.10.1"
+ }
+ },
+ {
+ "identity" : "swift-syntax",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/swiftlang/swift-syntax",
+ "state" : {
+ "revision" : "050f1a346fbbac0ca2cfb15a95274f7bd1cf0ccf",
+ "version" : "604.0.0"
+ }
+ }
+ ],
+ "version" : 3
+}
diff --git a/Examples/DemoTCA/Package.swift b/Examples/DemoTCA/Package.swift
new file mode 100644
index 0000000..cef2c3c
--- /dev/null
+++ b/Examples/DemoTCA/Package.swift
@@ -0,0 +1,30 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoTCA",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoTCA",
+ targets: ["DemoTCA"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ .package(url: "https://github.com/pointfreeco/swift-composable-architecture.git", from: "1.0.0"),
+ ],
+ targets: [
+ .target(
+ name: "DemoTCA",
+ dependencies: [
+ "ExampleSupport",
+ .product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
+ ],
+ ),
+ ]
+)
diff --git a/Examples/DemoTCA/Sources/DemoTCA/ContentView.swift b/Examples/DemoTCA/Sources/DemoTCA/ContentView.swift
new file mode 100644
index 0000000..ef44c9d
--- /dev/null
+++ b/Examples/DemoTCA/Sources/DemoTCA/ContentView.swift
@@ -0,0 +1,24 @@
+import SwiftUI
+import ComposableArchitecture
+import ExampleSupport
+
+struct ContentView: View {
+ let store: StoreOf<CounterFeature>
+
+ var body: some View {
+ VStack {
+ Image(systemName: "globe")
+ .imageScale(.large)
+ .foregroundStyle(.tint)
+ Text("Count: \(store.count)")
+ }
+ .padding()
+ .onAppear {
+ store.send(.appear)
+ }
+ .onChange(of: store.count) { _, count in
+ guard count == 1 else { return }
+ Example.pass()
+ }
+ }
+}
diff --git a/Examples/DemoTCA/Sources/DemoTCA/CounterFeature.swift b/Examples/DemoTCA/Sources/DemoTCA/CounterFeature.swift
new file mode 100644
index 0000000..fb1d06d
--- /dev/null
+++ b/Examples/DemoTCA/Sources/DemoTCA/CounterFeature.swift
@@ -0,0 +1,31 @@
+import ComposableArchitecture
+
+@Reducer
+struct CounterFeature {
+ @ObservableState
+ struct State {
+ var count = 0
+ }
+
+ enum Action {
+ case appear
+ case timerElapsed
+ }
+
+ @Dependency(\.continuousClock) var continuousClock
+
+ var body: some Reducer<State, Action> {
+ Reduce { state, action in
+ switch action {
+ case .appear:
+ return .run { [continuousClock] send in
+ try await continuousClock.sleep(for: .seconds(1))
+ await send(.timerElapsed)
+ }
+ case .timerElapsed:
+ state.count += 1
+ return .none
+ }
+ }
+ }
+}
diff --git a/Examples/DemoTCA/Sources/DemoTCA/DemoTCAApp.swift b/Examples/DemoTCA/Sources/DemoTCA/DemoTCAApp.swift
new file mode 100644
index 0000000..ed1ab9e
--- /dev/null
+++ b/Examples/DemoTCA/Sources/DemoTCA/DemoTCAApp.swift
@@ -0,0 +1,15 @@
+import SwiftUI
+import ComposableArchitecture
+
+@main
+struct DemoTCAApp: App {
+ private let store = Store(initialState: CounterFeature.State()) {
+ CounterFeature()
+ }
+
+ var body: some Scene {
+ WindowGroup {
+ ContentView(store: store)
+ }
+ }
+}
diff --git a/Examples/DemoTCA/xtool.yml b/Examples/DemoTCA/xtool.yml
new file mode 100644
index 0000000..5662c54
--- /dev/null
+++ b/Examples/DemoTCA/xtool.yml
@@ -0,0 +1,2 @@
+version: 1
+bundleID: sh.xtool.examples.DemoTCA
diff --git a/Examples/ExampleSupport/Package.swift b/Examples/ExampleSupport/Package.swift
new file mode 100644
index 0000000..a998d78
--- /dev/null
+++ b/Examples/ExampleSupport/Package.swift
@@ -0,0 +1,31 @@
+// swift-tools-version: 6.4
+
+import PackageDescription
+
+let package = Package(
+ name: "ExampleSupport",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "ExampleSupport",
+ targets: ["ExampleSupport"]
+ ),
+ .library(
+ name: "ExampleDynamicLibrary",
+ type: .dynamic,
+ targets: ["ExampleDynamicLibrary"]
+ ),
+ ],
+ targets: [
+ .target(name: "ExampleSupport"),
+ .target(
+ name: "ExampleDynamicLibrary",
+ resources: [
+ .process("response.txt"),
+ ]
+ ),
+ ]
+)
diff --git a/Examples/ExampleSupport/Sources/ExampleDynamicLibrary/ExampleDynamicLibrary.swift b/Examples/ExampleSupport/Sources/ExampleDynamicLibrary/ExampleDynamicLibrary.swift
new file mode 100644
index 0000000..449addd
--- /dev/null
+++ b/Examples/ExampleSupport/Sources/ExampleDynamicLibrary/ExampleDynamicLibrary.swift
@@ -0,0 +1,9 @@
+import Foundation
+
+public func exampleDynamicLibraryFunction() -> String {
+ guard let bundled = #bundle.url(forResource: "response", withExtension: "txt")
+ else { fatalError("Missing bundled.txt resource") }
+ // swiftlint:disable:next force_try
+ let contents = try! String(contentsOf: bundled, encoding: .utf8)
+ return "Hello \(contents)"
+}
diff --git a/Examples/ExampleSupport/Sources/ExampleDynamicLibrary/response.txt b/Examples/ExampleSupport/Sources/ExampleDynamicLibrary/response.txt
new file mode 100644
index 0000000..d258eaa
--- /dev/null
+++ b/Examples/ExampleSupport/Sources/ExampleDynamicLibrary/response.txt
@@ -0,0 +1 @@
+from the dynamic library
diff --git a/Examples/ExampleSupport/Sources/ExampleSupport/ExampleApp.swift b/Examples/ExampleSupport/Sources/ExampleSupport/ExampleApp.swift
new file mode 100644
index 0000000..edef3ea
--- /dev/null
+++ b/Examples/ExampleSupport/Sources/ExampleSupport/ExampleApp.swift
@@ -0,0 +1,25 @@
+import SwiftUI
+
+public protocol ExampleApp: App {}
+extension ExampleApp {
+ public var body: some Scene {
+ WindowGroup {
+ ContentView()
+ }
+ }
+}
+
+private struct ContentView: View {
+ var body: some View {
+ VStack {
+ Image(systemName: "globe")
+ .imageScale(.large)
+ .foregroundStyle(.tint)
+ Text("Hello, world!")
+ }
+ .padding()
+ .task {
+ Example.pass()
+ }
+ }
+}
diff --git a/Examples/ExampleSupport/Sources/ExampleSupport/ExampleSupport.swift b/Examples/ExampleSupport/Sources/ExampleSupport/ExampleSupport.swift
new file mode 100644
index 0000000..dae8aa2
--- /dev/null
+++ b/Examples/ExampleSupport/Sources/ExampleSupport/ExampleSupport.swift
@@ -0,0 +1,12 @@
+import Foundation
+
+public enum Example {}
+extension Example {
+ public static func pass() {
+ Task {
+ try? await Task.sleep(for: .seconds(1))
+ print("xtool test succeeded")
+ exit(0)
+ }
+ }
+}
diff --git a/Examples/README.md b/Examples/README.md
new file mode 100644
index 0000000..7507d5d
--- /dev/null
+++ b/Examples/README.md
@@ -0,0 +1,14 @@
+# Examples
+
+These primarily exist as fixtures for integration tests, but also double as snippets of sample code.
+
+Each demo is designed to make some assertions shortly after launching, and then exit. On success, stdout will include the message "xtool test succeeded".
+
+## Testing
+
+```
+./Examples/test.sh [--build | --run] [DemoName]
+```
+
+- Omit `--build`/`--run` to build _and_ run
+- Omit the demo name to loop through all demos
diff --git a/Examples/test.sh b/Examples/test.sh
new file mode 100755
index 0000000..453444a
--- /dev/null
+++ b/Examples/test.sh
@@ -0,0 +1,118 @@
+#!/bin/bash
+
+set -euo pipefail
+shopt -s nullglob
+
+usage() {
+ echo "Usage: $0 [--build | --run] [DemoName]"
+}
+
+mode=both
+case "${1:-}" in
+ --build) mode=build; shift ;;
+ --run) mode=run; shift ;;
+ -h|--help) usage; exit 0 ;;
+esac
+
+if [[ $# -gt 1 || (${1:-} != "" && (${1:-} != Demo* || ${1:-} == */*)) ]]; then
+ usage >&2
+ exit 1
+fi
+
+cd "$(dirname "$0")"
+examples_dir="$PWD"
+out_dir="$examples_dir/out"
+
+if [[ -n "${1:-}" ]]; then
+ demos=("$1")
+elif [[ "$mode" == run ]]; then
+ demos=()
+ for app in "$out_dir"/*.app; do
+ name="${app##*/}"
+ demos+=("${name%.app}")
+ done
+else
+ demos=()
+ for demo in "$examples_dir"/Demo*/; do
+ [[ -f "$demo/Package.swift" ]] || continue
+ demo="${demo%/}"
+ demos+=("${demo##*/}")
+ done
+fi
+
+if [[ ${#demos[@]} -eq 0 ]]; then
+ echo "No demos found. Run $0 --build first if using --run." >&2
+ exit 1
+fi
+
+logs_dir="$(mktemp -d)"
+trap 'rm -rf "$logs_dir"' EXIT
+trap 'exit 130' INT
+trap 'exit 143' TERM
+
+build_demo() {
+ local demo="$1"
+ echo "Building $demo..."
+ mkdir -p "$out_dir" || return 1
+ # Do not leave an older successful build available after a failed rebuild.
+ rm -rf "$out_dir/$demo.app" || return 1
+ (cd "$examples_dir/$demo" && xtool dev build --triple arm64-apple-ios-simulator) || return 1
+ cp -R "$examples_dir/$demo/xtool/$demo.app" "$out_dir/$demo.app"
+}
+
+run_demo() (
+ demo="$1"
+ app="$out_dir/$demo.app"
+ log="$logs_dir/$demo-run.log"
+ if [[ ! -d "$app" ]]; then
+ echo "Missing $app. Run $0 --build $demo first." >&2
+ exit 1
+ fi
+ bundle_id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$app/Info.plist") || exit 1
+ echo "Running $demo..."
+ xcrun simctl install booted "$app" || exit 1
+ xcrun simctl launch --terminate-running-process --console booted "$bundle_id" >"$log" 2>&1 &
+ launch_pid=$!
+ # A demo should exit shortly after launch. Bound failures that hang instead.
+ (
+ sleep_pid=""
+ trap '[[ -z "$sleep_pid" ]] || kill "$sleep_pid" 2>/dev/null || true' EXIT
+ sleep 60 &
+ sleep_pid=$!
+ wait "$sleep_pid"
+ sleep_pid=""
+ touch "$log.timeout"
+ kill -TERM "$launch_pid" 2>/dev/null || exit 0
+ sleep 5 &
+ sleep_pid=$!
+ wait "$sleep_pid"
+ sleep_pid=""
+ kill -KILL "$launch_pid" 2>/dev/null || true
+ ) >/dev/null 2>&1 &
+ timeout_pid=$!
+ trap 'kill "$timeout_pid" "$launch_pid" 2>/dev/null || true' EXIT
+ status=0
+ wait "$launch_pid" || status=$?
+ kill "$timeout_pid" 2>/dev/null || true
+ wait "$timeout_pid" 2>/dev/null || true
+ cat "$log"
+ if [[ -f "$log.timeout" ]]; then
+ echo "$demo did not terminate within 60 seconds." >&2
+ exit 1
+ fi
+ [[ "$status" -eq 0 ]] && grep -Fxq 'xtool test succeeded' "$log"
+)
+
+status=0
+for demo in "${demos[@]}"; do
+ if [[ "$mode" != run ]] && ! build_demo "$demo"; then
+ echo "Build failed: $demo" >&2
+ status=1
+ continue
+ fi
+ if [[ "$mode" != build ]] && ! run_demo "$demo"; then
+ echo "Test failed: $demo" >&2
+ status=1
+ fi
+done
+exit "$status"