feat: add test_suite containing all tests from write_source_files (#256)
This commit is contained in:
parent
951e1ec9ad
commit
9d531ca646
|
@ -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
|
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).
|
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`
|
**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 out_file:
|
||||||
if not in_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:
|
if not in_file or not out_file or not diff_test:
|
||||||
return
|
return None
|
||||||
|
|
||||||
out_file_missing = _is_file_missing(out_file)
|
out_file_missing = _is_file_missing(out_file)
|
||||||
test_target_name = "%s_test" % name
|
test_target_name = "%s_test" % name
|
||||||
|
@ -126,6 +129,8 @@ To update *only* this file, run:
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return test_target_name
|
||||||
|
|
||||||
_write_source_file_attrs = {
|
_write_source_file_attrs = {
|
||||||
"in_file": attr.label(allow_files = True, mandatory = False),
|
"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
|
# out_file is intentionally an attr.string() and not a attr.label(). This is so that
|
||||||
|
|
|
@ -95,6 +95,7 @@ def write_source_files(
|
||||||
|
|
||||||
single_update_target = len(files.keys()) == 1
|
single_update_target = len(files.keys()) == 1
|
||||||
update_targets = []
|
update_targets = []
|
||||||
|
test_targets = []
|
||||||
for i, pair in enumerate(files.items()):
|
for i, pair in enumerate(files.items()):
|
||||||
out_file, in_file = pair
|
out_file, in_file = pair
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ def write_source_files(
|
||||||
this_suggested_update_target = name
|
this_suggested_update_target = name
|
||||||
|
|
||||||
# Runnable target that writes to the out file to the source tree
|
# Runnable target that writes to the out file to the source tree
|
||||||
_write_source_file(
|
test_target = _write_source_file(
|
||||||
name = update_target_name,
|
name = update_target_name,
|
||||||
in_file = in_file,
|
in_file = in_file,
|
||||||
out_file = out_file,
|
out_file = out_file,
|
||||||
|
@ -118,6 +119,17 @@ def write_source_files(
|
||||||
**kwargs
|
**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:
|
if not single_update_target:
|
||||||
_write_source_file(
|
_write_source_file(
|
||||||
name = name,
|
name = name,
|
||||||
|
|
Loading…
Reference in New Issue