-
-
Notifications
You must be signed in to change notification settings - Fork 601
/
test
executable file
·274 lines (238 loc) · 13.4 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
GREEN="\033[0;32m"
CLEAR="\033[0m"
if which xcodebuild > /dev/null; then
echo -e "Gathering ${GREEN}xcodebuild sdk versions${CLEAR}..."
BUILD_DIR=`pwd`/build
LATEST_IOS_SDK_VERSION=`xcodebuild -showsdks | grep iphonesimulator | cut -d ' ' -f 4 | ruby -e 'puts STDIN.read.chomp.split("\n").last'`
LATEST_IOS_VERSION=`xcrun simctl list | grep ^iOS | ruby -e 'puts /\(([0-9.]+).*\)/.match(STDIN.read.chomp.split("\n").last).to_a[1]'`
LATEST_TVOS_SDK_VERSION=`xcodebuild -showsdks | grep appletvsimulator | cut -d ' ' -f 4 | ruby -e 'puts STDIN.read.chomp.split("\n").last'`
LATEST_TVOS_VERSION=`xcrun simctl list | grep ^tvOS | ruby -e 'puts /\(([0-9.]+).*\)/.match(STDIN.read.chomp.split("\n").last).to_a[1]'`
LATEST_WATCHOS_SDK_VERSION=`xcodebuild -showsdks | grep -e '-sdk watchos' | cut -d ' ' -f 2 | ruby -e 'puts STDIN.read.chomp.split("\n").last'`
LATEST_WATCHOS_VERSION=`xcrun simctl list | grep ^watchOS | ruby -e 'puts /\(([0-9.]+).*\)/.match(STDIN.read.chomp.split("\n").last).to_a[1]'`
LATEST_MACOS_SDK_VERSION=`xcodebuild -showsdks | grep -e '-sdk macosx' | cut -d ' ' -f 2 | ruby -e 'puts STDIN.read.chomp.split("\n").last'`
LATEST_VISIONOS_SDK_VERSION=`xcodebuild -showsdks | grep -e '-sdk xros' | cut -d ' ' -f 2 | ruby -e 'puts STDIN.read.chomp.split("\n").last'`
LATEST_VISIONOS_VERSION=`xcrun simctl list | grep ^visionOS | ruby -e 'puts /\(([0-9.]+).*\)/.match(STDIN.read.chomp.split("\n").last).to_a[1]'`
BUILD_IOS_SDK_VERSION=${NIMBLE_BUILD_IOS_SDK_VERSION:-$LATEST_IOS_SDK_VERSION}
RUNTIME_IOS_VERSION=${NIMBLE_RUNTIME_IOS_VERSION:-$LATEST_IOS_VERSION}
BUILD_TVOS_SDK_VERSION=${NIMBLE_BUILD_TVOS_SDK_VERSION:-$LATEST_TVOS_SDK_VERSION}
RUNTIME_TVOS_VERSION=${NIMBLE_RUNTIME_TVOS_VERSION:-$LATEST_TVOS_VERSION}
BUILD_WATCHOS_SDK_VERSION=${NIMBLE_BUILD_WATCHOS_SDK_VERSION:-$LATEST_WATCHOS_SDK_VERSION}
RUNTIME_WATCHOS_VERSION=${NIMBLE_RUNTIME_WATCHOS_VERSION:-$LATEST_WATCHOS_VERSION}
BUILD_MACOS_SDK_VERSION=${NIMBLE_BUILD_MACOS_SDK_VERSION:-$LATEST_MACOS_SDK_VERSION}
BUILD_VISIONOS_SDK_VERSION=${NIMBLE_BUILD_VISIONOS_SDK_VERSION:-$LATEST_VISIONOS_SDK_VERSION}
RUNTIME_VISIONOS_VERSION=${NIMBLE_RUNTIME_VISIONOS_VERSION:-$LATEST_VISIONOS_VERSION}
fi
set -e
function color_if_overridden {
local actual=$1
local env_var=$2
if [ -z "$env_var" ]; then
printf "$actual"
else
printf "$GREEN$actual$CLEAR"
fi
}
function print_env {
echo "=== Environment ==="
echo " iOS:"
echo " Latest iOS SDK: $LATEST_IOS_SDK_VERSION"
echo " Building with iOS SDK: `color_if_overridden $BUILD_IOS_SDK_VERSION $NIMBLE_BUILD_IOS_SDK_VERSION`"
echo " Running with iOS: `color_if_overridden $RUNTIME_IOS_VERSION $NIMBLE_RUNTIME_IOS_VERSION`"
echo
echo " tvOS:"
echo " Latest tvOS SDK: $LATEST_TVOS_SDK_VERSION"
echo " Building with tvOS SDK: `color_if_overridden $BUILD_TVOS_SDK_VERSION $NIMBLE_BUILD_TVOS_SDK_VERSION`"
echo " Running with tvOS: `color_if_overridden $RUNTIME_TVOS_VERSION $NIMBLE_RUNTIME_TVOS_VERSION`"
echo
echo " watchOS:"
echo " Latest watchOS SDK: $LATEST_WATCHOS_SDK_VERSION"
echo " Building with watchOS SDK: `color_if_overridden $BUILD_WATCHOS_SDK_VERSION $NIMBLE_BUILD_WATCHOS_SDK_VERSION`"
echo " Running with watchOS: `color_if_overridden $RUNTIME_WATCHOS_VERSION $NIMBLE_RUNTIME_WATCHOS_VERSION`"
echo
echo " visionOS:"
echo " Latest visionOS SDK: $LATEST_VISIONOS_SDK_VERSION"
echo " Building with visionOS SDK: `color_if_overridden $BUILD_VISIONOS_SDK_VERSION $NIMBLE_BUILD_VISIONOS_SDK_VERSION`"
echo " Running with visionOS: `color_if_overridden $RUNTIME_VISIONOS_VERSION $NIMBLE_RUNTIME_VISIONOS_VERSION`"
echo
echo " macOS:"
echo " Latest macOS SDK: $LATEST_MACOS_SDK_VERSION"
echo " Building with macOS SDK: `color_if_overridden $BUILD_MACOS_SDK_VERSION $NIMBLE_BUILD_MACOS_SDK_VERSION`"
echo
echo "======= END ======="
echo
}
function run {
echo -e "$GREEN==>$CLEAR $@"
"$@"
}
function test_ios {
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -destination "generic/platform=iOS" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build | xcpretty
run osascript -e 'tell app "Simulator" to quit'
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -sdk "iphonesimulator$BUILD_IOS_SDK_VERSION" -destination "name=iPhone SE (3rd generation),OS=$RUNTIME_IOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_tvos {
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -destination "generic/platform=tvOS" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build | xcpretty
run osascript -e 'tell app "Simulator" to quit'
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -sdk "appletvsimulator$BUILD_TVOS_SDK_VERSION" -destination "name=Apple TV,OS=$RUNTIME_TVOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_watchos {
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -destination "generic/platform=watchOS" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build | xcpretty
run osascript -e 'tell app "Simulator" to quit'
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -sdk "watchsimulator$BUILD_WATCHOS_SDK_VERSION" -destination "name=Apple Watch Series 6 (40mm),OS=$RUNTIME_WATCHOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_visionos {
if [[ -z $LATEST_VISIONOS_SDK_VERSION ]]; then
echo "visionOS is not supported on this machine"
return
fi
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -destination "generic/platform=visionOS" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build | xcpretty
run osascript -e 'tell app "Simulator" to quit'
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -sdk "xrsimulator$BUILD_VISIONOS_SDK_VERSION" -destination "name=Apple Vision Pro),OS=$RUNTIME_VISIONOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_macos {
run set -o pipefail && xcodebuild -project Nimble.xcodeproj -scheme "Nimble" -configuration "Debug" -sdk "macosx$BUILD_MACOS_SDK_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_xcode_spm_macos {
mv Nimble.xcodeproj Nimble.xcodeproj.bak
trap 'mv Nimble.xcodeproj.bak Nimble.xcodeproj' EXIT
run set -o pipefail && xcodebuild -scheme "Nimble" -configuration "Debug" -sdk "macosx$BUILD_MACOS_SDK_VERSION" -destination "platform=macOS" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_xcode_spm_ios {
run osascript -e 'tell app "Simulator" to quit'
mv Nimble.xcodeproj Nimble.xcodeproj.bak
trap 'mv Nimble.xcodeproj.bak Nimble.xcodeproj' EXIT
run set -o pipefail && xcodebuild -scheme "Nimble" -configuration "Debug" -sdk "iphonesimulator$BUILD_IOS_SDK_VERSION" -destination "name=iPhone SE (3rd generation),OS=$RUNTIME_IOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_xcode_spm_tvos {
run osascript -e 'tell app "Simulator" to quit'
mv Nimble.xcodeproj Nimble.xcodeproj.bak
trap 'mv Nimble.xcodeproj.bak Nimble.xcodeproj' EXIT
run set -o pipefail && xcodebuild -scheme "Nimble" -configuration "Debug" -sdk "appletvsimulator$BUILD_TVOS_SDK_VERSION" -destination "name=Apple TV,OS=$RUNTIME_TVOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_xcode_spm_watchos {
run osascript -e 'tell app "Simulator" to quit'
mv Nimble.xcodeproj Nimble.xcodeproj.bak
trap 'mv Nimble.xcodeproj.bak Nimble.xcodeproj' EXIT
run set -o pipefail && xcodebuild -scheme "Nimble" -configuration "Debug" -sdk "watchsimulator$BUILD_WATCHOS_SDK_VERSION" -destination "name=Apple Watch Series 6 (40mm),OS=$RUNTIME_WATCHOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_xcode_spm_visionos {
if [[ -z $LATEST_VISIONOS_SDK_VERSION ]]; then
echo "visionOS is not supported on this machine"
return
fi
run osascript -e 'tell app "Simulator" to quit'
mv Nimble.xcodeproj Nimble.xcodeproj.bak
trap 'mv Nimble.xcodeproj.bak Nimble.xcodeproj' EXIT
run set -o pipefail && xcodebuild -scheme "Nimble" -configuration "Debug" -sdk "xrsimulator$BUILD_WATCHOS_SDK_VERSION" -destination "name=Apple Vision Pro,OS=$RUNTIME_WATCHOS_VERSION" OTHER_SWIFT_FLAGS='$(inherited) -suppress-warnings' build-for-testing test-without-building | xcpretty
}
function test_podspec {
PLATFORMS="ios,tvos,watchos,macos"
if [[ ! -z $LATEST_VISIONOS_SDK_VERSION ]]; then
PLATFORMS="$PLATFORMS,visionos"
fi
echo "Gathering CocoaPods installation information..."
run bundle exec pod --version
echo "Linting podspec..."
run bundle exec pod lib lint Nimble.podspec --skip-import-validation --verbose --platforms=$PLATFORMS
}
function test_carthage {
echo "Gathering Carthage installation information..."
run carthage version
echo "Verifying that Carthage artifacts build"
run carthage build --no-skip-current --use-xcframeworks --verbose
}
function test_swiftpm {
if [ -d .build ]; then
run swift package clean
fi
run swift build -Xswiftc -suppress-warnings && swift test -Xswiftc -suppress-warnings --enable-test-discovery
}
function test_swiftpm_docker {
run docker build -t nimble-tests -f Dockerfile.test --no-cache .
run docker run -it --privileged=true nimble-tests
}
function test() {
test_macos
test_ios
test_tvos
test_watchos
test_visionos
if xcodebuild --help 2>&1 | grep xcframework > /dev/null; then
test_xcode_spm_macos
test_xcode_spm_ios
test_xcode_spm_tvos
test_xcode_spm_watchos
test_xcode_spm_visionos
else
echo "Not testing with Swift Package Manager version of Xcode because it requires at least Xcode 11"
fi
if which swift-test; then
test_swiftpm
else
echo "Not testing with the Swift Package Manager because swift-test is not installed"
fi
if which docker; then
test_swiftpm_docker
else
echo "Not testing linux in docker container since docker is not in PATH!"
fi
}
function clean {
run rm -rf ~/Library/Developer/Xcode/DerivedData\; true
}
function help {
echo "Usage: $0 COMMANDS"
echo
echo "COMMANDS:"
echo " all - Runs the all tests of macos, ios and tvos"
echo " clean - Cleans the derived data directory of Xcode. Assumes default location"
echo " help - Displays this help"
echo " macos - Runs the tests on macOS 10.10 (Yosemite and newer only)"
echo " macos_xcodespm - Runs the tests on macOS using the Swift Package Manager version of Xcode"
echo " ios - Runs the tests as an iOS device"
echo " ios_xcodespm - Runs the tests as an iOS device using the Swift Package Manager version of Xcode"
echo " tvos - Runs the tests as an tvOS device"
echo " tvos_xcodespm - Runs the tests as an tvOS device using the Swift Package Manager version of Xcode"
echo " watchos - Runs the tests as an watchOS device"
echo " watchos_xcodespm - Runs the tests as an watchOS device using the Swift Package Manager version of Xcode"
echo " visionos - Runs the tests as an visionOS device"
echo " visionos_xcodespm - Runs the tests as an visionOS device using the Swift Package Manager version of Xcode"
echo " podspec - Runs pod lib lint against the podspec to detect breaking changes"
echo " carthage - Runs verifyies that the carthage artifacts build"
echo " swiftpm - Runs the tests built by the Swift Package Manager"
echo " swiftpm_docker - Runs the tests built by the Swift Package Manager in a docker linux container"
echo
exit 1
}
function main {
print_env
for arg in $@
do
case "$arg" in
clean) clean ;;
ios) test_ios ;;
ios_xcodespm) test_xcode_spm_ios ;;
tvos) test_tvos ;;
tvos_xcodespm) test_xcode_spm_tvos ;;
watchos) test_watchos ;;
watchos_xcodespm) test_xcode_spm_watchos ;;
visionos) test_visionos ;;
visionos_xcodespm) test_xcode_spm_visionos ;;
macos) test_macos ;;
macos_xcodespm) test_xcode_spm_macos ;;
podspec) test_podspec ;;
carthage) test_carthage ;;
test) test ;;
all) test ;;
swiftpm) test_swiftpm ;;
swiftpm_docker) test_swiftpm_docker ;;
help) help ;;
esac
done
if [ $# -eq 0 ]; then
clean
test
fi
}
main $@