diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 422c792f..aa38462b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/unit/ArcanistUnitTestResult.php b/src/unit/ArcanistUnitTestResult.php index 039393f8..a0dc2f72 100644 --- a/src/unit/ArcanistUnitTestResult.php +++ b/src/unit/ArcanistUnitTestResult.php @@ -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 index 00000000..7c4d43dd --- /dev/null +++ b/src/unit/__tests__/ArcanistUnitTestResultTestCase.php @@ -0,0 +1,43 @@ + 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); + } + } + +}