From cf22188e95b33f8471cf454797965f0724588544 Mon Sep 17 00:00:00 2001 From: Ryan Polley Date: Tue, 2 Nov 2021 01:06:05 -0500 Subject: [PATCH] Add more tests to `Tee-Object -Encoding` (#14539) --- .../Tee-Object.Tests.ps1 | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 index 7483c4d800..6d67665c37 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1 @@ -19,15 +19,33 @@ Describe "Tee-Object" -Tags "CI" { Remove-Item -Path $testfile -ErrorAction SilentlyContinue -Force } - It "Should return the output to the screen and to the variable" { - Write-Output teeobjecttest1 | Tee-Object -Variable teeresults - $teeresults | Should -BeExactly "teeobjecttest1" - } + It "Should return the output to the screen and to the variable" { + Write-Output teeobjecttest1 | Tee-Object -Variable teeresults + $teeresults | Should -BeExactly "teeobjecttest1" + } - It "Should tee the output to a file" { - $teefile = $testfile - Write-Output teeobjecttest3 | Tee-Object $teefile - Get-Content $teefile | Should -BeExactly "teeobjecttest3" + 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 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 } It "Parameter 'Encoding' should accept encoding" {