Skip to content

Commit

Permalink
Added Get-AstTopParent fn, ignore pipeline parts (#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
leojackson committed Oct 6, 2020
1 parent a575037 commit 4820503
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/functions/Coverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,25 @@ function New-CoverageBreakpoint {
}
}

Function Get-AstTopParent {
param(
[System.Management.Automation.Language.Ast] $Ast,
[int] $MaxDepth = 30
)

if ([string]::IsNullOrEmpty($Ast.Parent)) {
return $Ast
}
elseif ($MaxDepth -le 0) {
& $SafeCommands['Write-Verbose'] "Max depth reached, moving on"
return $null
}
else {
$MaxDepth--
Get-AstTopParent -Ast $Ast.Parent -MaxDepth $MaxDepth
}
}

function IsIgnoredCommand {
param ([System.Management.Automation.Language.Ast] $Command)

Expand All @@ -320,6 +339,15 @@ function IsIgnoredCommand {
}
}

if ($Command.Extent.Text -match '^{?& \$wrappedCmd @PSBoundParameters ?}?$' -and
(Get-AstTopParent -Ast $Command) -like '*$steppablePipeline.Begin($PSCmdlet)*$steppablePipeline.Process($_)*$steppablePipeline.End()*' ) {
# Fix for proxy function wrapped pipeline command. PowerShell does not increment the hit count when
# these functions are executed using the steppable pipeline; further, these checks are redundant, as
# all steppable pipeline constituents already get breakpoints set. This checks to ensure the top parent
# node of the command contains all three constituents of the steppable pipeline before ignoring it.
return $true
}

if (IsClosingLoopCondition -Command $Command) {
# For some reason, the closing expressions of do/while and do/until loops don't trigger their breakpoints.
# To avoid useless clutter, we'll ignore those lines as well.
Expand Down

0 comments on commit 4820503

Please sign in to comment.