Skip to content
Permalink
Browse files

Continuing work on updated code coverage reports.

  • Loading branch information...
markstory committed May 9, 2010
1 parent 955c6be commit 9a20a2344b122e5df46c0a654e0cfcb17c7e109d
@@ -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,
@@ -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) {
@@ -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;
@@ -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);

0 comments on commit 9a20a23

Please sign in to comment.
You can’t perform that action at this time.