From 88ed36245500eb33e9bae129683ee011ca86228b Mon Sep 17 00:00:00 2001 From: Raimund Andree Date: Sun, 11 Oct 2026 11:02:53 +0000 Subject: [PATCH] test(items): assert that Get-ChildItem2 restores the culture of the caller The tr-TR test reset the culture in its own finally block, so a cmdlet that did not restore it, or that wrote an item inside the scope of the invariant culture, would still pass. The test now reads the culture in the next pipeline stage for each item and once more after the call. Both mutations fail it: writing the item inside the scope, and leaving the scope without restoring the culture. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: AI Assistant --- Tests/ItemCmdlets.Tests.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tests/ItemCmdlets.Tests.ps1 b/Tests/ItemCmdlets.Tests.ps1 index 9adbfe5..e6a1e4a 100644 --- a/Tests/ItemCmdlets.Tests.ps1 +++ b/Tests/ItemCmdlets.Tests.ps1 @@ -180,13 +180,20 @@ Describe 'Get-ChildItem2' { [System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('tr-TR') 'I'.ToLower() | Should -Be ([string][char]0x131) -Because 'the culture of the thread has to be Turkish for the test to mean anything' - $result = @(Get-ChildItem2 -Path $folder -Filter $Filter -ErrorAction Stop) + # The next stage of the pipeline reads the culture of the thread for each item, and the test reads it once more + # after the cmdlet has returned: Turkish both times shows that the cmdlet restores the culture and writes no + # item inside the scope of the invariant culture. + $result = @(Get-ChildItem2 -Path $folder -Filter $Filter -ErrorAction Stop | + ForEach-Object -Process { [pscustomobject]@{ Name = $_.Name; Culture = [System.Threading.Thread]::CurrentThread.CurrentCulture.Name } }) + $cultureAfter = [System.Threading.Thread]::CurrentThread.CurrentCulture.Name } finally { [System.Threading.Thread]::CurrentThread.CurrentCulture = $original } ($result.Name | Sort-Object) -join ',' | Should -BeExactly $Expected + (@($result.Culture) | Select-Object -Unique) -join ',' | Should -BeExactly 'tr-TR' -Because 'the cmdlet writes each item outside the scope of the invariant culture' + $cultureAfter | Should -BeExactly 'tr-TR' -Because 'the cmdlet restores the culture of the caller' } # Only * and ? are wildcards in -Filter. A bracket stands for itself, so a file with brackets in its name is found