Skip to content

Commit

Permalink
Create iOS simulator before running IosUnitTests (flutter#33906)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman authored Jun 9, 2022
1 parent c489c4c commit 5d89a6c
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions testing/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,25 +605,53 @@ def RunObjcTests(ios_variant='ios_debug_sim_unopt', test_filter=None):
ios_out_dir = os.path.join(out_dir, ios_variant)
EnsureIosTestsAreBuilt(ios_out_dir)

ios_unit_test_dir = os.path.join(
buildroot_dir, 'flutter', 'testing', 'ios', 'IosUnitTests'
)
new_simulator_name = 'IosUnitTestsSimulator'

# Avoid using xcpretty unless the following can be addressed:
# - Make sure all relevant failure output is printed on a failure.
# - Make sure that a failing exit code is set for CI.
# See https://github.com/flutter/flutter/issues/63742
command = [
'xcodebuild '
'-sdk iphonesimulator '
'-scheme IosUnitTests '
"-destination platform='iOS Simulator,name=iPhone 11' "
'test '
'FLUTTER_ENGINE=' + ios_variant
# Delete simulators with this name in case any were leaked
# from another test run.
DeleteSimulator(new_simulator_name)

create_simulator = [
'xcrun '
'simctl '
'create '
'%s com.apple.CoreSimulator.SimDeviceType.iPhone-11' % new_simulator_name
]
RunCmd(create_simulator, shell=True)

try:
ios_unit_test_dir = os.path.join(
buildroot_dir, 'flutter', 'testing', 'ios', 'IosUnitTests'
)
# Avoid using xcpretty unless the following can be addressed:
# - Make sure all relevant failure output is printed on a failure.
# - Make sure that a failing exit code is set for CI.
# See https://github.com/flutter/flutter/issues/63742
test_command = [
'xcodebuild '
'-sdk iphonesimulator '
'-scheme IosUnitTests '
"-destination name='" + new_simulator_name + "' "
'test '
'FLUTTER_ENGINE=' + ios_variant
]
if test_filter != None:
test_command[0] = test_command[0] + " -only-testing:%s" % test_filter
RunCmd(test_command, cwd=ios_unit_test_dir, shell=True)
finally:
DeleteSimulator(new_simulator_name)


def DeleteSimulator(simulator_name):
# Will delete all simulators with this name.
delete_simulator = [
'xcrun',
'simctl',
'delete',
simulator_name,
]
if test_filter != None:
command[0] = command[0] + " -only-testing:%s" % test_filter
RunCmd(command, cwd=ios_unit_test_dir, shell=True)
# Let this fail if the simulator was never created.
RunCmd(delete_simulator, expect_failure=True)


def GatherDartTests(build_dir, filter, verbose_dart_snapshot):
Expand Down

0 comments on commit 5d89a6c

Please sign in to comment.