]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Preserve more information when merging coverage
authorepriestley <git@epriestley.com>
Mon, 10 Aug 2015 22:35:15 +0000 (15:35 -0700)
committerepriestley <git@epriestley.com>
Mon, 10 Aug 2015 22:35:15 +0000 (15:35 -0700)
Summary:
Ref T8096. Each test reports coverage information, which we sometimes merge into a combined coverage report.

Usually, each test will report results for every line in the file, so if the file is 30 lines long, coverage is usually 30 characters long.

However, for whatever reason, tests might report results for only the first part of the file. This is allowed and we handle it properly.

Right now, if one test reports 10 lines of results and another reports 30 lines of results, we only use the first 10 lines of results. Instead, extend the merged coverage to include the extra 20 lines of results.

(This is an uncommon case which I only hit because I was manually banging on my keyboard to generate test data, but there's no reason not to handle it better.)

Test Plan: Used web UI, added + executed unit tests.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8096

Differential Revision: https://secure.phabricator.com/D13854

src/__phutil_library_map__.php
src/unit/ArcanistUnitTestResult.php
src/unit/__tests__/ArcanistUnitTestResultTestCase.php [new file with mode: 0644]

index 422c792f04a7606d4b75095fd0234c9b73b2073f..aa38462b3cfbdb3a4a070af1ac64654ede80d027 100644 (file)
@@ -247,6 +247,7 @@ phutil_register_library_map(array(
     'ArcanistUnitRenderer' => 'unit/renderer/ArcanistUnitRenderer.php',
     'ArcanistUnitTestEngine' => 'unit/engine/ArcanistUnitTestEngine.php',
     'ArcanistUnitTestResult' => 'unit/ArcanistUnitTestResult.php',
+    'ArcanistUnitTestResultTestCase' => 'unit/__tests__/ArcanistUnitTestResultTestCase.php',
     'ArcanistUnitTestableLintEngine' => 'lint/engine/ArcanistUnitTestableLintEngine.php',
     'ArcanistUnitWorkflow' => 'workflow/ArcanistUnitWorkflow.php',
     'ArcanistUnnecessaryFinalModifierXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php',
@@ -525,6 +526,7 @@ phutil_register_library_map(array(
     'ArcanistUnitRenderer' => 'Phobject',
     'ArcanistUnitTestEngine' => 'Phobject',
     'ArcanistUnitTestResult' => 'Phobject',
+    'ArcanistUnitTestResultTestCase' => 'PhutilTestCase',
     'ArcanistUnitTestableLintEngine' => 'ArcanistLintEngine',
     'ArcanistUnitWorkflow' => 'ArcanistWorkflow',
     'ArcanistUnnecessaryFinalModifierXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
index 039393f84df3080ba70c83a4e65782e5dabde734..a0dc2f725c8f900914be08290a5fbd0b972185e1 100644 (file)
@@ -129,13 +129,22 @@ final class ArcanistUnitTestResult extends Phobject {
 
     $base = reset($coverage);
     foreach ($coverage as $more_coverage) {
-      $len = min(strlen($base), strlen($more_coverage));
+      $base_len = strlen($base);
+      $more_len = strlen($more_coverage);
+
+      $len = min($base_len, $more_len);
       for ($ii = 0; $ii < $len; $ii++) {
         if ($more_coverage[$ii] == 'C') {
           $base[$ii] = 'C';
         }
       }
+
+      // If a secondary report has more data, copy all of it over.
+      if ($more_len > $base_len) {
+        $base .= substr($more_coverage, $base_len);
+      }
     }
+
     return $base;
   }
 
diff --git a/src/unit/__tests__/ArcanistUnitTestResultTestCase.php b/src/unit/__tests__/ArcanistUnitTestResultTestCase.php
new file mode 100644 (file)
index 0000000..7c4d43d
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+final class ArcanistUnitTestResultTestCase extends PhutilTestCase {
+
+  public function testCoverageMerges() {
+    $cases = array(
+      array(
+        'coverage' => array(),
+        'expect' => null,
+      ),
+      array(
+        'coverage' => array(
+          'UUUNCNC',
+        ),
+        'expect' => 'UUUNCNC',
+      ),
+      array(
+        'coverage' => array(
+          'UUCUUU',
+          'UUUUCU',
+        ),
+        'expect' => 'UUCUCU',
+      ),
+      array(
+        'coverage' => array(
+          'UUCCCU',
+          'UUUCCCNNNC',
+        ),
+        'expect' => 'UUCCCCNNNC',
+      ),
+    );
+
+    foreach ($cases as $case) {
+      $input = $case['coverage'];
+      $expect = $case['expect'];
+
+      $actual = ArcanistUnitTestResult::mergeCoverage($input);
+
+      $this->assertEqual($expect, $actual);
+    }
+  }
+
+}