From d748e6fc4dd98dc76205dee021ef2979eaadb7e0 Mon Sep 17 00:00:00 2001 From: Todd Brown Date: Thu, 14 Feb 2019 13:35:09 -0600 Subject: [PATCH 1/3] Fix incorrect Code Coverage report counters when there are multiple packages in the report. (#1242) --- Functions/Coverage.Tests.ps1 | 58 +++++++++++++++++++++++++++++------- Functions/Coverage.ps1 | 24 ++++++++++++--- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/Functions/Coverage.Tests.ps1 b/Functions/Coverage.Tests.ps1 index 5a1edf4a7..5ed76b95f 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 SubFolder + $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 = '' From 3035866e5d1a33cc9b7e263a24f7a46edfe942b2 Mon Sep 17 00:00:00 2001 From: Todd Brown Date: Fri, 15 Feb 2019 09:05:43 -0600 Subject: [PATCH 2/3] Updated TestScript3.ps1 subFolder name to get consistent cross-platform test file name sorting (#1242) --- Functions/Coverage.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Functions/Coverage.Tests.ps1 b/Functions/Coverage.Tests.ps1 index 5ed76b95f..fcdb9e225 100644 --- a/Functions/Coverage.Tests.ps1 +++ b/Functions/Coverage.Tests.ps1 @@ -14,7 +14,7 @@ InModuleScope Pester { Describe 'Code Coverage Analysis' { $root = (Get-PSDrive TestDrive).Root - $rootSubFolder = Join-Path -Path $root -ChildPath SubFolder + $rootSubFolder = Join-Path -Path $root -ChildPath TestSubFolder $null = New-Item -Path $rootSubFolder -ItemType Directory -ErrorAction SilentlyContinue $testScriptPath = Join-Path -Path $root -ChildPath TestScript.ps1 @@ -287,8 +287,8 @@ InModuleScope Pester { - - + + From 479fffad4af138b9354267cf50124dfd27215023 Mon Sep 17 00:00:00 2001 From: Todd Brown Date: Fri, 15 Feb 2019 09:28:09 -0600 Subject: [PATCH 3/3] Empty commit to tigger builds (#1242)