@@ -256,6 +256,62 @@ Describe "Parameter Binding Tests" -Tags "CI" {
256256 DynamicParamTest - PipelineVariable bar | ForEach-Object { $bar } | Should - Be " hi"
257257 }
258258
259+ Context " PipelineVariable Behaviour" {
260+
261+ BeforeAll {
262+ function Write-PipelineVariable {
263+ [CmdletBinding ()]
264+ [OutputType ([int ])]
265+ param (
266+ [Parameter (ValueFromPipeline )]
267+ $a
268+ )
269+ begin { 1 }
270+ process { 2 }
271+ end { 3 }
272+ }
273+
274+ $testScripts = @ (
275+ @ {
276+ CmdletType = ' Script Cmdlet'
277+ Script = {
278+ 1 .. 3 |
279+ Write-PipelineVariable - PipelineVariable pipe |
280+ Select-Object - Property @ (
281+ @ { Name = " PipelineVariableSet" ; Expression = { $null -ne $pipe ? $true : $false } }
282+ @ { Name = " PipelineVariable" ; Expression = { $pipe } }
283+ )
284+ }
285+ }
286+ @ {
287+ CmdletType = ' Compiled Cmdlet'
288+ Script = {
289+ 1 .. 3 |
290+ Write-PipelineVariable |
291+ ForEach-Object { $_ } - PipelineVariable pipe |
292+ Select-Object - Property @ (
293+ @ { Name = " PipelineVariableSet" ; Expression = { $null -ne $pipe ? $true : $false } }
294+ @ { Name = " PipelineVariable" ; Expression = { $pipe } }
295+ )
296+ }
297+ }
298+ )
299+ }
300+
301+ AfterAll {
302+ Remove-Item - Path ' function:Write-PipelineVariable'
303+ }
304+
305+ It ' should set the pipeline variable every time for a <CmdletType>' - TestCases $testScripts {
306+ param ($Script , $CmdletType )
307+
308+ $result = & $Script
309+ $result.Count | Should - Be 5
310+ $result.PipelineVariableSet | Should -Not - Contain $false
311+ $result.PipelineVariable | Should - Be 1 , 2 , 2 , 2 , 3
312+ }
313+ }
314+
259315 Context " Use automatic variables as default value for parameters" {
260316 BeforeAll {
261317 # # Explicit use of 'CmdletBinding' make it a script cmdlet
0 commit comments