This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
forked from bazel-ios/rules_ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.bzl
100 lines (85 loc) · 4.13 KB
/
test.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
load("@build_bazel_rules_apple//apple:ios.bzl", rules_apple_ios_ui_test = "ios_ui_test", rules_apple_ios_ui_test_suite = "ios_ui_test_suite", rules_apple_ios_unit_test = "ios_unit_test", rules_apple_ios_unit_test_suite = "ios_unit_test_suite")
load("@bazel_skylib//lib:types.bzl", "types")
load("//rules:library.bzl", "apple_library")
load("//rules:plists.bzl", "info_plists_by_setting")
load("//rules:import_middleman.bzl", "import_middleman")
_IOS_TEST_KWARGS = [
"bundle_id",
"infoplists",
"minimum_os_version",
"test_host",
"env",
"args",
"size",
"timeout",
"visibility",
"resources",
"tags",
"shard_count",
"flaky",
]
def _ios_test(name, test_rule, test_suite_rule, apple_library, infoplists_by_build_setting = {}, **kwargs):
"""
Builds and packages iOS Unit/UI Tests.
Args:
name: The name of the unit test.
test_rule: The underlying rules_apple test rule.
test_suite_rule: The underlying rules_apple test suite rule.
apple_library: The macro used to package sources into a library.
infoplists_by_build_setting: A dictionary of infoplists grouped by bazel build setting.
Each value is applied if the respective bazel build setting
is resolved during the analysis phase.
If '//conditions:default' is not set the value in 'infoplists'
is set as default.
**kwargs: Arguments passed to the apple_library and test_rule rules as appropriate.
"""
ios_test_kwargs = {arg: kwargs.pop(arg) for arg in _IOS_TEST_KWARGS if arg in kwargs}
ios_test_kwargs["data"] = kwargs.pop("test_data", [])
if ios_test_kwargs.get("test_host", None) == True:
ios_test_kwargs["test_host"] = "@build_bazel_rules_ios//rules/test_host_app:iOS-%s-AppHost" % ios_test_kwargs.get("minimum_os_version")
if "runner" in kwargs and "runners" in kwargs:
fail("cannot specify both runner and runners for %s" % name)
runner = kwargs.pop("runner", kwargs.pop("runners", None))
rule = test_rule
if runner:
if types.is_list(runner):
ios_test_kwargs["runners"] = runner
rule = test_suite_rule
else:
ios_test_kwargs["runner"] = runner
library = apple_library(name = name, namespace_is_module_name = False, platforms = {"ios": ios_test_kwargs.get("minimum_os_version")}, **kwargs)
# Deduplicate against the test deps
if ios_test_kwargs.get("test_host", None):
host_args = [ios_test_kwargs["test_host"]]
else:
host_args = []
import_middleman(name = name + ".import_middleman", deps = library.lib_names, test_deps = host_args, tags = ["manual"])
rule(
name = name,
deps = select({
"@build_bazel_rules_ios//:arm64_simulator_use_device_deps": [name + ".import_middleman"],
"//conditions:default": library.lib_names,
}),
infoplists = info_plists_by_setting(name = name, infoplists_by_build_setting = infoplists_by_build_setting, default_infoplists = ios_test_kwargs.pop("infoplists", [])),
**ios_test_kwargs
)
def ios_unit_test(name, apple_library = apple_library, **kwargs):
"""
Builds and packages iOS Unit Tests.
Args:
name: The name of the unit test.
apple_library: The macro used to package sources into a library.
**kwargs: Arguments passed to the apple_library and ios_unit_test rules as appropriate.
"""
_ios_test(name, rules_apple_ios_unit_test, rules_apple_ios_unit_test_suite, apple_library, **kwargs)
def ios_ui_test(name, apple_library = apple_library, **kwargs):
"""
Builds and packages iOS UI Tests.
Args:
name: The name of the UI test.
apple_library: The macro used to package sources into a library.
**kwargs: Arguments passed to the apple_library and ios_ui_test rules as appropriate.
"""
if not kwargs.get("test_host", None):
fail("test_host is required for ios_ui_test.")
_ios_test(name, rules_apple_ios_ui_test, rules_apple_ios_ui_test_suite, apple_library, **kwargs)