Using Bazel to generate coverage report

后端 未结 2 604
温柔的废话
温柔的废话 2020-12-17 02:38

I am using genhtml command to generate html coverage report from Bazel generated coverage.dat file:

genhtml bazel-testlogs/path/to/TestTarget/coverage.dat --         


        
相关标签:
2条回答
  • 2020-12-17 03:04

    I was not able to find a way to get coverage.dat files as an output of a bazel rule. However, I was able to wrap all the locations of all the .dat files as srcs to a filegroup in WORKSPACE directory:

    filegroup(
        name = "coverage_files",
        srcs = glob(["bazel-out/**/coverage.dat"]),
    )
    

    and then use that filegroup in a custom .bzl rule that wraps the genthml command to generate html coverage report. So now I only have to call

    bazel coverage //path/... --instrumentation_filter=/path[/:]
    

    command to generate the coverage.dat files, generate html report and zip it up. Thus, bazel handles everything.

    0 讨论(0)
  • 2020-12-17 03:07

    Bazel added support for C++ coverage (though I couldn't find much documentation for it).

    I was able to generate a combined coverage.dat file with

    bazel coverage -s \
      --instrument_test_targets \
      --experimental_cc_coverage \
      --combined_report=lcov \
      --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main \
      //...
    

    The coverage file gets added to bazel-out/_coverage/_coverage_report.dat

    0 讨论(0)
提交回复
热议问题