diff --git a/Functions/Coverage.Tests.ps1 b/Functions/Coverage.Tests.ps1
index 5a1edf4a7..fcdb9e225 100644
--- a/Functions/Coverage.Tests.ps1
+++ b/Functions/Coverage.Tests.ps1
@@ -14,8 +14,12 @@ InModuleScope Pester {
Describe 'Code Coverage Analysis' {
$root = (Get-PSDrive TestDrive).Root
+ $rootSubFolder = Join-Path -Path $root -ChildPath TestSubFolder
+ $null = New-Item -Path $rootSubFolder -ItemType Directory -ErrorAction SilentlyContinue
+
$testScriptPath = Join-Path -Path $root -ChildPath TestScript.ps1
$testScript2Path = Join-Path -Path $root -ChildPath TestScript2.ps1
+ $testScript3Path = Join-Path -Path $rootSubFolder -ChildPath TestScript3.ps1
$null = New-Item -Path $testScriptPath -ItemType File -ErrorAction SilentlyContinue
@@ -109,32 +113,42 @@ InModuleScope Pester {
-f `
'other'
+'@
+
+ $null = New-Item -Path $testScript3Path -ItemType File -ErrorAction SilentlyContinue
+
+ Set-Content -Path $testScript3Path -Value @'
+ 'Some {0} file' `
+ -f `
+ 'other'
+
'@
Context 'Entire file' {
$testState = New-PesterState -Path $root
# Path deliberately duplicated to make sure the code doesn't produce multiple breakpoints for the same commands
- Enter-CoverageAnalysis -CodeCoverage $testScriptPath, $testScriptPath, $testScript2Path -PesterState $testState
+ Enter-CoverageAnalysis -CodeCoverage $testScriptPath, $testScriptPath, $testScript2Path, $testScript3Path -PesterState $testState
It 'Has the proper number of breakpoints defined' {
- $testState.CommandCoverage.Count | Should -Be 17
+ $testState.CommandCoverage.Count | Should -Be 18
}
$null = & $testScriptPath
$null = & $testScript2Path
+ $null = & $testScript3Path
$coverageReport = Get-CoverageReport -PesterState $testState
It 'Reports the proper number of executed commands' {
- $coverageReport.NumberOfCommandsExecuted | Should -Be 14
+ $coverageReport.NumberOfCommandsExecuted | Should -Be 15
}
It 'Reports the proper number of analyzed commands' {
- $coverageReport.NumberOfCommandsAnalyzed | Should -Be 17
+ $coverageReport.NumberOfCommandsAnalyzed | Should -Be 18
}
It 'Reports the proper number of analyzed files' {
- $coverageReport.NumberOfFilesAnalyzed | Should -Be 2
+ $coverageReport.NumberOfFilesAnalyzed | Should -Be 3
}
It 'Reports the proper number of missed commands' {
@@ -148,7 +162,7 @@ InModuleScope Pester {
}
It 'Reports the proper number of hit commands' {
- $coverageReport.HitCommands.Count | Should -Be 14
+ $coverageReport.HitCommands.Count | Should -Be 15
}
It 'Reports the correct hit command' {
@@ -273,10 +287,34 @@ InModuleScope Pester {
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
')
}
diff --git a/Functions/Coverage.ps1 b/Functions/Coverage.ps1
index 695660874..763c04e23 100644
--- a/Functions/Coverage.ps1
+++ b/Functions/Coverage.ps1
@@ -592,6 +592,13 @@ function Get-JaCoCoReportXml {
$packageList = & $SafeCommands['New-Object'] System.Collections.Generic.List[psobject]
+ $report = @{
+ Instruction = @{ Missed = 0; Covered = 0 }
+ Line = @{ Missed = 0; Covered = 0 }
+ Method = @{ Missed = 0; Covered = 0 }
+ Class = @{ Missed = 0; Covered = 0 }
+ }
+
foreach ($folderGroup in $folderGroups) {
$package = @{
@@ -660,6 +667,15 @@ function Get-JaCoCoReportXml {
$package.Classes.$file.Lines.$line.Instruction.Covered += $covered
}
+ $report.Class.Missed += $package.Class.Missed
+ $report.Class.Covered += $package.Class.Covered
+ $report.Method.Missed += $package.Method.Missed
+ $report.Method.Covered += $package.Method.Covered
+ $report.Line.Missed += $package.Line.Missed
+ $report.Line.Covered += $package.Line.Covered
+ $report.Instruction.Missed += $package.Instruction.Missed
+ $report.Instruction.Covered += $package.Instruction.Covered
+
$packageList.Add($package)
}
@@ -746,10 +762,10 @@ function Get-JaCoCoReportXml {
Add-JaCoCoCounter Class $package $packageElement
}
- Add-JaCoCoCounter Instruction $package $reportElement
- Add-JaCoCoCounter Line $package $reportElement
- Add-JaCoCoCounter Method $package $reportElement
- Add-JaCoCoCounter Class $package $reportElement
+ Add-JaCoCoCounter Instruction $report $reportElement
+ Add-JaCoCoCounter Line $report $reportElement
+ Add-JaCoCoCounter Method $report $reportElement
+ Add-JaCoCoCounter Class $report $reportElement
# There is no pretty way to insert the Doctype, as microsoft has deprecated the DTD stuff.
$jaCoCoReportDocType = ''