Skip to content

Commit

Permalink
Added failing test
Browse files Browse the repository at this point in the history
Repro for pester#353 in PowerShell 2.0.  I wasn't able to reproduce this using a function for some reason, but mocking Start-Process does cause the error to occur.

Incidentally, it's being caused by this line in MockPrototype:

[object] $ArgumentList = Get-Variable -Name args -ValueOnly -Scope Local -ErrorAction $IgnoreErrorPreference

It appears to be a problem when the mocked command also has an -ArgumentList parameter, which contains Validation attributes such as ValidateNotNullOrEmpty() (though why I wasn't able to reproduce this with a mocked function instead of Start-Process, I don't know.)
  • Loading branch information
dlwyatt committed May 18, 2015
1 parent 51d1eb3 commit c7c83d6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Functions/Mock.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,15 @@ Describe 'Mocking commands with potentially ambigious parameter sets' {
Assert-MockCalled SomeFunction -ParameterFilter { $p1 -eq 'Whatever' }
}
}

Describe 'When mocking a command that has an ArgumentList parameter with validation' {
Mock Start-Process { return 'mocked' }

It 'Calls the mock properly' {
$hash = @{ Result = $null }
$scriptBlock = { $hash.Result = Start-Process -FilePath cmd.exe -ArgumentList '/c dir c:\' }

$scriptBlock | Should Not Throw
$hash.Result | Should Be 'mocked'
}
}

0 comments on commit c7c83d6

Please sign in to comment.