vasilvv | 0604a53 | 2022-05-24 12:59:16 -0700 | [diff] [blame] | 1 | """Tools for building QUICHE tests.""" |
| 2 | |
vasilvv | 4a0a152 | 2022-09-26 13:12:57 -0700 | [diff] [blame] | 3 | load("@bazel_skylib//lib:dicts.bzl", "dicts") |
vasilvv | 0604a53 | 2022-05-24 12:59:16 -0700 | [diff] [blame] | 4 | load("@bazel_skylib//lib:paths.bzl", "paths") |
| 5 | |
| 6 | def test_suite_from_source_list(name, srcs, **kwargs): |
| 7 | """ |
| 8 | Generates a test target for every individual test source file specified. |
| 9 | |
| 10 | Args: |
| 11 | name: the name of the resulting test_suite target. |
| 12 | srcs: the list of source files from which the test targets are generated. |
| 13 | **kwargs: other arguments that are passed to the cc_test rule directly.s |
| 14 | """ |
| 15 | |
| 16 | tests = [] |
| 17 | for sourcefile in srcs: |
| 18 | if not sourcefile.endswith("_test.cc"): |
| 19 | fail("All source files passed to test_suite_from_source_list() must end with _test.cc") |
| 20 | test_name, _ = paths.split_extension(paths.basename(sourcefile)) |
vasilvv | 4a0a152 | 2022-09-26 13:12:57 -0700 | [diff] [blame] | 21 | extra_kwargs = {} |
| 22 | if test_name == "end_to_end_test": |
| 23 | extra_kwargs["shard_count"] = 16 |
vasilvv | 0604a53 | 2022-05-24 12:59:16 -0700 | [diff] [blame] | 24 | native.cc_test( |
| 25 | name = test_name, |
| 26 | srcs = [sourcefile], |
vasilvv | 4a0a152 | 2022-09-26 13:12:57 -0700 | [diff] [blame] | 27 | **dicts.add(kwargs, extra_kwargs) |
vasilvv | 0604a53 | 2022-05-24 12:59:16 -0700 | [diff] [blame] | 28 | ) |
| 29 | tests.append(test_name) |
| 30 | native.test_suite(name = name, tests = tests) |