Page MenuHomePhabricator

Don't show coverage data if it doesn't exist
Open, Needs TriagePublic


Currently, arc unit --coverage will report coverage data for files which don't have any coverage data available. For example, see D15251. When running arc unit for this diff, the following output is shown:

   PASS   51ms   ArcanistLibraryTestCase::testTrue
   PASS   1.8s   ArcanistLibraryTestCase::testMethodVisibility
   PASS   72ms   ArcanistLibraryTestCase::testEverythingImplemented
   PASS  367ms   ArcanistLibraryTestCase::testLibraryMap

      0%     bar
      0%     foo
    100%     src/__tests__/ArcanistLibraryTestCase.php

This doesn't appear to be unique to any specific test engine but seems to be due to the following code within ArcanistUnitWorkflow:

if ($coverage) {
  $file_coverage = array_fill_keys(
  $file_reports = array();
  foreach ($coverage as $file => $reports) {
    $report = ArcanistUnitTestResult::mergeCoverage($reports);
    $cov = substr_count($report, 'C');
    $uncov = substr_count($report, 'U');
    if ($cov + $uncov) {
      $coverage = $cov / ($cov + $uncov);
    } else {
      $coverage = 0;
    $file_coverage[$file] = $coverage;
    $file_reports[$file] = $report;