From 8076f8b2ad9992a8ecda72642a96805c19dd0f8f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 22 Dec 2018 13:40:37 -0800 Subject: [PATCH] [feature] help function should only pass content to pager if content was found --- .../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 8e680f50a1e..1acaef407d5 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -4131,7 +4131,7 @@ .FORWARDHELPCATEGORY Cmdlet { $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 10654c8a625..dcaeab9a4b6 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -469,3 +469,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" + } +}