Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
HelpSystem.Tests.ps1716 linesDownload Raw Back to Help
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3#4# Validates Get-Help for cmdlets in Microsoft.PowerShell.Core.5 6Import-Module HelpersCommon7 8$script:cmdletsToSkip = @(9    "Get-PSHostProcessInfo",10    "Out-Default",11    "Register-ArgumentCompleter",12    "New-PSRoleCapabilityFile",13    "Get-PSSessionCapability",14    "Disable-PSRemoting", # Content not available: Issue # https://github.com/PowerShell/PowerShell-Docs/issues/179015    "Enable-PSRemoting",16    "Get-ExperimentalFeature",17    "Enable-ExperimentalFeature",18    "Disable-ExperimentalFeature",19    "Get-PSSubsystem",20    "Switch-Process"21)22 23function UpdateHelpFromLocalContentPath {24    param ([string]$ModuleName, [string] $Scope = 'CurrentUser')25 26    $helpContentPath = Join-Path $PSScriptRoot "assets"27    $helpFiles = @(Get-ChildItem "$helpContentPath\*" -ErrorAction SilentlyContinue)28 29    if ($helpFiles.Count -eq 0) {30        throw "Unable to find help content at '$helpContentPath'"31    }32 33    # Test files are 'en-US', set explicit culture so test does not fail on non-US systems34    Update-Help -Module $ModuleName -SourcePath $helpContentPath -UICulture 'en-US' -Force -ErrorAction Stop -Scope $Scope35}36 37function GetCurrentUserHelpRoot {38    if ([System.Management.Automation.Platform]::IsWindows) {39        $userHelpRoot = Join-Path $HOME "Documents/PowerShell/Help/"40    } else {41        $userModulesRoot = [System.Management.Automation.Platform]::SelectProductNameForDirectory([System.Management.Automation.Platform+XDG_Type]::USER_MODULES)42        $userHelpRoot = Join-Path $userModulesRoot -ChildPath ".." -AdditionalChildPath "Help"43    }44 45    return $userHelpRoot46}47 48Describe 'Validate HelpInfo type' -Tags @('CI') {49 50    It 'Category should be a string' {51        $help = Get-Help *52        $category = $help | ForEach-Object { $_.Category.GetType().FullName } | Select-Object -Unique53        $category.Count | Should -Be 1 -Because 'All help categories should be strings, >1 indicates a type mismatch'54        $category | Should -BeExactly 'System.String'55    }56}57 58Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @('CI') {59 60    It "Get-Help returns information about the help system" {61 62        $help = Get-Help63        $help.Name | Should -Be "default"64        $help.Category | Should -Be "HelpFile"65        $help.Synopsis | Should -Match "SHORT DESCRIPTION"66    }67}68 69Describe "Validate that the Help function can Run in strict mode" -Tags @('CI') {70 71    It "Help doesn't fail when strict mode is on" {72        if (Test-IsWindowsArm64) {73            Set-ItResult -Pending -Because "IOException: The handle is invalid."74        }75 76 77        $help = & {78            # run in nested scope to keep strict mode from affecting other tests79            Set-StrictMode -Version 3.080            help81        }82        # the help function renders the help content as text so just verify that there is content83        $help | Should -Not -BeNullOrEmpty84    }85}86 87Describe "Validate that get-help works for CurrentUserScope" -Tags @('CI') {88    BeforeAll {89        $SavedProgressPreference = $ProgressPreference90        $ProgressPreference = "SilentlyContinue"91        $moduleName = "Microsoft.PowerShell.Core"92    }93    AfterAll {94        $ProgressPreference = $SavedProgressPreference95    }96 97    Context "for module : $moduleName" {98 99        BeforeAll {100            UpdateHelpFromLocalContentPath $moduleName -Scope 'CurrentUser'101            $cmdlets = Get-Command -Module $moduleName102        }103 104        $testCases = @()105 106        ## Just testing first 3 in CI, Feature tests validate full list.107        $cmdlets | Where-Object { $script:cmdletsToSkip -notcontains $_ } | Select-Object -First 3 | ForEach-Object { $testCases += @{ cmdletName = $_.Name }}108 109        It "Validate -Description and -Examples sections in help content. Run 'Get-help -name <cmdletName>" -TestCases $testCases {110            param($cmdletName)111            $help = Get-Help -Name $cmdletName112            $help.Description | Out-String | Should -Match $cmdletName113            $help.Examples | Out-String | Should -Match $cmdletName114        }115 116        It "Validate 'Aliases' is present in help content formatting" {117            ## The parameter help content should be formatted with the following section:118            ##   Accept pipeline input?       xxxx119            ##   Aliases                      NoOverwrite120            ##   Accept wildcard characters?  xxxx121            $output = Get-Help Import-Module -Parameter NoClobber | Out-String122            $output | Should -Match "Accept pipeline input\?.*\n\s+Aliases\s+NoOverwrite.*\n\s+Accept wildcard characters\?.*"123        }124    }125}126 127Describe "Testing Get-Help Progress" -Tags @('Feature') {128    It "Last ProgressRecord should be Completed" {129        try {130            $j = Start-Job { Get-Help ([guid]::NewGuid().ToString("N")) }131            $j | Wait-Job132            $j.ChildJobs[0].Progress[-1].RecordType | Should -Be ([System.Management.Automation.ProgressRecordType]::Completed)133        }134        finally {135            $j | Remove-Job136        }137    }138}139 140Describe "Validate that get-help works for AllUsers Scope" -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {141    BeforeAll {142        $SavedProgressPreference = $ProgressPreference143        $ProgressPreference = "SilentlyContinue"144        $moduleName = "Microsoft.PowerShell.Core"145    }146    AfterAll {147        $ProgressPreference = $SavedProgressPreference148    }149 150    Context "for module : $moduleName" {151 152        BeforeAll {153            if (Test-CanWriteToPsHome) {154                UpdateHelpFromLocalContentPath $moduleName -Scope 'AllUsers'155            }156            $cmdlets = Get-Command -Module $moduleName157        }158 159        $testCases = @()160        $cmdlets | Where-Object { $cmdletsToSkip -notcontains $_ } | ForEach-Object { $testCases += @{ cmdletName = $_.Name }}161 162        It "Validate -Description and -Examples sections in help content. Run 'Get-help -name <cmdletName>" -TestCases $testCases -Skip:(!(Test-CanWriteToPsHome)) {163            param($cmdletName)164            $help = Get-Help -Name $cmdletName165            $help.Description | Out-String | Should -Match $cmdletName166            $help.Examples | Out-String | Should -Match $cmdletName167        }168    }169}170 171Describe "Validate that get-help works for provider specific help" -Tags @('CI') {172    BeforeAll {173        $namespaces = @{174            command = 'http://schemas.microsoft.com/maml/dev/command/2004/10'175            dev     = 'http://schemas.microsoft.com/maml/dev/2004/10'176            maml    = 'http://schemas.microsoft.com/maml/2004/10'177            msh     = 'http://msh'178        }179 180        $helpFileRoot = Join-Path (GetCurrentUserHelpRoot) ([Globalization.CultureInfo]::CurrentUICulture)181 182        # Currently these test cases are verified only on Windows, because183        # - WSMan:\ and Cert:\ providers are not yet supported on non-Windows platforms.184        $testCases = @(185            @{186                helpFile    = "$helpFileRoot\System.Management.Automation.dll-help.xml"187                path        = "$userHelpRoot"188                helpContext = "[@id='FileSystem' or @ID='FileSystem']"189                verb        = 'Add'190                noun        = 'Content'191            }192        )193 194        if ($IsWindows) {195            $testCases += @(196                @{197                    helpFile    = "$helpFileRoot\Microsoft.WSMan.Management.dll-help.xml"198                    path        = 'WSMan:\localhost\ClientCertificate'199                    helpContext = "[@id='ClientCertificate' or @ID='ClientCertificate']"200                    cmdlet      = 'New-Item'201                }202                ,203                @{204                    helpFile    = "$helpFileRoot\Microsoft.PowerShell.Security.dll-help.xml"205                    path        = 'Cert:\'206                    helpContext = $null  # CertificateProvider uses only verb and noun in XPath query207                    verb        = 'New'208                    noun        = 'Item'209                }210            )211 212            UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.WSMan.Management' -Scope 'CurrentUser'213            UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Security' -Scope 'CurrentUser'214        }215 216        UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'CurrentUser'217    }218 219    ## The tests are marked as pending since provider specific help content in not available in PS v6.*220    It "Shows contextual help when Get-Help is invoked for provider-specific path (Get-Help -Name <verb>-<noun> -Path <path>)" -TestCases $testCases -Pending {221 222        param(223            $helpFile,224            $path,225            $verb,226            $noun227        )228 229        # Path should exist or else Get-Help will fallback to default help text230        $path | Should -Exist231 232        $xpath = "/msh:helpItems/msh:providerHelp/msh:CmdletHelpPaths/msh:CmdletHelpPath$helpContext/command:command/command:details[command:verb='$verb' and command:noun='$noun']"233        $helpXmlNode = Select-Xml -Path $helpFile -XPath $xpath -Namespace $namespaces | Select-Object -ExpandProperty Node234 235        # Synopsis comes from command:command/command:details/maml:description236        $expected = Get-Help -Name "$verb-$noun" -Path $path | Select-Object -ExpandProperty Synopsis237 238        # System.Management.Automation.ProviderContext.GetProviderSpecificHelpInfo ignores extra whitespace, line breaks and239        # comments when loading help XML, but Select-Xml can not; use BeLikeExactly operator to omit trailing line breaks:240        $helpXmlNode.description.para -clike "$expected*" | Should -BeTrue241    }242}243 244Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {245    BeforeAll {246        $modulePath = "$PSHOME\Modules\Test"247        if (Test-CanWriteToPsHome) {248            $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force249            New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1250            Set-Content -Path $modulePath\test.psm1 -Value "function foo{}"251            Set-Content -Path $modulePath\en-US\about_testhelp.help.txt -Value "Hello" -NoNewline252        }253 254        $aboutHelpPath = Join-Path (GetCurrentUserHelpRoot) (Get-Culture).Name255 256        ## If help content does not exist, update it first.257        if (-not (Test-Path (Join-Path $aboutHelpPath "about_Variables.help.txt"))) {258            UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'CurrentUser'259        }260    }261 262    AfterAll {263        if (Test-CanWriteToPsHome) {264            Remove-Item $modulePath -Recurse -Force265        }266        # Remove all the help content.267        Get-ChildItem -Path $aboutHelpPath -Include @('about_*.txt', "*help.xml") -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue268    }269 270    It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$PSHOME path" -Skip:(!(Test-CanWriteToPsHome)) {271 272        $help = Get-Help about_testhelp273        $help.count | Should -Be 1274        $help | Should -BeExactly "Hello"275    }276 277    It "Get-Help for about_Variable should return only one help object" {278        $help = Get-Help about_Variables279        $help.count | Should -Be 1280    }281}282 283Describe "About help files can be found in AllUsers scope" -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {284    BeforeAll {285        $aboutHelpPath = Join-Path $PSHOME (Get-Culture).Name286 287        ##clean up any CurrentUser if exists.288 289        $userHelpRoot = GetCurrentUserHelpRoot290 291        if (Test-Path $userHelpRoot) {292            Remove-Item $userHelpRoot -Force -Recurse -ErrorAction Stop293        }294 295        if (Test-CanWriteToPsHome) {296            UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers'297        }298    }299 300    It "Get-Help for about_Variable should return only one help object" -Skip:(!(Test-CanWriteToPsHome)) {301        $help = Get-Help about_Variables302        $help.count | Should -Be 1303    }304}305 306Describe "Get-Help should find help info within help files" -Tags @('CI') {307    It "Get-Help should find help files under pshome" {308        $helpFile = "about_testCase.help.txt"309        $helpFolderPath = Join-Path (GetCurrentUserHelpRoot) (Get-Culture).Name310        $helpFilePath = Join-Path $helpFolderPath $helpFile311 312        if (!(Test-Path $helpFolderPath)) {313            $null = New-Item -ItemType Directory -Path $helpFolderPath -ErrorAction SilentlyContinue314        }315 316        try {317            $null = New-Item -ItemType File -Path $helpFilePath -Value "about_test" -ErrorAction SilentlyContinue318            $helpContent = Get-Help about_testCase319            $helpContent | Should -Match "about_test"320        } finally {321            Remove-Item $helpFilePath -Force -ErrorAction SilentlyContinue322        }323    }324}325 326Describe "Get-Help should find pattern help files" -Tags "CI" {327 328    BeforeAll {329        $helpFile1 = "about_testCase1.help.txt"330        $helpFile2 = "about_testCase.2.help.txt"331        $helpFolderPath = Join-Path (GetCurrentUserHelpRoot) (Get-Culture).Name332        $helpFilePath1 = Join-Path $helpFolderPath $helpFile1333        $helpFilePath2 = Join-Path $helpFolderPath $helpFile2334        $null = New-Item -ItemType Directory -Path $helpFolderPath -ErrorAction SilentlyContinue -Force335        # Create at least one help file matches "about*" pattern336        $null = New-Item -ItemType File -Path $helpFilePath1 -Value "about_test1" -ErrorAction SilentlyContinue337        $null = New-Item -ItemType File -Path $helpFilePath2 -Value "about_test2" -ErrorAction SilentlyContinue338    }339 340    # Remove the test files341    AfterAll {342        Remove-Item $helpFilePath1 -Force -ErrorAction SilentlyContinue343        Remove-Item $helpFilePath2 -Force -ErrorAction SilentlyContinue344    }345 346    BeforeEach {347        $currentPSModulePath = $env:PSModulePath348    }349 350    AfterEach {351        $env:PSModulePath = $currentPSModulePath352    }353 354    $testcases = @(355        @{command = {Get-Help about_testCas?1}; testname = "test ? pattern"; result = "about_test1"}356        @{command = {Get-Help about_testCase.?}; testname = "test ? pattern with dot"; result = "about_test2"}357        @{command = {(Get-Help about_testCase*).Count}; testname = "test * pattern"; result = "2"}358        @{command = {Get-Help about_testCas?.2*}; testname = "test ?, * pattern with dot"; result = "about_test2"}359    )360 361    It "Get-Help should find pattern help files - <testname>" -TestCases $testcases {362        param (363            $command,364            $result365        )366        $command.Invoke() | Should -Be $result367    }368 369    It "Get-Help should fail expectedly searching for class help with hidden members" {370        $testModule = @'371        class foo372        {373            hidden static $monthNames = @('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')374        }375'@376        $modulesFolder = Join-Path $TestDrive "Modules"377        $modulePath = Join-Path $modulesFolder "TestModule"378        New-Item -ItemType Directory -Path $modulePath -Force > $null379        Set-Content -Path (Join-Path $modulePath "TestModule.psm1") -Value $testModule380        $env:PSModulePath += [System.IO.Path]::PathSeparator + $modulesFolder381 382        { Get-Help -Category Class -Name foo -ErrorAction Stop } | Should -Throw -ErrorId "HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand"383    }384}385 386Describe "Get-Help should find pattern alias" -Tags "CI" {387    BeforeAll {388        Set-Alias -Name testAlias1 -Value Where-Object389    }390 391    AfterAll {392        Remove-Item alias:\testAlias1 -ErrorAction SilentlyContinue393    }394 395    It "Get-Help should find alias as command" {396        (Get-Help where).Name | Should -BeExactly "Where-Object"397    }398 399    It "Get-Help should find alias with ? pattern" {400        $help = Get-Help wher?401        $help.Category | Should -BeExactly "Alias"402        $help.Synopsis | Should -BeExactly "Where-Object"403    }404 405    It "Get-Help should find alias with * pattern" {406        $help = Get-Help testAlias1*407        $help.Category | Should -BeExactly "Alias"408        $help.Synopsis | Should -BeExactly "Where-Object"409    }410 411    It "Help alias should be same as Get-Help alias" {412        $help1 = Get-Help testAlias*413        $help2 = help testAlias*414        Compare-Object $help1 $help2 | Should -BeNullOrEmpty415    }416}417 418Describe "help function uses full view by default" -Tags "CI" {419    It "help should return full view without -Full switch" {420        if (Test-IsWindowsArm64) {421            Set-ItResult -Pending -Because "IOException: The handle is invalid."422        }423 424        $gpsHelp = (help Microsoft.PowerShell.Management\Get-Process)425        $gpsHelp | Where-Object {$_ -cmatch '^PARAMETERS'} | Should -Not -BeNullOrEmpty426    }427 428    It "help should return full view even with -Full switch" {429        if (Test-IsWindowsArm64) {430            Set-ItResult -Pending -Because "IOException: The handle is invalid."431        }432 433        $gpsHelp = (help Microsoft.PowerShell.Management\Get-Process -Full)434        $gpsHelp | Where-Object {$_ -cmatch '^PARAMETERS'} | Should -Not -BeNullOrEmpty435    }436 437    It "help should not append -Full when not using AllUsersView parameter set" {438        if (Test-IsWindowsArm64) {439            Set-ItResult -Pending -Because "IOException: The handle is invalid."440        }441 442        $gpsHelp = (help Microsoft.PowerShell.Management\Get-Process -Parameter Name)443        $gpsHelp | Where-Object {$_ -cmatch '^PARAMETERS'} | Should -BeNullOrEmpty444    }445}446 447Describe 'help can be found for CurrentUser Scope' -Tags 'CI' {448    BeforeAll {449        $userHelpRoot = GetCurrentUserHelpRoot450 451        ## Clear all help from user scope.452        Remove-Item $userHelpRoot -Force -ErrorAction SilentlyContinue -Recurse453        UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'CurrentUser'454        UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Management' -Scope 'CurrentUser'455        UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Archive' -Scope 'CurrentUser' -Force456        UpdateHelpFromLocalContentPath -ModuleName 'PackageManagement' -Scope CurrentUser -Force457 458        ## Delete help from global scope if it exists.459        $currentCulture = (Get-Culture).Name460 461        $managementHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Commands.Management.dll-Help.xml'462        if (Test-Path $managementHelpFilePath) {463            Remove-Item $managementHelpFilePath -Force -ErrorAction SilentlyContinue464        }465 466        $coreHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'System.Management.Automation.dll-Help.xml'467        if (Test-Path $coreHelpFilePath) {468            Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue469        }470 471        $archiveHelpFilePath = Join-Path (Get-Module Microsoft.PowerShell.Archive -ListAvailable).ModuleBase -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Archive-help.xml'472        if (Test-Path $archiveHelpFilePath) {473            Remove-Item $archiveHelpFilePath -Force -ErrorAction SilentlyContinue474        }475 476        $TestCases = @(477            @{TestName = 'module under $PSHOME'; CmdletName = 'Add-Content'}478            @{TestName = 'module is a PSSnapin'; CmdletName = 'Get-Command' }479            @{TestName = 'module is under $PSHOME\Modules'; CmdletName = 'Compress-Archive' }480            @{TestName = 'module has a version folder'; CmdletName = 'Find-Package' }481        )482    }483 484    It 'help in user scope be found for <TestName>' -TestCases $TestCases {485        param($CmdletName)486 487        $helpObj = Get-Help -Name $CmdletName -Full488        $helpObj.description | Out-String | Should -Match $CmdletName489    }490}491 492Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {493    BeforeAll {494        $userHelpRoot = GetCurrentUserHelpRoot495 496        ## Clear all help from user scope.497        Remove-Item $userHelpRoot -Force -ErrorAction SilentlyContinue -Recurse498 499        ## Delete help from global scope if it exists.500        $currentCulture = (Get-Culture).Name501 502        if (Test-CanWriteToPsHome) {503            $managementHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Commands.Management.dll-Help.xml'504            if (Test-Path $managementHelpFilePath) {505                Remove-Item $managementHelpFilePath -Force -ErrorAction SilentlyContinue506            }507 508            $coreHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'System.Management.Automation.dll-Help.xml'509            if (Test-Path $coreHelpFilePath) {510                Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue511            }512 513            $archiveHelpFilePath = Join-Path (Get-Module Microsoft.PowerShell.Archive -ListAvailable).ModuleBase -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Archive-help.xml'514            if (Test-Path $archiveHelpFilePath) {515                Remove-Item $archiveHelpFilePath -Force -ErrorAction SilentlyContinue516            }517 518            UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers'519            UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Management' -Scope 'AllUsers'520            UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Archive' -Scope 'AllUsers' -Force521            UpdateHelpFromLocalContentPath -ModuleName 'PackageManagement' -Scope 'AllUsers' -Force522        }523 524        $TestCases = @(525            @{TestName = 'module under $PSHOME'; CmdletName = 'Add-Content'}526            @{TestName = 'module is a PSSnapin'; CmdletName = 'Get-Command' }527            @{TestName = 'module is under $PSHOME\Modules'; CmdletName = 'Compress-Archive' }528            @{TestName = 'module has a version folder'; CmdletName = 'Find-Package' }529        )530    }531 532    It 'help in user scope be found for <TestName>' -TestCases $TestCases -Skip:(!(Test-CanWriteToPsHome)) {533        param($CmdletName)534 535        $helpObj = Get-Help -Name $CmdletName -Full536        $helpObj.description | Out-String | Should -Match $CmdletName537    }538}539 540Describe "Get-Help should accept arrays as the -Parameter parameter value" -Tags @('CI') {541 542    BeforeAll {543        $userHelpRoot = GetCurrentUserHelpRoot544 545        ## Clear all help from user scope.546        Remove-Item $userHelpRoot -Force -ErrorAction SilentlyContinue -Recurse547        UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'CurrentUser'548 549        ## Delete help from global scope if it exists.550        $currentCulture = (Get-Culture).Name551        $coreHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'System.Management.Automation.dll-Help.xml'552        if (Test-Path $coreHelpFilePath) {553            Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue554        }555    }556 557    It "Should return help objects for two parameters" {558        $help = Get-Help -Name Get-Command -Parameter Verb, Noun559        $help | Should -HaveCount 2560        $help[0].Name | Should -BeExactly 'Verb'561        $help[1].Name | Should -BeExactly 'Noun'562    }563}564 565Describe "Get-Help for function parameter should be consistent" -Tags 'CI' {566    BeforeAll {567        $test1 = @'568            function test1 {569                param (570                    $First571                )572            }573'@574        $test2 = @'575            function test2 {576                param (577                    $First,578                    $Second579                )580            }581'@582        $test1Path = Join-Path $TestDrive "test1.ps1"583        Set-Content -Path $test1Path -Value $test1584 585        $test2Path = Join-Path $TestDrive "test2.ps1"586        Set-Content -Path $test2Path -Value $test2587 588        Import-Module $test1Path589        Import-Module $test2Path590    }591 592    AfterAll {593        Remove-Module -Name "test1"594        Remove-Module -Name "test2"595    }596 597    It "Get-Help for function parameter should be consistent" {598        $test1HelpPSType = (Get-Help test1 -Parameter First).PSTypeNames599        $test2HelpPSType = (Get-Help test2 -Parameter First).PSTypeNames600        $test1HelpPSType | Should -BeExactly $test2HelpPSType601    }602}603 604Describe "Help failure cases" -Tags Feature {605    It "An error is returned for a topic that doesn't exist: <command>" -TestCases @(606        @{ command = "help" },607        @{ command = "get-help" }608    ) {609        param($command)610 611        # under some conditions this does not throw, so include what we actually got612        $helpTopic = [guid]::NewGuid().ToString("N")613        { & $command $helpTopic -ErrorAction Stop } | Should -Throw -ErrorId "HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand" -Because "A help topic was unexpectantly found for $helpTopic"614    }615}616 617Describe 'help renders when using a PAGER with a space in the path' -Tags 'CI' {618    BeforeAll {619        $fakePager = @'620        param(621            [Parameter]622            $customCommandArgs,623 624            [Parameter(ValueFromPipelineByPropertyName)]625            $Name626        )627 628        $b = [System.Text.Encoding]::UTF8.GetBytes($Name)629        return [System.Convert]::ToBase64String($b)630'@631        $fakePagerFolder = Join-Path $TestDrive "path with space"632        $fakePagerPath = Join-Path $fakePagerFolder "fakepager.ps1"633        New-Item -ItemType File -Path $fakePagerPath -Force > $null634        Set-Content -Path $fakePagerPath -Value $fakePager635 636        $SavedEnvPager = $env:PAGER637        $env:PAGER = $fakePagerPath638    }639    AfterAll {640        $env:PAGER = $SavedEnvPager641    }642 643    It 'help renders when using a PAGER with a space in the path' {644        help Get-Command | Should -Be "R2V0LUNvbW1hbmQ="645    }646}647 648Describe 'Update-Help allows partial culture matches' -Tags 'CI' {649    BeforeAll {650        function Test-UpdateHelpAux($UICulture, $Pass)651        {652            # If null (in system culture tests), omit entirely653            $CultureArg = $UICulture ? @{ UICulture = $UICulture } : @{}654            $Args = @{655                Module = 'Microsoft.PowerShell.Core'656                SourcePath = Join-Path $PSScriptRoot 'assets'657                Force = $true658                ErrorAction = $Pass ? 'Stop' : 'SilentlyContinue'659                ErrorVariable = 'ErrorVariable'660            }661 662            Update-Help @Args @CultureArg663 664            if (-not $Pass) {665                $ErrorVariable | Should -Match 'Failed to update Help for the module.*'666            }667        }668    }669 670    AfterEach {671        [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('CurrentUICulture', $null)672    }673 674    It 'Checks culture match against en-US: <UICulture>' -TestCases @(675        @{ UICulture = 'en-US' }676        @{ UICulture = 'en' }677        @{ UICulture = 'en-GB'; Pass = $false }678        @{ UICulture = 'de-DE'; Pass = $false }679    ) {680        param($UICulture, $Pass = $true)681 682        Test-UpdateHelpAux $UICulture $Pass683    }684 685    # When using system culture, "en-GB" will use "en" as fallback, so passes686    It 'Checks system culture match against en-US: <UICulture>' -TestCases @(687        @{ UICulture = 'en-US' }688        @{ UICulture = 'en' }689        @{ UICulture = 'en-GB' }690        @{ UICulture = 'de-DE'; Pass = $false }691    ) {692        param($UICulture, $Pass = $true)693 694        [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('CurrentUICulture', [System.Globalization.CultureInfo]::new($UICulture))695        Test-UpdateHelpAux $null $Pass696    }697}698 699Describe 'InputTypes accurately describe pipelinable input' {700    BeforeAll {701        function invoke-inputtypetest {702            [CmdletBinding()]703            param (704            [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][string]$a,705            [Parameter(Position=1,ValueFromRemainingArguments=$true)][object[]]$c)706            Process { "$a $c" }707        }708    }709 710    It 'Should have only 1 input type' {711        $inputTypes = (Get-Help -full invoke-inputtypetest).inputtypes.inputtype.type.name.trim().split("`n")712        $inputTypes.Count | Should -Be 1713        $inputTypes | Should -Be "System.String"714    }715}716