Skip to content

Commit 57d46ed

Browse files
authored
Fix unit test attr forwarding (#927)
The `test.bzl` macros were incorrectly forwarding some of the attrs like `features`. This was leading to silent errors where things passed via `features` were dropped (such as main thread checking). This PR fixes the macro by properly forwarding ALL supported unit test attrs to the unit test rule.
1 parent 18cd914 commit 57d46ed

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

rules/test.bzl

+19-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ _IOS_TEST_KWARGS = [
99
"bundle_id",
1010
"bundle_name",
1111
"env",
12-
"features",
1312
"flaky",
1413
"frameworks",
1514
"infoplists",
@@ -34,7 +33,6 @@ _APPLE_BUNDLE_ATTRS = {
3433
"bundle_id",
3534
"bundle_name",
3635
"families",
37-
"features",
3836
"frameworks",
3937
"infoplists",
4038
"linkopts",
@@ -45,6 +43,22 @@ _APPLE_BUNDLE_ATTRS = {
4543
]
4644
}
4745

46+
# See: https://bazel.build/reference/be/common-definitions#common-attributes
47+
# NOTE: `testonly` arent listed because we have custom logic for them in here.
48+
_ALWAYS_AVAILABLE_ATTRS = [
49+
"compatible_with",
50+
"deprecation",
51+
"distribs",
52+
"exec_compatible_with",
53+
"exec_properties",
54+
"features",
55+
"restricted_to",
56+
"tags",
57+
"target_compatible_with",
58+
"toolchains",
59+
"visibility",
60+
]
61+
4862
_DEFAULT_APPLE_TEST_RUNNER = "@build_bazel_rules_apple//apple/testing/default_runner:ios_default_runner"
4963

5064
def _make_runner_split(name, runner, **in_split):
@@ -104,7 +118,7 @@ def _make_test(name, test_rule, **kwargs):
104118
Helper to create an individual test
105119
"""
106120
runner = kwargs.pop("runner", None) or _DEFAULT_APPLE_TEST_RUNNER
107-
test_attrs = {k: v for (k, v) in kwargs.items() if k not in _APPLE_BUNDLE_ATTRS}
121+
test_attrs = {k: v for (k, v) in kwargs.items() if (k not in _APPLE_BUNDLE_ATTRS) or (k in _ALWAYS_AVAILABLE_ATTRS)}
108122

109123
test_rule(
110124
name = name,
@@ -159,7 +173,7 @@ def _ios_test(name, bundle_rule, test_rule, test_factory, apple_library, infopli
159173
"""
160174

161175
testonly = kwargs.pop("testonly", True)
162-
ios_test_kwargs = {arg: kwargs.pop(arg) for arg in _IOS_TEST_KWARGS if arg in kwargs}
176+
ios_test_kwargs = {arg: kwargs.pop(arg) for arg in (_IOS_TEST_KWARGS + _ALWAYS_AVAILABLE_ATTRS) if arg in kwargs}
163177
ios_test_kwargs["data"] = kwargs.pop("test_data", [])
164178

165179
test_exec_properties = kwargs.pop("test_exec_properties", None)
@@ -218,7 +232,7 @@ def _ios_test(name, bundle_rule, test_rule, test_factory, apple_library, infopli
218232

219233
# Set this to a single __internal__ test bundle.
220234
test_bundle_name = name + ".__internal__.__test_bundle"
221-
bundle_attrs = {k: v for (k, v) in ios_test_kwargs.items() if k in _APPLE_BUNDLE_ATTRS}
235+
bundle_attrs = {k: v for (k, v) in ios_test_kwargs.items() if (k in _APPLE_BUNDLE_ATTRS) or (k in _ALWAYS_AVAILABLE_ATTRS)}
222236
bundle_name = bundle_attrs.pop("bundle_name", name)
223237
bundle_rule(
224238
name = test_bundle_name,

0 commit comments

Comments
 (0)