Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Functions/Mock.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1328,3 +1328,18 @@ Describe 'When mocking a command that has an ArgumentList parameter with validat
$hash.Result | Should Be 'mocked'
}
}

# These assertions won't actually "fail"; we had an infinite recursion bug in Get-DynamicParametersForCmdlet
# if the caller mocked New-Object. It should be fixed by making that call to New-Object module-qualified,
# and this test will make sure it's working properly. If this test fails, it'll take a really long time
# to execute, and then will throw a stack overflow error.

Describe 'Mocking New-Object' {
It 'Works properly' {
Mock New-Object

$result = New-Object -TypeName Object
$result | Should Be $null
Assert-MockCalled New-Object
}
}
2 changes: 1 addition & 1 deletion Functions/Mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ function Get-DynamicParametersForCmdlet
$PSCmdlet.ThrowTerminatingError($_)
}

$cmdlet = New-Object $command.ImplementingType.FullName
$cmdlet = Microsoft.PowerShell.Utility\New-Object $command.ImplementingType.FullName
if ($cmdlet -isnot [System.Management.Automation.IDynamicParameters])
{
return
Expand Down