MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Out-Default Tests" -Tag CI {4 BeforeAll {5 # due to https://github.com/PowerShell/PowerShell/issues/3405, `Out-Default -Transcript` emits output to pipeline6 # as running in Pester effectively wraps everything in parenthesis, workaround is to use another powershell7 # to run the test script passed as a string8 $powershell = "$PSHOME/pwsh"9 }10 11 It "'Out-Default -Transcript' shows up in transcript, but not host" {12 $script = @"13 `$null = Start-Transcript -Path "$testdrive\transcript.txt";14 'hello' | Microsoft.PowerShell.Core\Out-Default -Transcript;15 'bye';16 `$null = Stop-Transcript17"@18 19 & $powershell -noprofile -command $script | Should -BeExactly 'bye'20 "TestDrive:\transcript.txt" | Should -FileContentMatch 'hello'21 }22 23 It "Out-Default reverts transcription state when used more than once in a pipeline" {24 & $powershell -noprofile -command "Out-Default -Transcript | Out-Default -Transcript; 'Hello'" | Should -BeExactly "Hello"25 }26 27 It "Out-Default reverts transcription state when exception occurs in pipeline" {28 & $powershell -noprofile -command "try { & { throw } | Out-Default -Transcript } catch {}; 'Hello'" | Should -BeExactly "Hello"29 }30 31 It "Out-Default reverts transcription state even if Dispose() isn't called" {32 $script = @"33 `$sp = {Out-Default -Transcript}.GetSteppablePipeline();34 `$sp.Begin(`$false);35 `$sp = `$null;36 [GC]::Collect();37 [GC]::WaitForPendingFinalizers();38 'hello'39"@40 & $powershell -noprofile -command $script | Should -BeExactly 'hello'41 }42}43 