mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
* Adding PowerShellHelpFiles package which contains default.help.txt to powershell-win-core * Adding test case to validate that <pshome>/<culture>/default.help.txt is present. This is done by calling 'Get-Help' * Updating get-help to skip searching for the help file when the InternalTestHooks.BypassOnlineHelpRetrieval is enable. This way, we force get-help to generate a metadata driven help object, which includes a helpUri that points to the fwlink defined in the cmdlet code. * Updating get-help -online <cmdletName> tests to not delete the help files. Instead, I've added logic to get-help to not find the help file when the test hook BypassOnlineHelpRetrieval is enable.
105 lines
4.0 KiB
PowerShell
105 lines
4.0 KiB
PowerShell
Describe 'Online help tests for PowerShell Core Cmdlets' -Tags "CI" {
|
|
|
|
# The csv files (V2Cmdlets.csv and V3Cmdlets.csv) contain a list of cmdlets and expected HelpURIs.
|
|
# The HelpURI is part of the cmdlet metadata, and when the user runs 'get-help <cmdletName> -online'
|
|
# the browser navigates to the address in the HelpURI. However, if a help file is present, the HelpURI
|
|
# on the file take precedence over the one in the cmdlet metadata.
|
|
|
|
BeforeAll {
|
|
$SavedProgressPreference = $ProgressPreference
|
|
$ProgressPreference = "SilentlyContinue"
|
|
|
|
# Enable the test hook. This does the following:
|
|
# 1) get-help will not find a help file; instead, it will generate a metadata driven object.
|
|
# 2) get-help -online <cmdletName> will return the helpuri instead of opening the default web browser.
|
|
[system.management.automation.internal.internaltesthooks]::SetTestHook('BypassOnlineHelpRetrieval', $true)
|
|
}
|
|
|
|
AfterAll {
|
|
|
|
# Disable the test hook
|
|
[system.management.automation.internal.internaltesthooks]::SetTestHook('BypassOnlineHelpRetrieval', $false)
|
|
$ProgressPreference = $SavedProgressPreference
|
|
}
|
|
|
|
foreach ($filePath in @("$PSScriptRoot\assets\HelpURI\V2Cmdlets.csv", "$PSScriptRoot\assets\HelpURI\V3Cmdlets.csv"))
|
|
{
|
|
$cmdletList = Import-Csv $filePath -ea Stop
|
|
|
|
foreach ($cmdlet in $cmdletList)
|
|
{
|
|
# If the cmdlet is not preset in CoreCLR, skip it.
|
|
$skipTest = (Get-Command $cmdlet.TopicTitle -ea SilentlyContinue) -eq $null
|
|
|
|
# TopicTitle - is the cmdlet name in the csv file
|
|
# HelpURI - is the expected help URI in the csv file
|
|
|
|
It "Validate 'get-help $($cmdlet.TopicTitle) -Online'" -Skip:$skipTest {
|
|
$actualURI = Get-Help $cmdlet.TopicTitle -Online
|
|
$actualURI = $actualURI.Replace("Help URI: ","")
|
|
$actualURI | Should Be $cmdlet.HelpURI
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Describe 'Get-Help -Online opens the default web browser and navigates to the cmdlet help content' -Tags "Feature" {
|
|
|
|
$skipTest = [System.Management.Automation.Platform]::IsIoT -or
|
|
[System.Management.Automation.Platform]::IsNanoServer
|
|
|
|
# this code is a workaround for issue: https://github.com/PowerShell/PowerShell/issues/3079
|
|
if((-not ($skipTest)) -and $IsWindows)
|
|
{
|
|
$skipTest = $true
|
|
$regKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
|
|
|
|
try
|
|
{
|
|
$progId = [Microsoft.Win32.Registry]::GetValue($regKey, "ProgId", $null)
|
|
if($progId)
|
|
{
|
|
$browserKey = [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey("$progId\shell\open\command", $false)
|
|
if($browserKey)
|
|
{
|
|
$browserExe = ($browserKey.GetValue($null) -replace '"', '') -split " "
|
|
|
|
if ($browserExe.count -ge 1)
|
|
{
|
|
if($browserExe[0] -match '.exe')
|
|
{
|
|
$skipTest = $false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
# We are not able to access Registry, skipping test.
|
|
}
|
|
}
|
|
|
|
It "Get-Help get-process -online" -skip:$skipTest {
|
|
{ Get-Help get-process -online } | Should Not Throw
|
|
}
|
|
}
|
|
|
|
Describe 'Get-Help -Online is not supported on Nano Server and IoT' -Tags "CI" {
|
|
|
|
$skipTest = -not ([System.Management.Automation.Platform]::IsIoT -or [System.Management.Automation.Platform]::IsNanoServer)
|
|
|
|
It "Get-help -online <cmdletName> throws InvalidOperation." -skip:$skipTest {
|
|
|
|
try
|
|
{
|
|
Get-Help Get-Help -Online
|
|
throw "Execution should not have succeeded"
|
|
}
|
|
catch
|
|
{
|
|
$_.FullyQualifiedErrorId | Should Be "InvalidOperation,Microsoft.PowerShell.Commands.GetHelpCommand"
|
|
}
|
|
}
|
|
}
|