feat: add test_suite containing all tests from write_source_files (#256)

This commit is contained in:
Matt Mackay 2022-10-05 12:01:50 -04:00 committed by GitHub
parent 951e1ec9ad
commit 9d531ca646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -30,6 +30,9 @@ def write_source_file(
suggested_update_target: Label of the write_source_file target to suggest running when files are out of date
diff_test: Generate a test target to check that the source file(s) exist and are up to date with the generated files(s).
**kwargs: Other common named parameters such as `tags` or `visibility`
Returns:
Name of the generated test target if requested, otherwise None.
"""
if out_file:
if not in_file:
@ -59,7 +62,7 @@ def write_source_file(
)
if not in_file or not out_file or not diff_test:
return
return None
out_file_missing = _is_file_missing(out_file)
test_target_name = "%s_test" % name
@ -126,6 +129,8 @@ To update *only* this file, run:
**kwargs
)
return test_target_name
_write_source_file_attrs = {
"in_file": attr.label(allow_files = True, mandatory = False),
# out_file is intentionally an attr.string() and not a attr.label(). This is so that

View File

@ -95,6 +95,7 @@ def write_source_files(
single_update_target = len(files.keys()) == 1
update_targets = []
test_targets = []
for i, pair in enumerate(files.items()):
out_file, in_file = pair
@ -108,7 +109,7 @@ def write_source_files(
this_suggested_update_target = name
# Runnable target that writes to the out file to the source tree
_write_source_file(
test_target = _write_source_file(
name = update_target_name,
in_file = in_file,
out_file = out_file,
@ -118,6 +119,17 @@ def write_source_files(
**kwargs
)
if test_target:
test_targets.append(test_target)
if len(test_targets) > 0:
native.test_suite(
name = "%s_tests" % name,
tests = test_targets,
visibility = kwargs.get("visibility"),
tags = kwargs.get("tags"),
)
if not single_update_target:
_write_source_file(
name = name,