Skip to content

Commit b42ea42

Browse files
Rachel Goldfingercopybara-github
authored andcommitted
Refactor proto_bzl_test_suite to use a dictionary for test definitions.
PiperOrigin-RevId: 900303772
1 parent 8867244 commit b42ea42

9 files changed

Lines changed: 44 additions & 29 deletions

File tree

bazel/tests/java_lite_proto_library_tests/binary_deps/tests.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ def _test_binary_deps(env, target):
2525
"java/core/liblite_runtime_only-hjar.jar",
2626
])
2727

28-
TESTS = [(_test_binary_deps, ":foo_java_proto_lite")]
28+
TESTS = {
29+
":foo_java_proto_lite": [_test_binary_deps],
30+
}

bazel/tests/java_lite_proto_library_tests/binary_option_deps/tests.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ def _test_binary_option_deps(env, target):
2323
"java/core/liblite_runtime_only-hjar.jar",
2424
])
2525

26-
TESTS = [(_test_binary_option_deps, ":foo_java_proto_lite")]
26+
TESTS = {
27+
":foo_java_proto_lite": [_test_binary_option_deps],
28+
}

bazel/tests/java_lite_proto_library_tests/command_line_contains_target_label/tests.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ def _test_lite_command_line_contains_target_label(env, target):
99
"java_lite_proto_library",
1010
]).in_order()
1111

12-
TESTS = [(_test_lite_command_line_contains_target_label, ":foo_proto")]
12+
TESTS = {
13+
":foo_proto": [_test_lite_command_line_contains_target_label],
14+
}

bazel/tests/java_lite_proto_library_tests/compiler_args/tests.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ def _test_lite_java_proto2_compiler_args(env, target):
99
"{package}/foo.proto",
1010
]).in_order()
1111

12-
TESTS = [(_test_lite_java_proto2_compiler_args, ":foo_proto")]
12+
TESTS = {
13+
":foo_proto": [_test_lite_java_proto2_compiler_args],
14+
}

bazel/tests/java_lite_proto_library_tests/proto_library_builds_compiled_jar/tests.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ def _test_lite_proto_library_builds_compiled_jar(env, target):
55
"{package}/libfoo_proto-lite.jar",
66
)
77

8-
TESTS = [(_test_lite_proto_library_builds_compiled_jar, ":foo_java_proto_lite")]
8+
TESTS = {
9+
":foo_java_proto_lite": [_test_lite_proto_library_builds_compiled_jar],
10+
}

bazel/tests/java_lite_proto_library_tests/same_version_compiler_arguments/tests.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ def _test_same_version_compiler_arguments(env, target):
1818
"java/core/liblite_runtime_only.jar",
1919
])
2020

21-
TESTS = [(_test_same_version_compiler_arguments, ":baz_proto")]
21+
TESTS = {
22+
":baz_proto": [_test_same_version_compiler_arguments],
23+
}

bazel/tests/proto_bzl_test_suite.bzl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,30 @@ def bzl_test_suite(
2222
"""Defines a test suite for bzl analysis tests.
2323
2424
Args:
25-
tests: A list of tuples, where each tuple contains an analysis test
26-
implementation function and a target to test.
27-
config_settings: A dictionary of config settings to apply to the test suite.
28-
testing_aspect: The testing aspect to use.
2925
name: The name of the test suite.
26+
tests: A dictionary where the key is the build target and the value is a list of
27+
analysis test implementation functions using that target.
28+
attrs: A dictionary of attributes to apply to the testing aspect.
29+
testing_aspect: The testing aspect to use in the test suite.
30+
provider_subject_factories: An array of subject factories to use in the test suite.
31+
config_settings: A dictionary of config settings to apply to the test suite.
3032
"""
3133

3234
test_names = []
33-
for (impl, target) in tests:
34-
impl_name = get_function_name(impl)
35-
test_name = create_test_name(impl_name, name)
36-
analysis_test(
37-
name = test_name,
38-
target = target,
39-
impl = impl,
40-
provider_subject_factories = provider_subject_factories,
41-
config_settings = config_settings,
42-
testing_aspect = testing_aspect,
43-
attrs = attrs,
44-
)
45-
test_names.append(test_name)
35+
for target, impl_list in tests.items():
36+
for impl in impl_list:
37+
impl_name = get_function_name(impl)
38+
test_name = create_test_name(impl_name, name)
39+
analysis_test(
40+
name = test_name,
41+
target = target,
42+
impl = impl,
43+
provider_subject_factories = provider_subject_factories,
44+
config_settings = config_settings,
45+
testing_aspect = testing_aspect,
46+
attrs = attrs,
47+
)
48+
test_names.append(test_name)
4649

4750
native.test_suite(
4851
name = name,

bazel/tests/py_proto_library_tests/collects_python_files_from_deps_when_srcs_is_empty/tests.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ def test_collects_python_files_from_deps_when_srcs_is_empty(env, target):
66
expected_basename = "b_pb2.py"
77
env.expect.that_collection(runfiles_paths).contains(expected_basename)
88

9-
TESTS = [
10-
(test_collects_python_files_from_deps_when_srcs_is_empty, ":a_py_pb2"),
11-
]
9+
TESTS = {
10+
":a_py_pb2": [test_collects_python_files_from_deps_when_srcs_is_empty],
11+
}

bazel/tests/py_proto_library_tests/python_proto2_deps/tests.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ def _test_python_proto2_deps(env, target):
55

66
env.expect.that_collection(runfiles_paths).contains("message.py")
77

8-
TESTS = [
9-
(_test_python_proto2_deps, ":proto2_deps_bin"),
10-
]
8+
TESTS = {
9+
":proto2_deps_bin": [_test_python_proto2_deps],
10+
}

0 commit comments

Comments
 (0)