2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
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" {
|
|
|
|
|
|
2021-07-22 06:26:07 +02:00
|
|
|
BeforeAll {
|
|
|
|
|
$testfile = Join-Path $TestDrive -ChildPath "testfile.txt"
|
|
|
|
|
$testvalue = "ф"
|
|
|
|
|
if ($IsWindows) {
|
|
|
|
|
# Expected bytes: 244 - 'ф', 13 - '`r', 10 - '`n'.
|
|
|
|
|
$expectedBytes = 244,13,10 -join "-"
|
|
|
|
|
} else {
|
|
|
|
|
$expectedBytes = 244,10 -join "-"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BeforeEach {
|
|
|
|
|
Remove-Item -Path $testfile -ErrorAction SilentlyContinue -Force
|
|
|
|
|
}
|
2016-03-04 14:52:27 -08:00
|
|
|
|
2021-11-02 01:06:05 -05:00
|
|
|
It "Should return the output to the screen and to the variable" {
|
|
|
|
|
Write-Output teeobjecttest1 | Tee-Object -Variable teeresults
|
|
|
|
|
$teeresults | Should -BeExactly "teeobjecttest1"
|
|
|
|
|
}
|
2015-11-19 06:23:45 +00:00
|
|
|
|
2021-11-02 01:06:05 -05:00
|
|
|
It "Should tee the output to a file" {
|
|
|
|
|
$teefile = $testfile
|
|
|
|
|
Write-Output teeobjecttest3 | Tee-Object $teefile
|
|
|
|
|
Get-Content $teefile | Should -BeExactly "teeobjecttest3"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$unicodeTestString = "A1£ę௸🤔"
|
|
|
|
|
It "Should tee output to file using <encoding> encoding when selected" -TestCases @(
|
|
|
|
|
@{ Encoding = "ascii"; Content = "teeobjecttest1"},
|
|
|
|
|
@{ Encoding = "bigendianunicode"; Content = $unicodeTestString },
|
|
|
|
|
@{ Encoding = "default"; Content = $unicodeTestString },
|
|
|
|
|
@{ Encoding = "latin1"; Content = "téèõbjêcttëst1" },
|
|
|
|
|
@{ Encoding = "unicode"; Content = $unicodeTestString },
|
|
|
|
|
@{ Encoding = "utf32"; Content = $unicodeTestString },
|
|
|
|
|
@{ Encoding = "utf7"; Content = $unicodeTestString},
|
|
|
|
|
@{ Encoding = "utf8"; Content = $unicodeTestString}
|
|
|
|
|
) {
|
|
|
|
|
param($Encoding, $Content)
|
|
|
|
|
$teefile = $testfile
|
|
|
|
|
Write-Output -InputObject $content | Tee-Object -FilePath $teefile -Encoding $Encoding
|
|
|
|
|
Get-Content -Path $teefile -Encoding $Encoding | Should -BeExactly $content
|
|
|
|
|
Remove-Item -Path $teefile -ErrorAction SilentlyContinue
|
2021-07-22 06:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Parameter 'Encoding' should accept encoding" {
|
|
|
|
|
$teefile = $testfile
|
|
|
|
|
$encoding = 1251
|
|
|
|
|
$testvalue | Tee-Object -Encoding $encoding $teefile
|
|
|
|
|
Get-Content $teefile -Encoding $encoding | Should -BeExactly $testvalue
|
|
|
|
|
(Get-Content $teefile -AsByteStream) -join "-" | Should -BeExactly $expectedBytes
|
|
|
|
|
}
|
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
|
2018-03-23 10:26:23 -07:00
|
|
|
$results.Length | Should -Be 3
|
|
|
|
|
$results | Should -Be $expected
|
2016-06-01 19:44:02 -07:00
|
|
|
$content = Get-Content $tempFile
|
2018-03-23 10:26:23 -07:00
|
|
|
$content | Should -Be $expected
|
2016-05-30 02:35:04 -07:00
|
|
|
}
|
|
|
|
|
|
2018-02-27 13:05:58 -08:00
|
|
|
It "Positive File Test with Path parameter alias" {
|
|
|
|
|
$expected = "1", "2", "3"
|
|
|
|
|
$results = $expected | Tee-Object -Path $tempFile
|
2018-03-23 10:26:23 -07:00
|
|
|
$results.Length | Should -Be 3
|
|
|
|
|
$results | Should -Be $expected
|
2018-02-27 13:05:58 -08:00
|
|
|
$content = Get-Content $tempFile
|
2018-03-23 10:26:23 -07:00
|
|
|
$content | Should -Be $expected
|
2018-02-27 13:05:58 -08:00
|
|
|
}
|
|
|
|
|
|
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
|
2018-03-23 10:26:23 -07:00
|
|
|
$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
|
2018-03-23 10:26:23 -07:00
|
|
|
$results.Length | Should -Be 3
|
|
|
|
|
$results | Should -Be $expected
|
2016-05-30 02:35:04 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-25 14:01:41 -07:00
|
|
|
}
|