1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Filter out some Clover coverage to prevent false positives

Summary: Clover reports generated from PHPUnit sometimes give false positives of lines that were not covered by a test that should have actually been not coverable, apparently due to inaccurate static analysis of files that weren't actually executed. This filters coverage reports of files that show no coverage which avoids these false positives. Fixes T10420.

Test Plan:
Looked at coverage reports of files before and after the change

Before: {F1124115}

After: {F1124113}

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, aurelijus

Maniphest Tasks: T10420

Differential Revision: https://secure.phabricator.com/D15343
This commit is contained in:
Eric Stern 2016-02-24 12:48:37 -08:00
parent fcc11b3a27
commit 086f5399bf

View file

@ -129,34 +129,33 @@ final class ArcanistPhpunitTestResultParser extends ArcanistTestResultParser {
$line_count = count(file($class_path));
$coverage = '';
$any_line_covered = false;
$start_line = 1;
$lines = $file->getElementsByTagName('line');
for ($ii = 0; $ii < $lines->length; $ii++) {
$line = $lines->item($ii);
for (; $start_line < $line->getAttribute('num'); $start_line++) {
$coverage .= 'N';
}
$coverage = str_repeat('N', $line_count);
foreach ($lines as $line) {
if ($line->getAttribute('type') != 'stmt') {
$coverage .= 'N';
} else {
if ((int)$line->getAttribute('count') == 0) {
$coverage .= 'U';
} else if ((int)$line->getAttribute('count') > 0) {
$coverage .= 'C';
}
continue;
}
$start_line++;
if ((int)$line->getAttribute('count') > 0) {
$is_covered = 'C';
$any_line_covered = true;
} else {
$is_covered = 'U';
}
$line_no = (int)$line->getAttribute('num');
$coverage[$line_no - 1] = $is_covered;
}
for (; $start_line <= $line_count; $start_line++) {
$coverage .= 'N';
// Sometimes the Clover coverage gives false positives on uncovered lines
// when the file wasn't actually part of the test. This filters out files
// with no coverage which helps give more accurate overall results.
if ($any_line_covered) {
$len = strlen($this->projectRoot.DIRECTORY_SEPARATOR);
$class_path = substr($class_path, $len);
$reports[$class_path] = $coverage;
}
$len = strlen($this->projectRoot.DIRECTORY_SEPARATOR);
$class_path = substr($class_path, $len);
$reports[$class_path] = $coverage;
}
return $reports;