Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Tee-Object.Tests.ps196 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Tee-Object" -Tags "CI" {4 5    Context "Validate Tee-Object is correctly forking output" {6 7        BeforeAll {8            $testfile = Join-Path $TestDrive -ChildPath "testfile.txt"9            $testvalue = "ф"10            if ($IsWindows) {11                # Expected bytes: 244 - 'ф', 13  - '`r', 10  - '`n'.12                $expectedBytes = 244,13,10 -join "-"13            } else {14                $expectedBytes = 244,10 -join "-"15            }16        }17 18        BeforeEach {19            Remove-Item -Path $testfile -ErrorAction SilentlyContinue -Force20        }21 22        It "Should return the output to the screen and to the variable" {23            Write-Output teeobjecttest1 | Tee-Object -Variable teeresults24            $teeresults | Should -BeExactly "teeobjecttest1"25        }26 27        It "Should tee the output to a file" {28            $teefile = $testfile29            Write-Output teeobjecttest3  | Tee-Object $teefile30            Get-Content $teefile | Should -BeExactly "teeobjecttest3"31        }32 33        $unicodeTestString = "A1£ę௸🤔"34        It "Should tee output to file using <encoding> encoding when selected" -TestCases @(35            @{ Encoding = "ascii"; Content = "teeobjecttest1"},36            @{ Encoding = "bigendianunicode"; Content = $unicodeTestString  },37            @{ Encoding = "default"; Content = $unicodeTestString },38            @{ Encoding = "latin1"; Content = "téèõbjêcttëst1" },39            @{ Encoding = "unicode"; Content = $unicodeTestString },40            @{ Encoding = "utf32"; Content = $unicodeTestString },41            @{ Encoding = "utf7"; Content = $unicodeTestString},42            @{ Encoding = "utf8"; Content = $unicodeTestString}43        ) {44            param($Encoding, $Content)45            $teefile = $testfile46            Write-Output -InputObject $content  | Tee-Object -FilePath $teefile -Encoding $Encoding47            Get-Content -Path $teefile -Encoding $Encoding | Should -BeExactly $content48            Remove-Item -Path $teefile -ErrorAction SilentlyContinue49        }50 51        It "Parameter 'Encoding' should accept encoding" {52            $teefile = $testfile53            $encoding = 125154            $testvalue | Tee-Object -Encoding $encoding $teefile55            Get-Content $teefile -Encoding $encoding | Should -BeExactly $testvalue56            (Get-Content $teefile -AsByteStream) -join "-" | Should -BeExactly $expectedBytes57        }58    }59}60 61Describe "Tee-Object DRT Unit Tests" -Tags "CI" {62    BeforeAll {63        $tempFile = Join-Path $TestDrive -ChildPath "TeeObjectTestsTempFile"64    }65    It "Positive File Test" {66        $expected = "1", "2", "3"67        $results = $expected | Tee-Object -FilePath $tempFile68        $results.Length | Should -Be 369        $results | Should -Be $expected70        $content = Get-Content $tempFile71        $content | Should -Be $expected72    }73 74    It "Positive File Test with Path parameter alias" {75        $expected = "1", "2", "3"76        $results = $expected | Tee-Object -Path $tempFile77        $results.Length | Should -Be 378        $results | Should -Be $expected79        $content = Get-Content $tempFile80        $content | Should -Be $expected81    }82 83    It "Positive Variable Test" {84        $expected = "1", "2", "3"85        $varName = "teeObjectTestVar"86        $results = $expected | Tee-Object -Variable $varName87        $results.Length | Should -Be 388        $results | Should -Be $expected89 90        $results = Get-Variable -Name $varName -ValueOnly91        $results.Length | Should -Be 392        $results | Should -Be $expected93    }94 95}96