Help function should only pass content to pager if content was found (#8528)

This commit is contained in:
Steve Lee 2019-01-08 09:56:56 -08:00 committed by Aditya Patwardhan
parent 031cbf0f16
commit 64fcddcb53
2 changed files with 12 additions and 1 deletions

View file

@ -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+'

View file

@ -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: <command>" -TestCases @(
@{ command = "help" },
@{ command = "get-help" }
){
param($command)
{ & $command foobar -ErrorAction Stop } | Should -Throw -ErrorId "HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand"
}
}