Skip to content

Commit

Permalink
Fix NRE in mock debug log for native commands (#2480)
Browse files Browse the repository at this point in the history
* Fix NRE in mock debug log for native commands

* Exclude for commands without parameters
  • Loading branch information
fflaten authored May 21, 2024
1 parent b577d1b commit 2d6418b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/functions/Mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,10 @@ function Should-InvokeInternal {
$nonMatchingCalls = [System.Collections.Generic.List[object]]@()

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

0 comments on commit 2d6418b

Please sign in to comment.