Skip to content

Commit

Permalink
Fix failure on zero analyzed commands (pester#2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Jun 17, 2021
1 parent 268fddf commit 4d79ce5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/functions/Coverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ function Get-JaCoCoReportXml {
$isGutters = "CoverageGutters" -eq $Format

if ($null -eq $CoverageReport -or ($pester.Show -eq [Pester.OutputTypes]::None) -or $CoverageReport.NumberOfCommandsAnalyzed -eq 0) {
return
return [string]::Empty
}

$now = & $SafeCommands['Get-Date']
Expand Down
7 changes: 7 additions & 0 deletions tst/functions/Coverage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,13 @@ InPesterModuleScope {
')
}

It 'JaCoCo returns empty string when there are 0 analyzed commands' {
$coverageReport = [PSCustomObject] @{ NumberOfCommandsAnalyzed = 0 }
[String]$jaCoCoReportXml = Get-JaCoCoReportXml -CommandCoverage @{} -TotalMilliseconds 10000 -CoverageReport $coverageReport -Format "CoverageGutters"
$jaCoCoReportXml | Should -Not -Be $null
$jaCoCoReportXml | Should -Be ([String]::Empty)
}

It 'Reports the right line numbers' {
$coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted - 1].Line | Should -Be 1
$coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted - 1].StartLine | Should -Be 1
Expand Down

0 comments on commit 4d79ce5

Please sign in to comment.