Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specific simulator IDs for iOS tests #648

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apple/testing/default_runner/ios_test_runner.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""iOS test runner rule."""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"@build_bazel_rules_apple//apple/testing:apple_test_rules.bzl",
"AppleTestRunnerInfo",
Expand All @@ -26,6 +27,7 @@ def _get_template_substitutions(ctx):
subs = {
"device_type": device_type,
"os_version": str(os_version),
"simulator_id": ctx.attr.simulator_id[BuildSettingInfo].value if ctx.attr.simulator_id else "",
"testrunner_binary": ctx.executable._testrunner.short_path,
}
return {"%(" + k + ")s": subs[k] for k in subs}
Expand Down Expand Up @@ -84,6 +86,14 @@ the runner. In most common cases, this should not be used.
The os version of the iOS simulator to run test. The supported os versions
correspond to the output of `xcrun simctl list runtimes`. ' 'E.g., 11.2, 9.3.
By default, it is the latest supported version of the device type.'
""",
),
"simulator_id": attr.label(
default = None,
providers = [BuildSettingInfo],
doc = """
The specific UDID for the simulator to be used. In this case the caller is
responsible for making sure this simulator exists and is booted
""",
),
"_test_template": attr.label(
Expand Down
20 changes: 17 additions & 3 deletions apple/testing/default_runner/ios_test_runner.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,25 @@ if [[ -n "${LAUNCH_OPTIONS_JSON_STR}" ]]; then
runner_flags+=("--launch_options_json_path=${LAUNCH_OPTIONS_JSON_PATH}")
fi

simulator_id="%(simulator_id)s"
target_flags=()
if [[ -n "$simulator_id" ]]; then
target_flags=(
"test"
"--id=$simulator_id"
)
else
target_flags=(
"simulator_test"
"--device_type=%(device_type)s"
"--os_version=%(os_version)s"
)
fi

set -x
cmd=("%(testrunner_binary)s"
"${runner_flags[@]}"
simulator_test
"--device_type=%(device_type)s"
"--os_version=%(os_version)s"
"${target_flags[@]}"
"$@")
"${cmd[@]}" 2>&1
status=$?
Expand Down