@@ -968,6 +968,42 @@ like `srcs` in `dependency_attributes` instead of `source_attributes`, but it
968
968
avoids the need for explicit coverage configuration for all rules in the
969
969
dependency chain.)
970
970
971
+ #### Test rules
972
+
973
+ Test rules require additional setup to generate coverage reports. The rule
974
+ itself has to add the following implicit attributes:
975
+
976
+ ``` python
977
+ my_test = rule(
978
+ ... ,
979
+ attrs = {
980
+ ... ,
981
+ # Implicit dependencies used by Bazel to generate coverage reports.
982
+ " _lcov_merger" : attr.label(
983
+ default = configuration_field(fragment = " coverage" , name = " output_generator" ),
984
+ executable = True ,
985
+ cfg = config.exec(exec_group = " test" ),
986
+ ),
987
+ " _collect_cc_coverage" : attr.label(
988
+ default = " @bazel_tools//tools/test:collect_cc_coverage" ,
989
+ executable = True ,
990
+ cfg = config.exec(exec_group = " test" ),
991
+ )
992
+ },
993
+ test = True ,
994
+ )
995
+ ```
996
+
997
+ By using ` configuration_field ` , the dependency on the Java LCOV merger tool can
998
+ be avoided as long as coverage is not requested.
999
+
1000
+ When the test is run, it should emit coverage information in the form of one or
1001
+ more [ LCOV files] ( https://manpages.debian.org/unstable/lcov/geninfo.1.en.html#TRACEFILE_FORMAT )
1002
+ with unique names into the directory specified by the ` COVERAGE_DIR ` environment
1003
+ variable. Bazel will then merge these files into a single LCOV file using the
1004
+ ` _lcov_merger ` tool. If present, it will also collect C/C++ coverage using the
1005
+ ` _collect_cc_coverage ` tool.
1006
+
971
1007
### Validation Actions
972
1008
973
1009
Sometimes you need to validate something about the build, and the
0 commit comments