Last active
September 26, 2017 14:15
-
-
Save alx9r/a738a04c6feae503dcb637af41370653 to your computer and use it in GitHub Desktop.
Test fixture for https://stackoverflow.com/q/46428736/1404637
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New-Module m { | |
function SomeScriptblockInvoker { | |
param | |
( | |
[Parameter(Position = 1)] | |
[scriptblock] | |
$Scriptblock, | |
[Parameter(ValueFromPipeline)] | |
$InputObject | |
) | |
process | |
{ | |
$modifiedLocal = 'variable name collision' | |
$local = 'variable name collision' | |
$InputObject | . $Scriptblock | |
} | |
} | |
} | | |
Import-Module | |
Describe command { | |
$sb = { | |
$modifiedLocal = 'modified local value' | |
[pscustomobject] @{ | |
Local = $local | |
DollarBar = $_ | |
} | |
} | |
foreach ( $commandName in 'ForEach-Object','SomeScriptblockInvoker' ) | |
{ | |
Context $commandName { | |
$modifiedLocal = 'original local value' | |
$local = 'local' | |
$r = 'input object' | & $commandName $sb | |
It 'Local is accessible' { | |
$r.Local | Should be 'local' | |
} | |
It 'DollarBar is input object' { | |
$r.DollarBar | Should be 'input object' | |
} | |
It 'modifies local variable' { | |
$modifiedLocal | Should be 'modified local value' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment