Skip to content

Commit

Permalink
Continuing work on updated code coverage reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 9, 2010
1 parent 955c6be commit 9a20a23
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
12 changes: 6 additions & 6 deletions cake/tests/cases/libs/html_coverage_report.test.php
Expand Up @@ -143,9 +143,9 @@ function other_thing() {
$result = $this->Coverage->getExecutableLines(explode("\n", $contents));
$expected = array(
0 => false,
1 => true,
2 => true,
3 => true,
1 => false,
2 => false,
3 => false,
4 => true,
5 => true,
6 => false,
Expand Down Expand Up @@ -186,14 +186,14 @@ function testGenerateDiff() {
3 => 1,
4 => 1,
5 => -1,
6 => -1,
7 => -1,
6 => 1,
7 => 1,
8 => 1,
9 => -1,
10 => 1,
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/<h2>myfile\.php Code coverage\: \d+\.\d+\%<\/h2>/', $result);
$this->assertRegExp('/<h2>myfile\.php Code coverage\: \d+\.?\d*\%<\/h2>/', $result);
$this->assertRegExp('/<div class="code-coverage-results">/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {
Expand Down
39 changes: 26 additions & 13 deletions cake/tests/lib/coverage/html_coverage_report.php
Expand Up @@ -150,14 +150,27 @@ public function getExecutableLines($lines) {

$phpTagPattern = '/^[ |\t]*[<\?php|\?>]+[ |\t]*/';
$basicallyEmptyPattern = '/^[ |\t]*[{|}|\(|\)]+[ |\t]*/';
$commentStart = '/\/\*\*/';
$commentEnd = '/\*\//';
$ignoreStart = '/@codeCoverageIgnoreStart/';
$ignoreStop = '/@codeCoverageIgnoreEnd/';
$inComment = false;

foreach ($lines as $lineno => $line) {
$runnable = true;
if (preg_match($phpTagPattern, $line) || preg_match($basicallyEmptyPattern, $line)) {
$runnable = false;
}
if ($runnable && preg_match($commentStart, $line)) {
$runnable = false;
$inComment = true;
}
if ($inComment == true) {
$runnable = false;
}
if (!$runnable && preg_match($commentEnd, $line)) {
$inComment = false;
}
$output[$lineno] = $runnable;
}
return $output;
Expand All @@ -183,22 +196,22 @@ function generateDiff($filename, $fileLines, $coverageData) {
$executableLines = $this->getExecutableLines($fileLines);

foreach ($fileLines as $lineno => $line) {
$isExecutable = (isset($executableLines[$lineno]) && $executableLines[$lineno] == true);
$manualFind = (
isset($executableLines[$lineno]) &&
$executableLines[$lineno] == true &&
trim($line) != ''
);

$class = 'uncovered';
if (!$isExecutable) {
$class = 'ignored';
} elseif (isset($coverageData[$lineno]) && $coverageData[$lineno] > 0) {
$class = 'covered';
}
$diff[] = $this->_paintLine($line, $lineno, $class);

if ($class == 'covered') {
$covered++;
}
if ($class == 'uncovered' || $class == 'covered') {
$class = 'ignored';
if ($manualFind) {
$class = 'uncovered';
$total++;
if (isset($coverageData[$lineno]) && $coverageData[$lineno] > 0) {
$class = 'covered';
$covered++;
}
}
$diff[] = $this->_paintLine($line, $lineno, $class);
}

$percentCovered = round($covered / $total, 2);
Expand Down

0 comments on commit 9a20a23

Please sign in to comment.