Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/System.Management.Automation/help/CommandHelpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,21 @@ private HelpInfo GetHelpInfo(CommandInfo commandInfo, bool reportErrors, bool se
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
Expand Down Expand Up @@ -291,7 +297,7 @@ private HelpInfo GetHelpInfo(CommandInfo commandInfo, bool reportErrors, bool se
}
}

if (!String.IsNullOrEmpty(helpFile))
if (!String.IsNullOrEmpty(helpFile) && !InternalTestHooks.BypassOnlineHelpRetrieval)
{
if (!_helpFiles.Contains(helpFile))
{
Expand All @@ -306,7 +312,7 @@ private HelpInfo GetHelpInfo(CommandInfo commandInfo, bool reportErrors, bool se
// 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
Expand Down Expand Up @@ -542,6 +548,13 @@ private string GetHelpFile(string helpFile, CmdletInfo cmdletInfo)
/// <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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests that actually depend on this test hook to test the metadata driven help?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking this because I don't see this test hook is used for this purpose in the tests from this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dongbo Wang (@daxian-dbw) : Yes we do. These are located test/powershell/engine/Help/HelpSystem.OnlineHelp.Tests.ps1, which are part of this PR. Please see "Files Changed" section.

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 2, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. get-help will not find a help file; instead, it will generate a metadata driven object.
  2. get-help -online will return the helpuri instead of opening the default web browser.

Yes, I know this test hook is used in that test, but it's used there for get-help -online to return helpuri instead of opening web browser. I don't see where it's used for getting metadata driven help object. Maybe I missed something, can you please clarify?

return null;
}

if (cmdletInfo == null)
{
throw PSTraceSource.NewArgumentNullException("cmdletInfo");
Expand Down
8 changes: 8 additions & 0 deletions src/System.Management.Automation/help/ProviderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Management.Automation.Provider;
using System.Xml;
using System.Management.Automation.Internal;

using Dbg = System.Management.Automation.Diagnostics;

Expand Down Expand Up @@ -51,6 +52,13 @@ internal ProviderContext(
/// </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;
Expand Down
3 changes: 2 additions & 1 deletion src/powershell-win-core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
15 changes: 4 additions & 11 deletions test/powershell/engine/Help/HelpSystem.OnlineHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions test/powershell/engine/Help/HelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down