-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
Implement Cobertura coverage format #2298
Conversation
Also, it seems that the XML attributes don't always have consistent ordering when the XML is serialized. This is currently failing the tests. Does anyone know how we could get past this?
|
Thanks for looking into this so fast! :) |
After fixing all the build failures (related to multiple PS versions and OSs), I re-ran this branch to produce a Cobertura report against my other project and compared it to the HTML report I previously generated from the JaCoCo option. Everything seems to match up (whew!). |
@joeskeen just checked it, looks good to me! Again, thanks for your help and work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments below. As mentioned, I'm not an expert on coverage and haven't tested this format, so I might be wrong.
Still, it feels like line-elements are unnecessarily duplicated in the report and should only be reported once per method or class. Though it might work fine, it would cause large files
@fflaten thanks for the thorough review. I did some more testing yesterday and found that there were a lot of problems with my initial implementation. So yesterday I started from scratch and I'm liking it much better. I'll push the changes shortly after I address a couple linting issues. |
@fflaten (or others) - my last remaining linting error is
What is the suggested alternative for Edit: maybe this isn't an issue, I just found that |
Looks like using |
A replacement depends on each scenario, but often If you can avoid them, that's great, but it's not critical in this code as it's only executed once in post-process. The rule is there to highlight potential performance issues in the runtime for code executed 100s or 1000s of times. 🙂 Please let me know when it's ready for review again. |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, few nitpicks.
I was going to fix this PR but you beat me to it @fflaten . Makes sense to backport to v5? |
Felt this was a "you break it, you buy it" scenario 😄 Started testing it with ReportGenerator and got same HTML report with JaCoCo and Cobertura which is good. Haven't tested multiple source paths yet as I got distracted by weird codecov results like no coverage for BeLessThan (tested tst/functions against src/functions) in both formats. Not too familiar with CC so please help testdrive it.
Yes |
I will try to test drive it, but not today. :) And sorry @joeskeen for taking so long to merge this. |
Co-authored-by: Jakub Jareš <[email protected]>
# Report uses unix epoch time format (milliseconds since midnight 1/1/1970 UTC) | ||
[long] $endTime = [System.DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() | ||
[long] $startTime = [math]::Floor($endTime - $TotalMilliseconds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Source for epoch time format: https://github.com/cobertura/cobertura/blob/0ff963284cecaace30f409a977dccb07c41a5a8f/cobertura/src/main/java/net/sourceforge/cobertura/reporting/xml/XMLReport.java#L89
Backport version will need to use:
$nineteenSeventy = & $SafeCommands['New-Object'] 'System.DateTime' -ArgumentList @(1970, 1, 1, 0, 0, 0, [System.DateTimeKind]::Utc)
$now = [DateTime]::Now.ToUniversalTime()
[long] $endTime = [math]::Floor(($now - $nineteenSeventy).TotalMilliseconds)
[long] $startTime = [math]::Floor($endTime - $TotalMilliseconds)
# Report uses unix epoch time format (milliseconds since midnight 1/1/1970 UTC) | ||
[long] $endTime = [System.DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nohwnd I included this bugfix for JaCoCo as well. [DateTime]"01/01/1970"
is not proper epoch origin (missing UTC kind), so off by one hour in my timezone.
Source for epoch time format:
https://github.com/jacoco/jacoco/blob/77d2af5ec31faf04419d945e1a0c34da49f8a702/org.jacoco.core/src/org/jacoco/core/data/SessionInfo.java#L33-L38
Backport version will need to use:
$nineteenSeventy = & $SafeCommands['New-Object'] 'System.DateTime' -ArgumentList @(1970, 1, 1, 0, 0, 0, [System.DateTimeKind]::Utc)
$now = [DateTime]::Now.ToUniversalTime()
[long] $endTime = [math]::Floor(($now - $nineteenSeventy).TotalMilliseconds)
[long] $startTime = [math]::Floor($endTime - $TotalMilliseconds)
TODO: Need to update the hardcoded report in |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
You were right, it is all broken now 😅 |
Hard-coded reports = The gift that keeps on giving 🙏 Fixed and ready for test & review. |
* wip: Implement Cobertura coverage format * fix unit test * revert editor settings change * remove ?? operator * fix attribute ordering * make coverage report test work on all platforms * Fix windows paths * fix unit test for Windows paths * kick the build * re-implement Cobertura coverage report generation * fix compatibility issues * fix tests * removing Cobertura from v4 parameter options * fix compatibility with ReportGenerator * Update src/functions/Coverage.ps1 Co-authored-by: Frode Flaten <[email protected]> * fix whitespace * fix output * fix windows paths * order packages,classes,methods by name * change Cobertura DTD to loose * Tune coverage report for performance * Remove outdated condition * Add Cobertura DTD file * Apply suggestions from code review Co-authored-by: Jakub Jareš <[email protected]> * Fix typo and update JaCoCo starttime * Fix tests * Use epoch time for Cobertura and JaCoCo * Update test --------- Co-authored-by: Frode Flaten <[email protected]> Co-authored-by: Jakub Jareš <[email protected]>
* Implement Cobertura coverage format (#2298) * wip: Implement Cobertura coverage format * fix unit test * revert editor settings change * remove ?? operator * fix attribute ordering * make coverage report test work on all platforms * Fix windows paths * fix unit test for Windows paths * kick the build * re-implement Cobertura coverage report generation * fix compatibility issues * fix tests * removing Cobertura from v4 parameter options * fix compatibility with ReportGenerator * Update src/functions/Coverage.ps1 Co-authored-by: Frode Flaten <[email protected]> * fix whitespace * fix output * fix windows paths * order packages,classes,methods by name * change Cobertura DTD to loose * Tune coverage report for performance * Remove outdated condition * Add Cobertura DTD file * Apply suggestions from code review Co-authored-by: Jakub Jareš <[email protected]> * Fix typo and update JaCoCo starttime * Fix tests * Use epoch time for Cobertura and JaCoCo * Update test --------- Co-authored-by: Frode Flaten <[email protected]> Co-authored-by: Jakub Jareš <[email protected]> * Ignore call base class contructor in code coverage (#2553) * Ignore calls to base class constructor in code coverage * Update tests * Unix timestamps with supported apis * Add info about mode * output bps * output bps * output bps * What if we don't call it? * Revert "What if we don't call it?" This reverts commit 1c03a6b. * bsclass --------- Co-authored-by: Joe Skeen <[email protected]> Co-authored-by: Frode Flaten <[email protected]>
PR Summary
Cobertura is a commonly used code coverage format, and has been requested as a feature: #2203
Fix #2203
To implement this feature, I copy-pasted the JaCoCo code and modified it to produce the required XML structure for Cobertura.
I am not an expert on the Cobertura format, but I did reference their DTD and the Cobertura output from my TypeScript project that uses
jest-junit
. If anyone is able to review it for correctness, I would greatly appreciate it. A good place to analyze the output is the unit test I added, where you can compare the JaCoCo output directly above it to the new Cobertura output (I used the same inputs for both reports).PR Checklist
Create Pull Request
to mark it as a draft. PR can be markedReady for review
when it's ready.