Skip to content

Commit 4b483f2

Browse files
authored
Run tests on either macOS 12 or macOS 13 (#5089)
In preparation for migrating our fleet to macOS 13, we're updating tests to run on either macOS 12 or macOS 13.
1 parent 158ec1f commit 4b483f2

File tree

5 files changed

+80
-5
lines changed

5 files changed

+80
-5
lines changed

.ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ platform_properties:
6464
[
6565
{"dependency": "gems", "version": "v3.3.14"}
6666
]
67-
os: Mac-12
67+
os: "Mac-12|Mac-13"
6868
device_type: none
6969
cpu: arm64
7070
$flutter/osx_sdk : >-
@@ -77,7 +77,7 @@ platform_properties:
7777
[
7878
{"dependency": "gems", "version": "v3.3.14"}
7979
]
80-
os: Mac-12
80+
os: "Mac-12|Mac-13"
8181
device_type: none
8282
cpu: x86
8383
$flutter/osx_sdk : >-

.ci/scripts/boot_simulator.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
set -e
6+
7+
# The name here must match create_simulator.sh
8+
readonly DEVICE_NAME=Flutter-iPhone
9+
10+
# Allow boot to fail; cases like "Unable to boot device in current state: Booted"
11+
# exit with failure.
12+
xcrun simctl boot "$DEVICE_NAME" || :
13+
echo -e ""
14+
xcrun simctl list

.ci/scripts/create_simulator.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,18 @@ readonly DEVICE_NAME=Flutter-iPhone
1111
readonly DEVICE=com.apple.CoreSimulator.SimDeviceType.iPhone-14
1212
readonly OS=com.apple.CoreSimulator.SimRuntime.iOS-16-4
1313

14-
xcrun simctl list
14+
# Delete any existing devices named Flutter-iPhone. Having more than one may
15+
# cause issues when builds target the device.
16+
echo -e "Deleting any existing devices names $DEVICE_NAME..."
17+
RESULT=0
18+
while [[ $RESULT == 0 ]]; do
19+
xcrun simctl delete "$DEVICE_NAME" || RESULT=1
20+
if [ $RESULT == 0 ]; then
21+
echo -e "Deleted $DEVICE_NAME"
22+
fi
23+
done
24+
echo -e ""
25+
26+
echo -e "\nCreating $DEVICE_NAME $DEVICE $OS ...\n"
1527
xcrun simctl create "$DEVICE_NAME" "$DEVICE" "$OS" | xargs xcrun simctl boot
28+
xcrun simctl list

.ci/targets/ios_platform_tests.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ tasks:
2121
args: ["xcode-analyze", "--ios", "--ios-min-version=13.0"]
2222
- name: native test
2323
script: script/tool_runner.sh
24-
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=iPhone 14,OS=latest"]
24+
# Simulator name must match name in create_simulator.sh
25+
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=16.4"]
26+
- name: boot simulator
27+
# Ensure simulator is still booted
28+
script: .ci/scripts/boot_simulator.sh
29+
infra_step: true # Note infra steps failing prevents "always" from running.
2530
- name: drive examples
2631
# `drive-examples` contains integration tests, which changes the UI of the application.
2732
# This UI change sometimes affects `xctest`.

packages/pigeon/tool/shared/test_suites.dart

+44-1
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,54 @@ Future<int> _runIOSPluginUnitTests(String testPluginPath) async {
294294
return compileCode;
295295
}
296296

297+
const String deviceName = 'Pigeon-Test-iPhone';
298+
const String deviceType = 'com.apple.CoreSimulator.SimDeviceType.iPhone-14';
299+
const String deviceRuntime = 'com.apple.CoreSimulator.SimRuntime.iOS-16-4';
300+
const String deviceOS = '16.4';
301+
await _createSimulator(deviceName, deviceType, deviceRuntime);
297302
return runXcodeBuild(
298303
'$examplePath/ios',
299304
sdk: 'iphonesimulator',
300-
destination: 'platform=iOS Simulator,name=iPhone 14',
305+
destination: 'platform=iOS Simulator,name=$deviceName,OS=$deviceOS',
301306
extraArguments: <String>['test'],
307+
).whenComplete(() => _deleteSimulator(deviceName));
308+
}
309+
310+
Future<int> _createSimulator(
311+
String deviceName,
312+
String deviceType,
313+
String deviceRuntime,
314+
) async {
315+
// Delete any existing simulators with the same name until it fails. It will
316+
// fail once there are no simulators with the name. Having more than one may
317+
// cause issues when builds target the device.
318+
int deleteResult = 0;
319+
while (deleteResult == 0) {
320+
deleteResult = await _deleteSimulator(deviceName);
321+
}
322+
return runProcess(
323+
'xcrun',
324+
<String>[
325+
'simctl',
326+
'create',
327+
deviceName,
328+
deviceType,
329+
deviceRuntime,
330+
],
331+
streamOutput: false,
332+
logFailure: true,
333+
);
334+
}
335+
336+
Future<int> _deleteSimulator(String deviceName) async {
337+
return runProcess(
338+
'xcrun',
339+
<String>[
340+
'simctl',
341+
'delete',
342+
deviceName,
343+
],
344+
streamOutput: false,
302345
);
303346
}
304347

0 commit comments

Comments
 (0)