-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test: raise Humanizer coverage above 99 percent #1727
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18bcca9
test: raise Humanizer coverage above 99 percent
clairernovotny 4568d13
refactor: lower generated catalog branch complexity
clairernovotny fa1c814
test: cover formatter branch hotspots
clairernovotny 1d4f384
test: cover Spanish ordinal branch hotspots
clairernovotny 6298523
test: cover analyzer and generator edge cases
clairernovotny 4b3d0ef
test: normalize generator migration assertions
clairernovotny fd79751
test: cover additional coverage hotspots
clairernovotny 810a989
test: remove redundant billion generator fixture
clairernovotny 2ab20af
test: address catalog null lookup feedback
clairernovotny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| [string[]] $Reports, | ||
|
|
||
| [int] $Top = 25, | ||
|
|
||
| [string] $JsonOutputPath | ||
| ) | ||
|
|
||
| Set-StrictMode -Version 3.0 | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| function Get-AttributeValue { | ||
| param( | ||
| [System.Xml.XmlElement] $Element, | ||
| [string] $Name | ||
| ) | ||
|
|
||
| $value = $Element.GetAttribute($Name) | ||
| if ([string]::IsNullOrWhiteSpace($value)) { | ||
| return $null | ||
| } | ||
|
|
||
| return $value | ||
| } | ||
|
|
||
| $files = foreach ($report in $Reports) { | ||
| Get-ChildItem -Path $report -File | ||
| } | ||
|
|
||
| if (-not $files) { | ||
| throw "No Cobertura reports matched: $($Reports -join ', ')" | ||
| } | ||
|
|
||
| $byFile = @{} | ||
|
|
||
| foreach ($file in $files) { | ||
| [xml] $document = Get-Content -LiteralPath $file.FullName -Raw | ||
| foreach ($class in $document.coverage.packages.package.classes.class) { | ||
| $sourceFile = Get-AttributeValue $class 'filename' | ||
| if ([string]::IsNullOrWhiteSpace($sourceFile)) { | ||
| continue | ||
| } | ||
|
|
||
| if (-not $byFile.ContainsKey($sourceFile)) { | ||
| $byFile[$sourceFile] = [ordered]@{ | ||
| file = $sourceFile | ||
| coveredBranches = 0 | ||
| totalBranches = 0 | ||
| missedBranches = 0 | ||
| lines = @{} | ||
| } | ||
| } | ||
|
|
||
| foreach ($line in $class.lines.line) { | ||
| if ((Get-AttributeValue $line 'branch') -ne 'True') { | ||
| continue | ||
| } | ||
|
|
||
| $coverage = Get-AttributeValue $line 'condition-coverage' | ||
| if ($coverage -notmatch '\((\d+)/(\d+)\)') { | ||
| continue | ||
| } | ||
|
|
||
| $covered = [int] $Matches[1] | ||
| $total = [int] $Matches[2] | ||
| $missed = $total - $covered | ||
| $lineNumber = [int] (Get-AttributeValue $line 'number') | ||
| $entry = $byFile[$sourceFile] | ||
| $entry.coveredBranches += $covered | ||
| $entry.totalBranches += $total | ||
| $entry.missedBranches += $missed | ||
|
|
||
| if ($missed -gt 0) { | ||
| if (-not $entry.lines.ContainsKey($lineNumber)) { | ||
| $entry.lines[$lineNumber] = [ordered]@{ | ||
| line = $lineNumber | ||
| coveredBranches = 0 | ||
| totalBranches = 0 | ||
| missedBranches = 0 | ||
| } | ||
| } | ||
|
|
||
| $lineEntry = $entry.lines[$lineNumber] | ||
| $lineEntry.coveredBranches += $covered | ||
| $lineEntry.totalBranches += $total | ||
| $lineEntry.missedBranches += $missed | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $hotspots = $byFile.Values | | ||
| Where-Object { $_.missedBranches -gt 0 } | | ||
| ForEach-Object { | ||
| [pscustomobject] [ordered]@{ | ||
| file = $_.file | ||
| branchCoverage = [Math]::Round(100.0 * $_.coveredBranches / $_.totalBranches, 2) | ||
| coveredBranches = $_.coveredBranches | ||
| totalBranches = $_.totalBranches | ||
| missedBranches = $_.missedBranches | ||
| missedLines = @($_.lines.Values | | ||
| ForEach-Object { [pscustomobject] $_ } | | ||
| Sort-Object @{ Expression = 'missedBranches'; Descending = $true }, @{ Expression = 'line'; Ascending = $true } | | ||
| Select-Object -First 10) | ||
| } | ||
| } | | ||
| Sort-Object @{ Expression = 'missedBranches'; Descending = $true }, @{ Expression = 'totalBranches'; Descending = $true } | | ||
| Select-Object -First $Top | ||
|
|
||
| $summary = [ordered]@{ | ||
| reports = @($files.FullName) | ||
| totalFilesWithMissedBranches = ($byFile.Values | Where-Object { $_.missedBranches -gt 0 }).Count | ||
| hotspots = @($hotspots) | ||
| } | ||
|
|
||
| if ($JsonOutputPath) { | ||
| $summary | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $JsonOutputPath -Encoding UTF8 | ||
| } | ||
|
|
||
| "Missed Branch Hotspots" | ||
| "======================" | ||
| foreach ($hotspot in $hotspots) { | ||
| "{0,5} missed {1,5}/{2,-5} {3,6:N2}% {4}" -f $hotspot.missedBranches, $hotspot.coveredBranches, $hotspot.totalBranches, $hotspot.branchCoverage, $hotspot.file | ||
| foreach ($line in $hotspot.missedLines) { | ||
| " L{0}: {1}/{2} covered, {3} missed" -f $line.line, $line.coveredBranches, $line.totalBranches, $line.missedBranches | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.