Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1
T

48 lines
1.5 KiB
PowerShell
Raw Normal View History

2016-07-25 14:01:41 -07:00
Describe "Tee-Object" -Tags "CI" {
2015-11-19 06:23:45 +00:00
Context "Validate Tee-Object is correctly forking output" {
$testfile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath testfile.txt
2016-05-30 02:35:04 -07:00
It "Should return the output to the screen and to the variable" {
$teefile = $testfile
echo teeobjecttest1 | Tee-Object -variable teeresults
$teeresults | Should Be "teeobjecttest1"
Remove-Item $teefile -ErrorAction SilentlyContinue
}
2015-11-19 06:23:45 +00:00
2016-05-30 02:35:04 -07:00
It "Should tee the output to a file" {
$teefile = $testfile
echo teeobjecttest3 | Tee-Object $teefile
Get-Content $teefile | Should Be "teeobjecttest3"
Remove-Item $teefile -ErrorAction SilentlyContinue
}
2015-11-19 06:23:45 +00:00
}
}
2016-05-30 02:35:04 -07:00
2016-07-25 14:01:41 -07:00
Describe "Tee-Object DRT Unit Tests" -Tags "CI" {
2016-06-01 19:44:02 -07:00
BeforeAll {
$tempFile = Join-Path $TestDrive -ChildPath "TeeObjectTestsTempFile"
}
2016-05-30 02:35:04 -07:00
It "Positive File Test" {
$expected = "1", "2", "3"
2016-06-01 19:44:02 -07:00
$results = $expected | Tee-Object -FilePath $tempFile
2016-05-30 02:35:04 -07:00
$results.Length | Should be 3
$results | Should Be $expected
2016-06-01 19:44:02 -07:00
$content = Get-Content $tempFile
2016-05-30 02:35:04 -07:00
$content | Should Be $expected
}
2016-06-01 19:44:02 -07:00
It "Positive Variable Test" {
2017-01-16 13:31:14 -08:00
$expected = "1", "2", "3"
2016-05-30 02:35:04 -07:00
$varName = "teeObjectTestVar"
$results = $expected | Tee-Object -Variable $varName
$results.Length | Should be 3
$results | Should Be $expected
2017-01-16 13:31:14 -08:00
2016-05-30 02:35:04 -07:00
$results = Get-Variable -Name $varName -ValueOnly
$results.Length | Should be 3
$results | Should Be $expected
}
2016-07-25 14:01:41 -07:00
}