2020-03-24 19:08:37 +01:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 18:23:53 +01:00
|
|
|
# Licensed under the MIT License.
|
2020-05-07 14:00:30 +02:00
|
|
|
Describe "Out-Default Tests" -Tag CI {
|
2017-04-02 01:36:04 +02:00
|
|
|
BeforeAll {
|
|
|
|
# due to https://github.com/PowerShell/PowerShell/issues/3405, `Out-Default -Transcript` emits output to pipeline
|
|
|
|
# as running in Pester effectively wraps everything in parenthesis, workaround is to use another powershell
|
|
|
|
# to run the test script passed as a string
|
2017-10-18 02:25:11 +02:00
|
|
|
$powershell = "$PSHOME/pwsh"
|
2017-04-02 01:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "'Out-Default -Transcript' shows up in transcript, but not host" {
|
|
|
|
$script = @"
|
|
|
|
`$null = Start-Transcript -Path "$testdrive\transcript.txt";
|
|
|
|
'hello' | Microsoft.PowerShell.Core\Out-Default -Transcript;
|
|
|
|
'bye';
|
|
|
|
`$null = Stop-Transcript
|
|
|
|
"@
|
|
|
|
|
2018-03-23 18:36:11 +01:00
|
|
|
& $powershell -noprofile -command $script | Should -BeExactly 'bye'
|
|
|
|
"TestDrive:\transcript.txt" | Should -FileContentMatch 'hello'
|
2017-04-02 01:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Out-Default reverts transcription state when used more than once in a pipeline" {
|
2018-03-23 18:36:11 +01:00
|
|
|
& $powershell -noprofile -command "Out-Default -Transcript | Out-Default -Transcript; 'Hello'" | Should -BeExactly "Hello"
|
2017-04-02 01:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Out-Default reverts transcription state when exception occurs in pipeline" {
|
2018-03-23 18:36:11 +01:00
|
|
|
& $powershell -noprofile -command "try { & { throw } | Out-Default -Transcript } catch {}; 'Hello'" | Should -BeExactly "Hello"
|
2017-04-02 01:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Out-Default reverts transcription state even if Dispose() isn't called" {
|
|
|
|
$script = @"
|
|
|
|
`$sp = {Out-Default -Transcript}.GetSteppablePipeline();
|
|
|
|
`$sp.Begin(`$false);
|
|
|
|
`$sp = `$null;
|
|
|
|
[GC]::Collect();
|
|
|
|
[GC]::WaitForPendingFinalizers();
|
|
|
|
'hello'
|
|
|
|
"@
|
2018-03-23 18:36:11 +01:00
|
|
|
& $powershell -noprofile -command $script | Should -BeExactly 'hello'
|
2017-04-02 01:36:04 +02:00
|
|
|
}
|
|
|
|
}
|