Skip to content

Commit

Permalink
Merge pull request #152 from dlwyatt/AddFunctionToCoverageOutput
Browse files Browse the repository at this point in the history
Coverage output now also includes function name
  • Loading branch information
nohwnd committed Jul 7, 2014
2 parents e3a6a0d + c45ea92 commit fbc7643
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Functions/Coverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,34 @@ function New-CoverageBreakpoint

[pscustomobject] @{
File = $Command.Extent.File
Function = Get-ParentFunctionName -Ast $Command
Line = $Command.Extent.StartLineNumber
Command = Get-CoverageCommandText -Ast $Command
Breakpoint = $breakpoint
}
}

function Get-ParentFunctionName
{
param ([System.Management.Automation.Language.Ast] $Ast)

$parent = $Ast.Parent

while ($null -ne $parent -and $parent -isnot [System.Management.Automation.Language.FunctionDefinitionAst])
{
$parent = $parent.Parent
}

if ($null -eq $parent)
{
return ''
}
else
{
return $parent.Name
}
}

function Get-CoverageCommandText
{
param ([System.Management.Automation.Language.Ast] $Ast)
Expand Down Expand Up @@ -358,7 +380,7 @@ function Get-CoverageReport

$totalCommandCount = $PesterState.CommandCoverage.Count

$missedCommands = @(Get-CoverageMissedCommands -CommandCoverage $PesterState.CommandCoverage | Select-Object File, Line, Command)
$missedCommands = @(Get-CoverageMissedCommands -CommandCoverage $PesterState.CommandCoverage | Select-Object File, Line, Function, Command)
$analyzedFiles = @($PesterState.CommandCoverage | Select-Object -ExpandProperty File -Unique)
$fileCount = $analyzedFiles.Count

Expand Down

0 comments on commit fbc7643

Please sign in to comment.