View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001917 | Xdebug | Documentation | public | 2020-12-16 02:16 | 2020-12-18 14:52 |
Reporter | DeadApe | Assigned To | derick | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 3.0.1 | ||||
Target Version | 3.0dev | ||||
Summary | 0001917: Document that code coverage flags only affect new function scopes | ||||
Description | I stumbled upon a behaviour of the code coverage component that I consider to be a bug OR insufficiently documented. It is so obvious that I almost can not believe it really is a bug, but at the same time I have no other explanation for it. I have the following code sample: What I expect: Code coverage to return a 1 for the executed lines 3, 4 and 7 and a -1 for an unexecuted line 5. Actual result: Line 5 is missing in the result. Additionally, I'd expect line 6 to appear in the result array with value -2 when passing the XDEBUG_CC_DEAD_CODE flag. This is not the case either. | ||||
Steps To Reproduce | Execute the given PHP snippet | ||||
Additional Information | php -v (prebuilt PHP binary from php.net; I was able to reproduce the same behaviour on a macOS 10.15.6 using PHP 7.4.9 and XDebug 2.9.6) php.ini xdebug settings: Untouched, except for | ||||
Tags | No tags attached. | ||||
Operating System | Windows 10.0.19041.685 | ||||
PHP Version | 7.4.10-7.4.19 | ||||
|
Hi! Thanks for your report. This is expected behaviour that is undocumented. The algorithm that analyses code for unused and/or dead code only runs for functions, methods, and included scripts that are being executed after the call to <code>xdebug_start_code_coverage()</code> is made. Because you are inlining your code in the same script, the analysis for the script has not been run. If you would move your code into a function, or into a file that you include, you will see that it will correctly detect the unused lines and/or dead code. However, this is not documented at https://xdebug.org/docs/all_functions#xdebug_start_code_coverage so I'm leaving this open and I've reclassified it as a documentation bug. cheers, |
|
Hi Derick, thanks a lot for your explanation. Are you interested in me supplying a pull request to add this to the docs in https://github.com/xdebug/xdebug.org/blob/master/html/docs/include/functions/xdebug_start_code_coverage or is it something you would like to do on your own? Cheers, |
|
Hi, I saw your offer for a PR to document this after I had already pushed it, so there is no need for it. Thanks for offering it though! cheers, |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-12-16 02:16 | DeadApe | New Issue | |
2020-12-17 15:08 | derick | Category | Code Coverage => Documentation |
2020-12-17 15:08 | derick | Target Version | => 3.0dev |
2020-12-17 15:08 | derick | Note Added: 0005592 | |
2020-12-17 15:09 | derick | Status | new => confirmed |
2020-12-18 13:14 | DeadApe | Note Added: 0005596 | |
2020-12-18 14:52 | derick | Summary | Code Coverage return is missing out unused line even with XDEBUG_CC_UNUSED flag => Document that code coverage flags only affect new function scopes |
2020-12-18 14:52 | derick | Assigned To | => derick |
2020-12-18 14:52 | derick | Status | confirmed => closed |
2020-12-18 14:52 | derick | Resolution | open => fixed |
2020-12-18 14:52 | derick | Note Added: 0005600 |