Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Output.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

76 lines
2.3 KiB
PowerShell

Describe "Write-Output DRT Unit Tests" -Tags "CI" {
It "Simple Write Object Test" {
$objectWritten = 1, 2.2, @("John", "Smith", 10), "abc"
$results = Write-Output $objectWritten
$results.Length | Should Be $objectWritten.Length
$results[0] | Should Be $objectWritten[0]
$results[1] | Should Be $objectWritten[1]
$results[2] | Should Be $objectWritten[2]
$results[2] -is [System.Array] | Should Be $true
$results[3] | Should Be $objectWritten[3]
$results[3] -is [System.String] | Should Be $true
}
It "Works with NoEnumerate switch" {
$objectWritten = 1, 2.2, @("John", "Smith", 10), "abc"
[string]$s = Write-Output $objectWritten -NoEnumerate 6>&1
$s | Should be '1 2.2 System.Object[] abc'
}
}
Describe "Write-Output" -Tags "CI" {
$testString = $testString
Context "Input Tests" {
It "Should allow piped input" {
{ $testString | Write-Output } | Should Not Throw
}
It "Should write output to the output stream when using piped input" {
$testString | Write-Output | Should Be $testString
}
It "Should use inputobject switch" {
{ Write-Output -InputObject $testString } | Should Not Throw
}
It "Should write output to the output stream when using inputobject switch" {
Write-Output -InputObject $testString | Should Be $testString
}
It "Should be able to write to a variable" {
Write-Output -InputObject $testString -OutVariable var
$var | Should Be $testString
}
}
Context "Pipeline Command Tests" {
It "Should send object to the next command in the pipeline" {
Write-Output -InputObject (1+1) | Should Be 2
}
It "Should have the same result between inputobject switch and piped input" {
Write-Output -InputObject (1+1) | Should Be 2
1+1 | Write-Output | Should Be 2
}
}
Context "Enumerate Objects" {
$enumerationObject = @(1,2,3)
It "Should see individual objects when not using the NoEnumerate switch" {
$singleCollection = $(Write-Output $enumerationObject| Measure-Object).Count
$singleCollection | Should Be $enumerationObject.length
}
It "Should be able to treat a collection as a single object using the NoEnumerate switch" {
$singleCollection = $(Write-Output $enumerationObject -NoEnumerate | Measure-Object).Count
$singleCollection | Should Be 1
}
}
}