diff --git a/Functions/Coverage.Tests.ps1 b/Functions/Coverage.Tests.ps1 index ffdd9d29b..197b2590d 100644 --- a/Functions/Coverage.Tests.ps1 +++ b/Functions/Coverage.Tests.ps1 @@ -40,7 +40,9 @@ InModuleScope Pester { $null = New-Item -Path $(Join-Path -Path $root -ChildPath TestScript2.ps1) -ItemType File -ErrorAction SilentlyContinue Set-Content -Path $(Join-Path -Path $root -ChildPath TestScript2.ps1) -Value @' - 'Some other file' + 'Some {0} file' ` + -f ` + 'other' '@ @@ -96,6 +98,18 @@ InModuleScope Pester { $jaCoCoReportXml = $jaCoCoReportXml.Replace($root.Replace('\', '/'), '') $jaCoCoReportXml | should -be '' } + + It 'Reports the right line numbers' { + $coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted-1].Line | Should -Be 1 + $coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted-1].StartLine | Should -Be 1 + $coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted-1].EndLine | Should -Be 3 + } + + It 'Reports the right column numbers' { + $coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted-1].StartColumn | Should -Be 13 + $coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted-1].EndColumn | Should -Be 24 + } + Exit-CoverageAnalysis -PesterState $testState } diff --git a/Functions/Coverage.ps1 b/Functions/Coverage.ps1 index 3add209f7..9cd02d41c 100644 --- a/Functions/Coverage.ps1 +++ b/Functions/Coverage.ps1 @@ -282,11 +282,14 @@ function New-CoverageBreakpoint $breakpoint = & $SafeCommands['Set-PSBreakpoint'] @params [pscustomobject] @{ - File = $Command.Extent.File - Function = Get-ParentFunctionName -Ast $Command - Line = $Command.Extent.StartLineNumber - Command = Get-CoverageCommandText -Ast $Command - Breakpoint = $breakpoint + File = $Command.Extent.File + Function = Get-ParentFunctionName -Ast $Command + StartLine = $Command.Extent.StartLineNumber + EndLine = $Command.Extent.EndLineNumber + StartColumn = $Command.Extent.StartColumnNumber + EndColumn = $Command.Extent.EndColumnNumber + Command = Get-CoverageCommandText -Ast $Command + Breakpoint = $breakpoint } } @@ -484,24 +487,28 @@ function Get-CoverageReport { param ([object] $PesterState) - $totalCommandCount = $PesterState.CommandCoverage.Count - - $missedCommands = @(Get-CoverageMissedCommands -CommandCoverage $PesterState.CommandCoverage | & $SafeCommands['Select-Object'] File, Line, Function, Command) - $hitCommands = @(Get-CoverageHitCommands -CommandCoverage $PesterState.CommandCoverage | & $SafeCommands['Select-Object'] File, Line, Function, Command) - $allCommands = @($PesterState.CommandCoverage | & $SafeCommands['Select-Object'] File, Line, Function, Command, Breakpoint) + $properties = @( + 'File' + @{ Name = 'Line'; Expression = { $_.StartLine } } + 'StartLine' + 'EndLine' + 'StartColumn' + 'EndColumn' + 'Function' + 'Command' + @{ Name = 'HitCount'; Expression = { $_.Breakpoint.HitCount } } + ) + $missedCommands = @(Get-CoverageMissedCommands -CommandCoverage $PesterState.CommandCoverage | & $SafeCommands['Select-Object'] $properties) + $hitCommands = @(Get-CoverageHitCommands -CommandCoverage $PesterState.CommandCoverage | & $SafeCommands['Select-Object'] $properties) $analyzedFiles = @($PesterState.CommandCoverage | & $SafeCommands['Select-Object'] -ExpandProperty File -Unique) - $fileCount = $analyzedFiles.Count - - $executedCommandCount = $totalCommandCount - $missedCommands.Count [pscustomobject] @{ - NumberOfCommandsAnalyzed = $totalCommandCount - NumberOfFilesAnalyzed = $fileCount - NumberOfCommandsExecuted = $executedCommandCount + NumberOfCommandsAnalyzed = $PesterState.CommandCoverage.Count + NumberOfFilesAnalyzed = $analyzedFiles.Count + NumberOfCommandsExecuted = $hitCommands.Count NumberOfCommandsMissed = $missedCommands.Count MissedCommands = $missedCommands HitCommands = $hitCommands - AllCommands = $allCommands AnalyzedFiles = $analyzedFiles } } @@ -610,7 +617,7 @@ function Get-JaCoCoReportXml { $file = $command.File $function = $command.Function if (!$function) { $function = '