From 64fcddcb533820f0c6f2c68503a06c14fa83c14b Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 8 Jan 2019 09:56:56 -0800 Subject: [PATCH] `Help` function should only pass content to pager if content was found (#8528) --- .../engine/InitialSessionState.cs | 2 +- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index dbd79857e..fc4bbb303 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -4157,7 +4157,7 @@ param( { $help } - else + elseif ($help -ne $null) { # Respect PAGER, use more on Windows, and use less on Linux $moreCommand,$moreArgs = $env:PAGER -split '\s+' diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index a9a59f5ab..af9e1b351 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -477,3 +477,14 @@ Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdmin $helpObj.description | Out-String | Should -Match $CmdletName } } + +Describe "Help failure cases" -Tags Feature { + It "An error is returned for a topic that doesn't exist: " -TestCases @( + @{ command = "help" }, + @{ command = "get-help" } + ){ + param($command) + + { & $command foobar -ErrorAction Stop } | Should -Throw -ErrorId "HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand" + } +}