Skip to content

Commit

Permalink
Fix Get-Help issue wih -Parameter option #8697
Browse files Browse the repository at this point in the history
  • Loading branch information
throwaway774 committed Jan 26, 2019
1 parent db1b309 commit 0e64b17
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/System.Management.Automation/help/BaseCommandHelpInfo.cs
Expand Up @@ -393,8 +393,21 @@ internal override PSObject[] GetParameter(string pattern)
return base.GetParameter(pattern);
}

// The Maml format simplifies array fields containing only one object
// by transforming them into the objects themselves. To ensure the consistency
// of the help command result we change it back into an array.

var param = prmts.Properties["parameter"].Value;
PSObject paramPSObj = param as PSObject;
PSObject[] paramAsPSObjArray = new PSObject[1];

if (paramPSObj != null)
{
paramAsPSObjArray[0] = paramPSObj;
}

PSObject[] prmtArray = (PSObject[])LanguagePrimitives.ConvertTo(
prmts.Properties["parameter"].Value,
paramAsPSObjArray != null ? paramAsPSObjArray : param,
typeof(PSObject[]),
CultureInfo.InvariantCulture);

Expand Down
20 changes: 20 additions & 0 deletions test/powershell/engine/Help/HelpSystem.Tests.ps1
Expand Up @@ -503,6 +503,26 @@ Describe "Get-Help should accept arrays as the -Parameter parameter value" -Tags
}
}

Describe "Get-Help for function parameter should be consistent" -Tags 'CI' {
BeforeAll {
$test = @'
function test {
param (
$First
)
}
'@
$testPath = Join-Path $TestDrive "test.ps1"
New-Item -ItemType File -Path $testPath -Force > $null
Set-Content -Path $testPath -Value $test
}

It "Get-Help for function parameter should be consistent" {
Import-Module $testPath
(Get-Help test -Parameter First).PSTypeName | Should -BeExactly "MamlCommandHelpInfo#parameter"
}
}

Describe "Help failure cases" -Tags Feature {
It "An error is returned for a topic that doesn't exist: <command>" -TestCases @(
@{ command = "help" },
Expand Down

0 comments on commit 0e64b17

Please sign in to comment.