Skip to content

Instantly share code, notes, and snippets.

@alx9r
Last active September 26, 2017 14:15
Show Gist options
  • Save alx9r/a738a04c6feae503dcb637af41370653 to your computer and use it in GitHub Desktop.
Save alx9r/a738a04c6feae503dcb637af41370653 to your computer and use it in GitHub Desktop.
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