1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-29 10:12:41 +01:00

Preserve more information when merging coverage

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
This commit is contained in:
epriestley 2015-08-10 15:35:15 -07:00
parent e4caf1a7d9
commit de58fc809e
3 changed files with 55 additions and 1 deletions

View file

@ -247,6 +247,7 @@ phutil_register_library_map(array(
'ArcanistUnitRenderer' => 'unit/renderer/ArcanistUnitRenderer.php', 'ArcanistUnitRenderer' => 'unit/renderer/ArcanistUnitRenderer.php',
'ArcanistUnitTestEngine' => 'unit/engine/ArcanistUnitTestEngine.php', 'ArcanistUnitTestEngine' => 'unit/engine/ArcanistUnitTestEngine.php',
'ArcanistUnitTestResult' => 'unit/ArcanistUnitTestResult.php', 'ArcanistUnitTestResult' => 'unit/ArcanistUnitTestResult.php',
'ArcanistUnitTestResultTestCase' => 'unit/__tests__/ArcanistUnitTestResultTestCase.php',
'ArcanistUnitTestableLintEngine' => 'lint/engine/ArcanistUnitTestableLintEngine.php', 'ArcanistUnitTestableLintEngine' => 'lint/engine/ArcanistUnitTestableLintEngine.php',
'ArcanistUnitWorkflow' => 'workflow/ArcanistUnitWorkflow.php', 'ArcanistUnitWorkflow' => 'workflow/ArcanistUnitWorkflow.php',
'ArcanistUnnecessaryFinalModifierXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php', 'ArcanistUnnecessaryFinalModifierXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php',
@ -525,6 +526,7 @@ phutil_register_library_map(array(
'ArcanistUnitRenderer' => 'Phobject', 'ArcanistUnitRenderer' => 'Phobject',
'ArcanistUnitTestEngine' => 'Phobject', 'ArcanistUnitTestEngine' => 'Phobject',
'ArcanistUnitTestResult' => 'Phobject', 'ArcanistUnitTestResult' => 'Phobject',
'ArcanistUnitTestResultTestCase' => 'PhutilTestCase',
'ArcanistUnitTestableLintEngine' => 'ArcanistLintEngine', 'ArcanistUnitTestableLintEngine' => 'ArcanistLintEngine',
'ArcanistUnitWorkflow' => 'ArcanistWorkflow', 'ArcanistUnitWorkflow' => 'ArcanistWorkflow',
'ArcanistUnnecessaryFinalModifierXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistUnnecessaryFinalModifierXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',

View file

@ -129,13 +129,22 @@ final class ArcanistUnitTestResult extends Phobject {
$base = reset($coverage); $base = reset($coverage);
foreach ($coverage as $more_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++) { for ($ii = 0; $ii < $len; $ii++) {
if ($more_coverage[$ii] == 'C') { if ($more_coverage[$ii] == 'C') {
$base[$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; return $base;
} }

View file

@ -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);
}
}
}