PowerShell/test/powershell/Modules/Microsoft.PowerShell.Core/Out-Default.Tests.ps1
Steve Lee 7bce1653f3 Add Windows PowerShell PSModulePath by default on Windows (#4132)
This change is only for Windows and appends the Windows PowerShell PSModulePath on startup via a default profile. Depending on the data/feedback we get, we can decide what to do (opt-in vs opt-out) as we get closer to a release candidate.
2017-07-07 09:43:37 -07:00

40 lines
1.7 KiB
PowerShell

Describe "Out-Default Tests" -tag CI {
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
$powershell = "$PSHOME/powershell"
}
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
"@
& $powershell -noprofile -command $script | Should BeExactly 'bye'
"TestDrive:\transcript.txt" | Should Contain 'hello'
}
It "Out-Default reverts transcription state when used more than once in a pipeline" {
& $powershell -noprofile -command "Out-Default -Transcript | Out-Default -Transcript; 'Hello'" | Should BeExactly "Hello"
}
It "Out-Default reverts transcription state when exception occurs in pipeline" {
& $powershell -noprofile -command "try { & { throw } | Out-Default -Transcript } catch {}; 'Hello'" | Should BeExactly "Hello"
}
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'
"@
& $powershell -noprofile -command $script | Should BeExactly 'hello'
}
}