-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Ensure -PipelineVariable is set for all output from script cmdlets #12766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,6 +256,62 @@ Describe "Parameter Binding Tests" -Tags "CI" { | |
| DynamicParamTest -PipelineVariable bar | ForEach-Object { $bar } | Should -Be "hi" | ||
| } | ||
|
|
||
| Context "PipelineVariable Behaviour" { | ||
|
|
||
| BeforeAll { | ||
| function Write-PipelineVariable { | ||
| [CmdletBinding()] | ||
| [OutputType([int])] | ||
| param( | ||
| [Parameter(ValueFromPipeline)] | ||
| $a | ||
| ) | ||
| begin { 1 } | ||
| process { 2 } | ||
| end { 3 } | ||
| } | ||
|
|
||
| $testScripts = @( | ||
|
||
| @{ | ||
| CmdletType = 'Script Cmdlet' | ||
| Script = { | ||
| 1..3 | | ||
| Write-PipelineVariable -PipelineVariable pipe | | ||
| Select-Object -Property @( | ||
| @{ Name = "PipelineVariableSet"; Expression = { $null -ne $pipe ? $true : $false } } | ||
| @{ Name = "PipelineVariable"; Expression = { $pipe } } | ||
| ) | ||
| } | ||
| } | ||
| @{ | ||
| CmdletType = 'Compiled Cmdlet' | ||
| Script = { | ||
| 1..3 | | ||
| Write-PipelineVariable | | ||
| ForEach-Object { $_ } -PipelineVariable pipe | | ||
| Select-Object -Property @( | ||
| @{ Name = "PipelineVariableSet"; Expression = { $null -ne $pipe ? $true : $false } } | ||
| @{ Name = "PipelineVariable"; Expression = { $pipe } } | ||
| ) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| AfterAll { | ||
| Remove-Item -Path 'function:Write-PipelineVariable' | ||
| } | ||
|
|
||
| It 'should set the pipeline variable every time for a <CmdletType>' -TestCases $testScripts { | ||
| param($Script, $CmdletType) | ||
|
|
||
| $result = & $Script | ||
| $result.Count | Should -Be 5 | ||
| $result.PipelineVariableSet | Should -Not -Contain $false | ||
| $result.PipelineVariable | Should -Be 1, 2, 2, 2, 3 | ||
| } | ||
| } | ||
|
|
||
| Context "Use automatic variables as default value for parameters" { | ||
| BeforeAll { | ||
| ## Explicit use of 'CmdletBinding' make it a script cmdlet | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.