-
-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncovered new line at end of file #799
Comments
Thank you for your report. Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting. Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue. |
I've created a small demo here: https://github.com/davidgrayston/phpunit-demo/tree/master/php-code-coverage-799 You can run |
PHP reports a line "14" for the implicit return at the end of a file. This is not a bug in php-code-coverage or Xdebug:
|
The introduction of this line in the report has affected coverage reporting on SonarCloud - should I follow this up with SonarCloud linking to this issue? |
I understand the issue is now closed (so I apologise for replying), but I thought it's worth mentioning that setting
I don't fully understand why this is happening - perhaps the file is loaded when gathering uncovered files (so executes the line at the end of the file), but not loaded again by the autoloader when running the tests. |
Notwithstanding the analysis by @derickr (thanks!), I think this should be reopened. I feel this is one of those cases where being technically correct is not the best kind of correct. There are few overlapping reasons:
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1598109988">
<project timestamp="1598109988">
<file name="C:\tmp\phpunit-demo\php-code-coverage-799\src\Demo.php">
<class name="DG\Demo" namespace="global">
<metrics complexity="1" methods="1" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="2" coveredelements="2"/>
</class>
<line num="9" type="method" name="hello" visibility="public" complexity="1" crap="1" count="1"/>
<line num="11" type="stmt" count="1"/>
<line num="14" type="stmt" count="0"/>
<metrics loc="13" ncloc="13" classes="1" methods="1" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="2" coveredelements="2"/>
</file>
<metrics files="1" loc="13" ncloc="13" classes="1" methods="1" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="2" coveredelements="2"/>
</project>
</coverage> Since every other part of the codebase (and developer expectation) seems to think that example file only has 13 lines, I think the clover report should be adjusted to match and strip off the last line of a file if it's empty to match. |
I would like to avoid handling this in the report(s) and rather clean up the data. |
It should be fixed in PHP. |
That's not true though, the line should show as covered if the file is included. |
When However, when [1] Loading of source files appears to be done before the test suite rather than after as a part of a Xdebug performance hack for dead code detection, see #433 and #384 |
I wonder whether we can get rid of the |
It's also completely possible that the preloading code isn't necessary anymore...looking at the original issue that added it, the justification was that a lot of time was spent doing analysis on code in Time for some benchmarking... |
As discussed in sebastianbergmann#799, this feature is no longer required because of Xdebug's built in filter
The PR in #800 will ensure that line 14 from this example has consistent raw data to work at least with regardless of internal settings @sebastianbergmann how do you want to resolve the wider issues? I see two questions:
|
As discussed in #799, this feature is no longer required because of Xdebug's built in filter
How about considering empty lines to be not executable in general? |
Seems that this bug is reintroduced in 9.1.7 - I look into |
Of course, the whole point of 9.1.7 was to revert this (so that it can be properly fixed later). See #805 (comment) for details. |
Since upgrading from PHPUnit
9.2
, new lines at the end of files are being reported as uncovered in the XML report, e.g.It seems to be caused by the removal of this workaround (as reinstating it fixes the clover report): d9c9b7b
The report is being consumed by SonarCloud - should the last line of files be ignored regardless of the uploaded XML report? If that's the case, I can raise an issue with SonarCloud.
The text was updated successfully, but these errors were encountered: