Download & Extend

Deal with Xdebug inconsistencies

Project:Code coverage
Version:7.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

And figure out a way to deal with them.

For example: http://imagebin.ca/view/TyoeOu.html

Comments

#1

#2

Title:Determine why Xdebug reports empty lines in templates as having been executed» Deal with Xdebug inconsistencies

Marking #639102: wrong coverage on curly brace after return statement in favor of general Xdebug issue.

Recording lines that come back with XDEBUG_CC_DEAD_CODE partly solves the issue, but oddly doesn't solve it completely.

Index: code_coverage.xdebug.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/code_coverage/code_coverage.xdebug.inc,v
retrieving revision 1.7
diff -u -r1.7 code_coverage.xdebug.inc
--- code_coverage.xdebug.inc 12 Mar 2010 21:41:00 -0000 1.7
+++ code_coverage.xdebug.inc 12 Mar 2010 23:34:20 -0000
@@ -33,7 +33,7 @@

   // Start Xdebug code coverage and register shutdown function to collect the
   // results and place them in the log table.
-  xdebug_start_code_coverage();
+  xdebug_start_code_coverage(XDEBUG_CC_DEAD_CODE);
   drupal_register_shutdown_function('code_coverage_record', $coverage_set, !empty($_GET['code_coverage']));
}

#3

The mentioned flag + the UNUSED flag is used by the patch in #983808: Fix Simpletest integration

However, the overall results are very poor, even with the latest Xdebug stable. For example, code coverage report tells me that an experimental class (which happens to live within a file that has been loaded) is 100% covered, even though the class is never instantiated. Same behavior with procedural code in a .module file.

#4

Looks like this is just simply a logic error. We currently do:

<?php
       
// Insert all line information into log table.
       
$insert = db_insert('code_coverage_log', $db_options)->fields(array('file_id', 'line'));
        foreach (
$lines as $line => $count) {
         
// Ignore line 0.
         
if ($line) {
           
$insert->values(array(
?>

but the combined XDEBUG_CC_DEAD_CODE | XDEBUG_CC_UNUSED flag leads to $count being negative for affected lines, as explained by the xdebug maintainer in http://www.slideshare.net/sebastian_bergmann/analysing-php-code

Thus, should be

<?php
         
if ($line && $count) {
?>

Will incorporate that into #983808: Fix Simpletest integration

#5

Of course, it must be

<?php
         
if ($line && $count > 0) {
?>

http://twitter.com/#!/tha_sun/statuses/82248712830730243

#6

Nice find, do we need to do something additional with that? For example, to mark dead code (closing } in functions as in the presentation) to not show up as untested? I haven't looked at the results yet.

nobody click here