Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Get-FormatData.Tests.ps173 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Get-FormatData" -Tags "CI" {4 5    Context "Check return type of Get-FormatData" {6        It "Should return an object[] as the return type" {7            $result = Get-FormatData8            , $result | Should -BeOfType "System.Object[]"9        }10    }11 12    # Note: Format data for [System.IO.FileInfo] (among others) is not to be13    #       returned to v5.0- remoting clients.14 15    Context "Local use: Can get format data requiring v5.1+ by default" {16        BeforeAll {17            $cmds = @(18                @{ cmd = { Get-FormatData System.IO.FileInfo } }19                @{ cmd = { (Get-FormatData System.IO.FileInfo &) | Receive-Job -Wait -AutoRemoveJob } }20            )21        }22        It "Can get format data requiring v5.1+ with <cmd>" -TestCases $cmds {23            param([scriptblock] $cmd)24 25            if ($IsWindows) {26                $expectedCount = 427            } else {28                # UnixStat addes extra one29                $expectedCount = 530            }31 32            $format = & $cmd33            $format.TypeNames | Should -HaveCount 234            $format.TypeNames[0] | Should -BeExactly "System.IO.DirectoryInfo"35            $format.TypeNames[1] | Should -BeExactly "System.IO.FileInfo"36            $format.FormatViewDefinition | Should -HaveCount $expectedCount37        }38    }39 40    Context "Can override client version with -PowerShellVersion" {41        BeforeAll {42            $cmds = @(43                @{ shouldBeNull = $true; cmd = { Get-FormatData System.IO.FileInfo -PowerShellVersion 5.0 } }44                @{ shouldBeNull = $false; cmd = { Get-FormatData System.IO.FileInfo -PowerShellVersion 5.1 } }45                @{ shouldBeNull = $false; cmd = { $PSSenderInfo = [System.Management.Automation.Internal.InternalTestHooks]::GetCustomPSSenderInfo('foo', [version] '5.0'); Get-FormatData System.IO.FileInfo -PowerShellVersion 5.1 } }46            )47        }48        It "<cmd> should return <shouldBeNull> for a null-output test" -TestCases $cmds {49            param([scriptblock] $cmd, [bool] $shouldBeNull)50            $null -eq $(& $cmd) | Should -Be $shouldBeNull51        }52    }53 54    Context "Remote use: By default, don't get format data requiring v5.1+ for v5.0- clients" {55        BeforeAll {56            # Simulated PSSenderInfo instances for various PowerShell versions.57            $pssiV50 = [System.Management.Automation.Internal.InternalTestHooks]::GetCustomPSSenderInfo('foo', [version] '5.0')58            $pssiV51 = [System.Management.Automation.Internal.InternalTestHooks]::GetCustomPSSenderInfo('foo', [version] '5.1')59            $pssiV70 = [System.Management.Automation.Internal.InternalTestHooks]::GetCustomPSSenderInfo('foo', [version] '7.0')60            $cmds = @(61                @{ shouldBeNull = $true; cmd = { $PSSenderInfo = $pssiV50; Get-FormatData System.IO.FileInfo } }62                @{ shouldBeNull = $false; cmd = { $PSSenderInfo = $pssiV51; Get-FormatData System.IO.FileInfo } }63                @{ shouldBeNull = $false; cmd = { $PSSenderInfo = $pssiV70; Get-FormatData System.IO.FileInfo } }64            )65        }66        It "When remoting, <cmd> should return <shouldBeNull> for a null-output test" -TestCases $cmds {67            param([scriptblock] $cmd, [bool] $shouldBeNull)68            $null -eq $(& $cmd) | Should -Be $shouldBeNull69        }70    }71 72}73