Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Core/Out-Default.Tests.ps1
T
James Truher [MSFT] 99a7d38cae Update test framework and tests to support 4x version of Pester (#6064)
* Test fixes and changes needed to support Pester 4.0.8

* Replace 'Should Contain' with new 'Should FileContentMatch' assertion

Explicitly check for string creation with write-output

* Use the current version of pester and install it in modulesDir

* Simplify logic for relative path test.

Multiple '..' is not needed for a relative path, a single one will do. Also, on multi-drive systems using split-path -noqualifier will probably do the wrong thing with regard to constructing a correct path.
Remove extraneous Should Not Throw test, if this throws, the test will fail, we don't need to explicitly assert the not throw

* In some environments it is possible that computer name is 'localhost', so that should be allowed

* [feature] Add link for migrating tests from Pester v3 to v4

Fix up capitalization and white space issues
Change one test to check FullyQualifiedErrorId rather than just `Should Throw`

* [feature] update invoke-item test to handle the case where multiple notepad processes are running

* Fix spelling issue with Pester 4x, calling it Pester 4 should be sufficient
2018-02-05 11:58:25 -08:00

41 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/pwsh"
}
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 FileContentMatch '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'
}
}