From 4d5d223a4c9f3c3c4bc2aa64831df117b8d8c579 Mon Sep 17 00:00:00 2001 From: chunqingchen Date: Tue, 11 Apr 2017 04:13:19 -0700 Subject: [PATCH] Get-Help should find help files under pshome --- .../help/HelpProvider.cs | 16 ++----- .../engine/Help/HelpSystem.Tests.ps1 | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/System.Management.Automation/help/HelpProvider.cs b/src/System.Management.Automation/help/HelpProvider.cs index a590459b28d..b4b35b2061f 100644 --- a/src/System.Management.Automation/help/HelpProvider.cs +++ b/src/System.Management.Automation/help/HelpProvider.cs @@ -222,30 +222,20 @@ internal void ReportHelpFileError(Exception exception, string target, string hel /// /// Each Shell ( minishell ) will have its own path specified by the - /// registry HKLM\software\microsoft\msh\1\ShellIds\<ShellID>\path. Every help - /// provider should search this path for content. + /// application base folder, which should be the same as $pshome /// /// string representing base directory of the executing shell. internal string GetDefaultShellSearchPath() { string shellID = this.HelpSystem.ExecutionContext.ShellID; - string returnValue = CommandDiscovery.GetShellPathFromRegistry(shellID); + // Beginning in PowerShell 6.0.0.12, the $pshome is no longer registry specified, we search the application base instead. + string returnValue = Utils.GetApplicationBase(shellID); if (returnValue == null) { // use executing assemblies location in case registry entry not found returnValue = Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName); } - else - { - // Get the directory path of the executing shell - returnValue = Path.GetDirectoryName(returnValue); - if (!Directory.Exists(returnValue)) - { - // use executing assemblies location in case registry entry not found - returnValue = Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName); - } - } return returnValue; } diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 39be0a54328..2181da4db22 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -180,3 +180,49 @@ Describe "Validate that Get-Help returns provider-specific help" -Tags @('CI', ' } } } + +Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI') { + BeforeAll { + $modulePath = "$pshome\Modules\Test" + $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force + New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1 + Set-Content -Path $modulePath\test.psm1 -Value "function foo{}" + Set-Content -Path $modulePath\en-US\about_testhelp.help.txt -Value "Hello" -NoNewline + } + + AfterAll { + Remove-Item $modulePath -Recurse -Force + } + + It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$pshome path" { + + $help = Get-Help about_testhelp + $help.count | Should Be 1 + $help | Should BeExactly "Hello" + } +} + +Describe "Get-Help should find help info within help files" -Tags @('CI', 'RequireAdminOnWindows') { + It "Get-Help should find help files under pshome" { + $helpFile = "about_testCase.help.txt" + $culture = (Get-Culture).Name + $helpFolderPath = Join-Path $PSHOME $culture + $helpFilePath = Join-Path $helpFolderPath $helpFile + + if (!(Test-Path $helpFolderPath)) + { + $null = New-Item -ItemType Directory -Path $helpFolderPath -ErrorAction SilentlyContinue + } + + try + { + $null = New-Item -ItemType File -Path $helpFilePath -Value "about_test" -ErrorAction SilentlyContinue + $helpContent = Get-Help about_testCase + $helpContent | Should Match "about_test" + } + finally + { + Remove-Item $helpFilePath -Force -ErrorAction SilentlyContinue + } + } +}