Skip to content

Commit 10d375c

Browse files
committed
Remove the groups arg from the ct_suite macro
Most of the functionality can be achieved with passing the same argument through ct_group_matrix or ct_group_case_matrix before passing the result to the matrix argument of `ct_suite` ct_suite was feeling overly complex in the groups codepath, which is less general than the matrix argument
1 parent 58ad110 commit 10d375c

File tree

1 file changed

+21
-60
lines changed

1 file changed

+21
-60
lines changed

ct.bzl

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,8 @@ def ct_suite(
145145
runtime_deps = [],
146146
tools = [],
147147
test_env = {},
148-
groups = [],
149148
matrix = [],
150149
**kwargs):
151-
if len(groups) > 0 and len(matrix) > 0:
152-
fail("groups and matrix are mutually exclusive for ct_suite")
153-
154150
if suite_name == "":
155151
suite_name = name
156152

@@ -166,64 +162,12 @@ def ct_suite(
166162

167163
data_dir_files = native.glob(["test/{}_data/**/*".format(suite_name)])
168164

169-
if len(groups) > 0:
170-
is_dict = hasattr(groups, "keys")
171-
tests = []
172-
for group in groups:
173-
if is_dict:
174-
group_tests = []
175-
for case in groups[group]:
176-
if hasattr(case, "keys"):
177-
case_name = case["case"]
178-
el_kwargs = dict(**case)
179-
el_kwargs.pop("case")
180-
el_kwargs.update(**kwargs)
181-
else:
182-
case_name = case
183-
el_kwargs = kwargs
184-
185-
ct_test(
186-
name = "{}-{}-{}".format(name, group, case_name),
187-
compiled_suites = [":{}_beam_files".format(name)] + additional_beam,
188-
data = data_dir_files + data,
189-
deps = [":test_bazel_erlang_lib"] + deps + runtime_deps,
190-
tools = tools,
191-
test_env = test_env,
192-
suites = [name],
193-
groups = [group],
194-
cases = [case_name],
195-
**el_kwargs
196-
)
197-
group_tests.append("{}-{}-{}".format(name, group, case_name))
198-
native.test_suite(
199-
name = "{}-{}".format(name, group),
200-
tests = group_tests,
201-
)
202-
tests.extend(group_tests)
203-
else:
204-
ct_test(
205-
name = "{}-{}".format(name, group),
206-
compiled_suites = [":{}_beam_files".format(name)] + additional_beam,
207-
data = data_dir_files + data,
208-
deps = [":test_bazel_erlang_lib"] + deps + runtime_deps,
209-
tools = tools,
210-
test_env = test_env,
211-
suites = [name],
212-
groups = [group],
213-
**kwargs
214-
)
215-
tests.append("{}-{}".format(name, group))
216-
217-
native.test_suite(
218-
name = name,
219-
tests = tests,
220-
)
221-
elif len(matrix) > 0:
165+
if len(matrix) > 0:
222166
all_tests = []
223167
for tag, args in matrix.items():
224168
test_name = "{}-{}".format(name, tag)
225-
el_kwargs = dict(**kwargs)
226-
el_kwargs.update(args)
169+
test_kwargs = dict(**kwargs)
170+
test_kwargs.update(args)
227171
ct_test(
228172
name = test_name,
229173
compiled_suites = [":{}_beam_files".format(name)] + additional_beam,
@@ -232,7 +176,7 @@ def ct_suite(
232176
tools = tools,
233177
test_env = test_env,
234178
suites = [name],
235-
**el_kwargs
179+
**test_kwargs
236180
)
237181
all_tests.append(test_name)
238182

@@ -250,3 +194,20 @@ def ct_suite(
250194
test_env = test_env,
251195
**kwargs
252196
)
197+
198+
def ct_group_matrix(groups):
199+
matrix = {}
200+
for group in groups:
201+
matrix[group] = {"groups": [group]}
202+
return matrix
203+
204+
def ct_group_case_matrix(groups):
205+
matrix = {}
206+
for group in groups:
207+
for case in groups[group]:
208+
name = "{}-{}".format(group, case)
209+
matrix[name] = {
210+
"groups": [group],
211+
"cases": [case],
212+
}
213+
return matrix

0 commit comments

Comments
 (0)