Skip to content

Commit 5e15a8d

Browse files
[rel/5.6.x] Fix NRE in mock debug log for native commands (#2481)
* Fix NRE in mock debug log for native commands * Exclude for commands without parameters --------- Co-authored-by: Frode Flaten <[email protected]>
1 parent 16f0f3b commit 5e15a8d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/functions/Mock.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ function Should-InvokeInternal {
411411
$nonMatchingCalls = [System.Collections.Generic.List[object]]@()
412412

413413
# Check for variables in ParameterFilter that already exists in session. Risk of conflict
414-
if ($PesterPreference.Debug.WriteDebugMessages.Value) {
414+
# Excluding native applications as they don't have parameters or metadata. Will always use $args
415+
if ($PesterPreference.Debug.WriteDebugMessages.Value -and
416+
$null -ne $ContextInfo.Hook.Metadata -and
417+
$ContextInfo.Hook.Metadata.Parameters.Count -gt 0) {
415418
$preExistingFilterVariables = @{}
416419
foreach ($v in $filter.Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.VariableExpressionAst] }, $true)) {
417420
if (-not $preExistingFilterVariables.ContainsKey($v.VariablePath.UserPath)) {

0 commit comments

Comments
 (0)