From be4bb938ab1e6f9edc007cd5e5109ec6668753b2 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 6 May 2025 10:14:24 -0700 Subject: [PATCH] Add more tests for `PSForEach` and `PSWhere` methods --- test/powershell/engine/ETS/Adapter.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/powershell/engine/ETS/Adapter.Tests.ps1 b/test/powershell/engine/ETS/Adapter.Tests.ps1 index 9e513b5d80e..f65b08f8174 100644 --- a/test/powershell/engine/ETS/Adapter.Tests.ps1 +++ b/test/powershell/engine/ETS/Adapter.Tests.ps1 @@ -204,6 +204,12 @@ Describe "Adapter Tests" -tags "CI" { It "Can use PSForEach as an alias for the Foreach magic method" { $x = 5 $x.PSForEach({$_}) | Should -Be 5 + + $p = $null.PSForEach{"I didn't run"} + $p.GetType().Name | Should -BeExactly 'Collection`1' + $p.Count | Should -BeExactly 0 + + ([pscustomobject]@{ Name = 'bar' }).PSForEach({$_.Name}) | Should -BeExactly 'bar' } } @@ -249,6 +255,12 @@ Describe "Adapter Tests" -tags "CI" { It "Can use PSWhere as an alias for the Where magic method" { $x = 5 $x.PSWhere{$true} | Should -Be 5 + + $p = $null.PSWhere{"I didn't run"} + $p.GetType().Name | Should -BeExactly 'Collection`1' + $p.Count | Should -BeExactly 0 + + ([pscustomobject]@{ Name = 'bar' }).PSWhere({$_.Name}) | ForEach-Object Name | Should -BeExactly 'bar' } } }