Skip to content

Commit

Permalink
Add test filter parameter to ios_unit_test (#1739)
Browse files Browse the repository at this point in the history
This is a port from this
[PR](#1616) to get into
the 5.x branch so we could use the ability to use the test filter
parameter

(cherry picked from commit 3d5944d)
  • Loading branch information
dostrander authored Oct 20, 2022
1 parent 201fcbe commit c17af58
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 11 deletions.
6 changes: 6 additions & 0 deletions apple/internal/rule_factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ AppleTestRunnerInfo provider.
"test_host": attr.label(
providers = [AppleBundleInfo],
),
"test_filter": attr.string(
doc = """
Test filter string that will be passed into the test runner to select which tests will run.
""",
default = "",
),
"_apple_coverage_support": attr.label(
cfg = "exec",
default = Label("@build_bazel_apple_support//tools:coverage_support"),
Expand Down
4 changes: 3 additions & 1 deletion apple/internal/testing/apple_test_rule_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ This aspect propagates a `CoverageFilesInfo` provider.
implementation = _coverage_files_aspect_impl,
)

def _get_template_substitutions(test_type, test_bundle, test_environment, test_host = None):
def _get_template_substitutions(test_type, test_bundle, test_environment, test_host = None, test_filter = None):
"""Dictionary with the substitutions to be applied to the template script."""
subs = {}

Expand All @@ -113,6 +113,7 @@ def _get_template_substitutions(test_type, test_bundle, test_environment, test_h
subs["test_bundle_path"] = test_bundle.short_path
subs["test_type"] = test_type.upper()
subs["test_env"] = ",".join([k + "=" + v for (k, v) in test_environment.items()])
subs["test_filter"] = test_filter or ""

return {"%(" + k + ")s": subs[k] for k in subs}

Expand Down Expand Up @@ -174,6 +175,7 @@ def _apple_test_rule_impl(ctx, test_type):
test_bundle,
test_environment,
test_host = test_host_archive,
test_filter = ctx.attr.test_filter,
),
is_executable = True,
)
Expand Down
13 changes: 11 additions & 2 deletions apple/testing/default_runner/ios_test_runner.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,26 @@ if [[ -n "${command_line_args}" ]]; then
LAUNCH_OPTIONS_JSON_STR+="\"args\":[\"$command_line_args\"]"
fi

TEST_FILTER="%(test_filter)s"

# Use the TESTBRIDGE_TEST_ONLY environment variable set by Bazel's --test_filter
# flag to set tests_to_run value in ios_test_runner's launch_options.
# Any test prefixed with '-' will be passed to "skip_tests". Otherwise the tests
# is passed to "tests_to_run"
if [[ -n "$TESTBRIDGE_TEST_ONLY" ]]; then
if [[ -n "$TESTBRIDGE_TEST_ONLY" || -n "$TEST_FILTER" ]]; then
if [[ -n "${LAUNCH_OPTIONS_JSON_STR}" ]]; then
LAUNCH_OPTIONS_JSON_STR+=","
fi

IFS=","
ALL_TESTS=("$TESTBRIDGE_TEST_ONLY")
if [[ -n "$TESTBRIDGE_TEST_ONLY" && -n "$TEST_FILTER" ]]; then
ALL_TESTS=("$TESTBRIDGE_TEST_ONLY,$TEST_FILTER")
elif [[ -n "$TESTBRIDGE_TEST_ONLY" ]]; then
ALL_TESTS=("$TESTBRIDGE_TEST_ONLY")
else
ALL_TESTS=("$TEST_FILTER")
fi

for TEST in $ALL_TESTS; do
if [[ $TEST == -* ]]; then
if [[ -n "$SKIP_TESTS" ]]; then
Expand Down
6 changes: 4 additions & 2 deletions doc/rules-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ Builds and bundles an iOS Sticker Pack Extension.
## ios_ui_test

<pre>
ios_ui_test(<a href="#ios_ui_test-name">name</a>, <a href="#ios_ui_test-data">data</a>, <a href="#ios_ui_test-deps">deps</a>, <a href="#ios_ui_test-env">env</a>, <a href="#ios_ui_test-platform_type">platform_type</a>, <a href="#ios_ui_test-runner">runner</a>, <a href="#ios_ui_test-test_host">test_host</a>)
ios_ui_test(<a href="#ios_ui_test-name">name</a>, <a href="#ios_ui_test-data">data</a>, <a href="#ios_ui_test-deps">deps</a>, <a href="#ios_ui_test-env">env</a>, <a href="#ios_ui_test-platform_type">platform_type</a>, <a href="#ios_ui_test-runner">runner</a>, <a href="#ios_ui_test-test_filter">test_filter</a>, <a href="#ios_ui_test-test_host">test_host</a>)
</pre>

iOS UI Test rule.
Expand Down Expand Up @@ -529,6 +529,7 @@ of the attributes inherited by all test rules, please check the
| <a id="ios_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="ios_ui_test-platform_type"></a>platform_type | - | String | optional | "ios" |
| <a id="ios_ui_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="ios_ui_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="ios_ui_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Expand All @@ -537,7 +538,7 @@ of the attributes inherited by all test rules, please check the
## ios_unit_test

<pre>
ios_unit_test(<a href="#ios_unit_test-name">name</a>, <a href="#ios_unit_test-data">data</a>, <a href="#ios_unit_test-deps">deps</a>, <a href="#ios_unit_test-env">env</a>, <a href="#ios_unit_test-platform_type">platform_type</a>, <a href="#ios_unit_test-runner">runner</a>, <a href="#ios_unit_test-test_host">test_host</a>)
ios_unit_test(<a href="#ios_unit_test-name">name</a>, <a href="#ios_unit_test-data">data</a>, <a href="#ios_unit_test-deps">deps</a>, <a href="#ios_unit_test-env">env</a>, <a href="#ios_unit_test-platform_type">platform_type</a>, <a href="#ios_unit_test-runner">runner</a>, <a href="#ios_unit_test-test_filter">test_filter</a>, <a href="#ios_unit_test-test_host">test_host</a>)
</pre>

Builds and bundles an iOS Unit `.xctest` test bundle. Runs the tests using the
Expand Down Expand Up @@ -571,6 +572,7 @@ of the attributes inherited by all test rules, please check the
| <a id="ios_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="ios_unit_test-platform_type"></a>platform_type | - | String | optional | "ios" |
| <a id="ios_unit_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="ios_unit_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="ios_unit_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Expand Down
6 changes: 4 additions & 2 deletions doc/rules-macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Builds and bundles a macOS Spotlight Importer.
## macos_ui_test

<pre>
macos_ui_test(<a href="#macos_ui_test-name">name</a>, <a href="#macos_ui_test-data">data</a>, <a href="#macos_ui_test-deps">deps</a>, <a href="#macos_ui_test-env">env</a>, <a href="#macos_ui_test-platform_type">platform_type</a>, <a href="#macos_ui_test-runner">runner</a>, <a href="#macos_ui_test-test_host">test_host</a>)
macos_ui_test(<a href="#macos_ui_test-name">name</a>, <a href="#macos_ui_test-data">data</a>, <a href="#macos_ui_test-deps">deps</a>, <a href="#macos_ui_test-env">env</a>, <a href="#macos_ui_test-platform_type">platform_type</a>, <a href="#macos_ui_test-runner">runner</a>, <a href="#macos_ui_test-test_filter">test_filter</a>, <a href="#macos_ui_test-test_host">test_host</a>)
</pre>

Builds and bundles an iOS UI `.xctest` test bundle. Runs the tests using the
Expand All @@ -427,6 +427,7 @@ Note: macOS UI tests are not currently supported in the default test runner.
| <a id="macos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="macos_ui_test-platform_type"></a>platform_type | - | String | optional | "macos" |
| <a id="macos_ui_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="macos_ui_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="macos_ui_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Expand All @@ -435,7 +436,7 @@ Note: macOS UI tests are not currently supported in the default test runner.
## macos_unit_test

<pre>
macos_unit_test(<a href="#macos_unit_test-name">name</a>, <a href="#macos_unit_test-data">data</a>, <a href="#macos_unit_test-deps">deps</a>, <a href="#macos_unit_test-env">env</a>, <a href="#macos_unit_test-platform_type">platform_type</a>, <a href="#macos_unit_test-runner">runner</a>, <a href="#macos_unit_test-test_host">test_host</a>)
macos_unit_test(<a href="#macos_unit_test-name">name</a>, <a href="#macos_unit_test-data">data</a>, <a href="#macos_unit_test-deps">deps</a>, <a href="#macos_unit_test-env">env</a>, <a href="#macos_unit_test-platform_type">platform_type</a>, <a href="#macos_unit_test-runner">runner</a>, <a href="#macos_unit_test-test_filter">test_filter</a>, <a href="#macos_unit_test-test_host">test_host</a>)
</pre>

Builds and bundles a macOS unit `.xctest` test bundle. Runs the tests using the
Expand All @@ -462,6 +463,7 @@ find more information about testing for Apple platforms
| <a id="macos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="macos_unit_test-platform_type"></a>platform_type | - | String | optional | "macos" |
| <a id="macos_unit_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="macos_unit_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="macos_unit_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Expand Down
6 changes: 4 additions & 2 deletions doc/rules-tvos.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ i.e. `--features=-swift.no_generated_header`).
## tvos_ui_test

<pre>
tvos_ui_test(<a href="#tvos_ui_test-name">name</a>, <a href="#tvos_ui_test-data">data</a>, <a href="#tvos_ui_test-deps">deps</a>, <a href="#tvos_ui_test-env">env</a>, <a href="#tvos_ui_test-platform_type">platform_type</a>, <a href="#tvos_ui_test-runner">runner</a>, <a href="#tvos_ui_test-test_host">test_host</a>)
tvos_ui_test(<a href="#tvos_ui_test-name">name</a>, <a href="#tvos_ui_test-data">data</a>, <a href="#tvos_ui_test-deps">deps</a>, <a href="#tvos_ui_test-env">env</a>, <a href="#tvos_ui_test-platform_type">platform_type</a>, <a href="#tvos_ui_test-runner">runner</a>, <a href="#tvos_ui_test-test_filter">test_filter</a>, <a href="#tvos_ui_test-test_host">test_host</a>)
</pre>


Expand All @@ -337,6 +337,7 @@ the attributes inherited by all test rules, please check the
| <a id="tvos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="tvos_ui_test-platform_type"></a>platform_type | - | String | optional | "tvos" |
| <a id="tvos_ui_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="tvos_ui_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="tvos_ui_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Expand All @@ -345,7 +346,7 @@ the attributes inherited by all test rules, please check the
## tvos_unit_test

<pre>
tvos_unit_test(<a href="#tvos_unit_test-name">name</a>, <a href="#tvos_unit_test-data">data</a>, <a href="#tvos_unit_test-deps">deps</a>, <a href="#tvos_unit_test-env">env</a>, <a href="#tvos_unit_test-platform_type">platform_type</a>, <a href="#tvos_unit_test-runner">runner</a>, <a href="#tvos_unit_test-test_host">test_host</a>)
tvos_unit_test(<a href="#tvos_unit_test-name">name</a>, <a href="#tvos_unit_test-data">data</a>, <a href="#tvos_unit_test-deps">deps</a>, <a href="#tvos_unit_test-env">env</a>, <a href="#tvos_unit_test-platform_type">platform_type</a>, <a href="#tvos_unit_test-runner">runner</a>, <a href="#tvos_unit_test-test_filter">test_filter</a>, <a href="#tvos_unit_test-test_host">test_host</a>)
</pre>


Expand Down Expand Up @@ -380,6 +381,7 @@ of the attributes inherited by all test rules, please check the
| <a id="tvos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="tvos_unit_test-platform_type"></a>platform_type | - | String | optional | "tvos" |
| <a id="tvos_unit_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="tvos_unit_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="tvos_unit_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


6 changes: 4 additions & 2 deletions doc/rules-watchos.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Builds and bundles a watchOS Static Framework.
## watchos_ui_test

<pre>
watchos_ui_test(<a href="#watchos_ui_test-name">name</a>, <a href="#watchos_ui_test-data">data</a>, <a href="#watchos_ui_test-deps">deps</a>, <a href="#watchos_ui_test-env">env</a>, <a href="#watchos_ui_test-platform_type">platform_type</a>, <a href="#watchos_ui_test-runner">runner</a>, <a href="#watchos_ui_test-test_host">test_host</a>)
watchos_ui_test(<a href="#watchos_ui_test-name">name</a>, <a href="#watchos_ui_test-data">data</a>, <a href="#watchos_ui_test-deps">deps</a>, <a href="#watchos_ui_test-env">env</a>, <a href="#watchos_ui_test-platform_type">platform_type</a>, <a href="#watchos_ui_test-runner">runner</a>, <a href="#watchos_ui_test-test_filter">test_filter</a>, <a href="#watchos_ui_test-test_host">test_host</a>)
</pre>

watchOS UI Test rule.
Expand All @@ -284,6 +284,7 @@ watchOS UI Test rule.
| <a id="watchos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="watchos_ui_test-platform_type"></a>platform_type | - | String | optional | "watchos" |
| <a id="watchos_ui_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="watchos_ui_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="watchos_ui_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Expand All @@ -292,7 +293,7 @@ watchOS UI Test rule.
## watchos_unit_test

<pre>
watchos_unit_test(<a href="#watchos_unit_test-name">name</a>, <a href="#watchos_unit_test-data">data</a>, <a href="#watchos_unit_test-deps">deps</a>, <a href="#watchos_unit_test-env">env</a>, <a href="#watchos_unit_test-platform_type">platform_type</a>, <a href="#watchos_unit_test-runner">runner</a>, <a href="#watchos_unit_test-test_host">test_host</a>)
watchos_unit_test(<a href="#watchos_unit_test-name">name</a>, <a href="#watchos_unit_test-data">data</a>, <a href="#watchos_unit_test-deps">deps</a>, <a href="#watchos_unit_test-env">env</a>, <a href="#watchos_unit_test-platform_type">platform_type</a>, <a href="#watchos_unit_test-runner">runner</a>, <a href="#watchos_unit_test-test_filter">test_filter</a>, <a href="#watchos_unit_test-test_host">test_host</a>)
</pre>

watchOS Unit Test rule.
Expand All @@ -308,6 +309,7 @@ watchOS Unit Test rule.
| <a id="watchos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="watchos_unit_test-platform_type"></a>platform_type | - | String | optional | "watchos" |
| <a id="watchos_unit_test-runner"></a>runner | The runner target that will provide the logic on how to run the tests. Needs to provide the AppleTestRunnerInfo provider. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="watchos_unit_test-test_filter"></a>test_filter | Test filter string that will be passed into the test runner to select which tests will run. | String | optional | "" |
| <a id="watchos_unit_test-test_host"></a>test_host | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Loading

0 comments on commit c17af58

Please sign in to comment.