Adding '$pshome/cultureName/default.help.txt' to PowerShell Windows Core project. (#3032)

* 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.
This commit is contained in:
Francisco Gamino 2017-02-01 17:56:52 -08:00 committed by Mike Richmond
parent 9750297ce3
commit f57f924caf
5 changed files with 41 additions and 15 deletions

View File

@ -210,15 +210,21 @@ namespace System.Management.Automation
string moduleDir = null;
string nestedModulePath = null;
// When InternalTestHooks.BypassOnlineHelpRetrieval is enable, we force get-help to generate a metadata
// driven object, which includes a helpUri that points to the fwlink defined in the cmdlet code.
// This means that we are not going to load the help content from the GetFromCommandCache and
// we are not going to read the help file.
// Only gets help for Cmdlet or script command
if (!isCmdlet && !isScriptCommand)
return null;
// Check if the help of the command is already in the cache.
// If not, try load the file specified by HelpFile property and retrieve help.
if (isCmdlet)
if (isCmdlet && !InternalTestHooks.BypassOnlineHelpRetrieval)
{
result = GetFromCommandCache(cmdletInfo.ModuleName, cmdletInfo.Name, cmdletInfo.HelpCategory);
if (null == result)
{
// Try load the help file specified by CmdletInfo.HelpFile property
@ -291,7 +297,7 @@ namespace System.Management.Automation
}
}
if (!String.IsNullOrEmpty(helpFile))
if (!String.IsNullOrEmpty(helpFile) && !InternalTestHooks.BypassOnlineHelpRetrieval)
{
if (!_helpFiles.Contains(helpFile))
{
@ -306,7 +312,7 @@ namespace System.Management.Automation
// in the appropriate UI culture subfolder of ModuleBase, and retrieve help
// If still not able to get help, try search for a file called <NestedModuleName>-Help.xml
// under the ModuleBase and the NestedModule's directory, and retrieve help
if (null == result)
if (null == result && !InternalTestHooks.BypassOnlineHelpRetrieval)
{
// Get the name and ModuleBase directory of the command's module
// and the nested module that implements the command
@ -542,6 +548,13 @@ namespace System.Management.Automation
/// <returns></returns>
private string FindHelpFile(CmdletInfo cmdletInfo)
{
if (InternalTestHooks.BypassOnlineHelpRetrieval)
{
// By returning null, 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.
return null;
}
if (cmdletInfo == null)
{
throw PSTraceSource.NewArgumentNullException("cmdletInfo");

View File

@ -4,6 +4,7 @@ Copyright (c) Microsoft Corporation. All rights reserved.
using System.Management.Automation.Provider;
using System.Xml;
using System.Management.Automation.Internal;
using Dbg = System.Management.Automation.Diagnostics;
@ -51,6 +52,13 @@ namespace System.Management.Automation
/// </summary>
internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
{
if (InternalTestHooks.BypassOnlineHelpRetrieval)
{
// By returning null, we force get-help to return generic help
// which includes a helpUri that points to the fwlink defined in the cmdlet code.
return null;
}
// Get the provider.
ProviderInfo providerInfo = null;
PSDriveInfo driveInfo = null;

View File

@ -85,7 +85,8 @@
"Microsoft.PowerShell.LocalAccounts": "6.0.0-*",
"Microsoft.Management.Infrastructure.CimCmdlets": "6.0.0-*",
"Microsoft.WSMan.Management": "6.0.0-*",
"PSDesiredStateConfiguration": "1.0.0-alpha01"
"PSDesiredStateConfiguration": "1.0.0-alpha01",
"PowerShellHelpFiles": "1.0.0-alpha01"
},
"frameworks": {

View File

@ -3,23 +3,16 @@
# 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. Therefore, the help content
# in the box needs to be deleted before running the tests, because otherwise, the HelpURI
# (when calling get-help -online) might not matched the one in the csv file.
# on the file take precedence over the one in the cmdlet metadata.
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
# Enable the test hook
# 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)
# Remove the help content
Write-Verbose "Deleting help content for get-help -online tests" -Verbose
foreach ($path in @("$pshome\en-US", "$pshome\Modules"))
{
Get-ChildItem $path -Include "*help.xml" -Recurse -ea SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
}
}
AfterAll {

View File

@ -62,6 +62,17 @@ function RunTestCase
}
}
Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @('CI') {
It "Get-Help returns information about the help system." {
$help = Get-Help
$help.Name | Should Be "default"
$help.Category | Should Be "HelpFile"
$help.Synopsis | Should Match "SHORT DESCRIPTION"
}
}
Describe "Validate that get-help <cmdletName> works" -Tags @('CI', 'RequireAdminOnWindows') {
BeforeAll {
$SavedProgressPreference = $ProgressPreference