-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
BUILD.bazel
244 lines (218 loc) · 7.81 KB
/
BUILD.bazel
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load(
"//bazel_integration_test:defs.bzl",
"bazel_integration_test",
"bazel_integration_tests",
"default_test_runner",
"integration_test_utils",
"script_test",
)
bzlformat_pkg(name = "bzlformat")
_LOCAL_BAZEL_BINARY_VERSION = "local"
# MARK: - Simple Tests
default_test_runner(
name = "simple_test_runner",
)
_LEGACY_FLAGS = [
"--noenable_bzlmod",
"--no@cgrindel_bazel_starlib//bzlmod:enabled",
]
default_test_runner(
name = "legacy_simple_test_runner",
bazel_cmds = [
"info {}".format(" ".join(_LEGACY_FLAGS)),
"test {} //...".format(" ".join(_LEGACY_FLAGS)),
],
)
# If you only want to execute against a single version of Bazel, use
# bazel_integration_test.
bazel_integration_test(
name = "simple_test",
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
# Avoid file permssion error when using disk and repository cache after
# 7.0.0rc2 upgrade.
# https://github.com/bazelbuild/bazel/issues/19908
"no-sandbox",
],
test_runner = ":simple_test_runner",
workspace_files = integration_test_utils.glob_workspace_files("simple") + [
"//:shared_bazelrc_files",
],
workspace_path = "simple",
)
# This is testing that the legacy loading of Bazel deps for
# rules_bazel_integration_test works.
bazel_integration_test(
name = "legacy_simple_test",
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
# Avoid file permssion error when using disk and repository cache after
# 7.0.0rc2 upgrade.
# https://github.com/bazelbuild/bazel/issues/19908
"no-sandbox",
],
test_runner = ":legacy_simple_test_runner",
workspace_files = integration_test_utils.glob_workspace_files("simple") + [
"//:shared_bazelrc_files",
],
workspace_path = "simple",
)
_SIMPLE_TEST_VERSIONS = [
version
for version in bazel_binaries.versions.other
if version != _LOCAL_BAZEL_BINARY_VERSION
]
# If you want to execute an integration test using multiple versions of Bazel,
# use bazel_integration_tests. It will generate multiple integration test
# targets with names derived from the base name and the bazel version.
bazel_integration_tests(
# buildifier: disable=duplicated-name
name = "simple_test",
bazel_binaries = bazel_binaries,
bazel_versions = _SIMPLE_TEST_VERSIONS,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
# Avoid file permssion error when using disk and repository cache after
# 7.0.0rc2 upgrade.
# https://github.com/bazelbuild/bazel/issues/19908
"no-sandbox",
],
test_runner = ":simple_test_runner",
workspace_files = integration_test_utils.glob_workspace_files("simple") + [
"//:shared_bazelrc_files",
],
workspace_path = "simple",
)
# MARK: - Custom Test Runner Tests
# NOTE: The following is used to test that the custom_test_runner integration
# tests work. It does not demonstrate how to use a custom test runner. See the
# custom_test_runner workspace for how to use a custom test runner.
default_test_runner(
name = "custom_test_runner_test_runner",
bazel_cmds = integration_test_utils.DEFAULT_BAZEL_CMDS + [
"test //:all_integration_tests",
],
)
bazel_integration_test(
name = "custom_test_runner_test",
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
# Avoid file permssion error when using disk and repository cache after
# 7.0.0rc2 upgrade.
# https://github.com/bazelbuild/bazel/issues/19908
"no-sandbox",
],
# GH120: Enable the custom_test_runner test once swift_bazel supports
# bzlmod.
target_compatible_with = select({
"@cgrindel_bazel_starlib//bzlmod:is_enabled": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
test_runner = ":custom_test_runner_test_runner",
workspace_files = integration_test_utils.glob_workspace_files("custom_test_runner") + [
"//:local_repository_files",
],
workspace_path = "custom_test_runner",
)
# MARK: - Custom Test Runner That Uses create_scratch_dir Test
sh_binary(
name = "use_create_scratch_dir_test_runner",
testonly = True,
srcs = ["use_create_scratch_dir_test.sh"],
data = [
"@rules_bazel_integration_test//tools:create_scratch_dir",
],
deps = [
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_starlib//shlib/lib:assertions",
],
)
bazel_integration_test(
name = "use_create_scratch_dir_test",
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
# Avoid file permssion error when using disk and repository cache after
# 7.0.0rc2 upgrade.
# https://github.com/bazelbuild/bazel/issues/19908
"no-sandbox",
],
test_runner = ":use_create_scratch_dir_test_runner",
workspace_files = integration_test_utils.glob_workspace_files("simple") + [
"//:local_repository_files",
],
workspace_path = "simple",
)
# MARK: - Dynamic workspace Test
sh_binary(
name = "dynamic_workspace_test_runner",
testonly = True,
srcs = ["dynamic_workspace_test_runner.sh"],
deps = [
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_starlib//shlib/lib:assertions",
],
)
bazel_integration_test(
name = "dynamic_workspace_test",
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
# Avoid file permssion error when using disk and repository cache after
# 7.0.0rc2 upgrade.
# https://github.com/bazelbuild/bazel/issues/19908
"no-sandbox",
],
test_runner = ":dynamic_workspace_test_runner",
)
# MARK: - script_test sample
script_test(
name = "sample_script_test",
srcs = ["sample_script_test.sh"],
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
deps = [
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_starlib//shlib/lib:assertions",
],
)
# MARK: - Local Bazel Binary Example/Test
script_test(
name = "local_bazel_binary_test",
srcs = ["local_bazel_binary_test.sh"],
bazel_binaries = bazel_binaries,
bazel_version = _LOCAL_BAZEL_BINARY_VERSION,
deps = [
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_starlib//shlib/lib:assertions",
],
)
# MARK: - Test Suite
# By default, the integration test targets are tagged as `manual`. This
# prevents the targets from being found from most target expansion (e.g.
# `//...`, `:all`). To easily execute a group of integration tests, you may
# want to define a test suite which includes the desired test targets.
test_suite(
name = "integration_tests",
# If you don't apply the test tags to the test suite, the test suite will
# be found when `bazel test //...` is executed.
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
tests = [
":custom_test_runner_test",
":dynamic_workspace_test",
":legacy_simple_test",
":local_bazel_binary_test",
":sample_script_test",
":simple_test",
":use_create_scratch_dir_test",
] + integration_test_utils.bazel_integration_test_names(
"simple_test",
_SIMPLE_TEST_VERSIONS,
),
visibility = ["//:__subpackages__"],
)