File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed
src/System.Management.Automation/help
test/powershell/engine/Help Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -393,8 +393,19 @@ internal override PSObject[] GetParameter(string pattern)
393
393
return base . GetParameter ( pattern ) ;
394
394
}
395
395
396
+ // The Maml format simplifies array fields containing only one object
397
+ // by transforming them into the objects themselves. To ensure the consistency
398
+ // of the help command result we change it back into an array.
399
+ var param = prmts . Properties [ "parameter" ] . Value ;
400
+ PSObject [ ] paramAsPSObjArray = new PSObject [ 1 ] ;
401
+
402
+ if ( param is PSObject paramPSObj )
403
+ {
404
+ paramAsPSObjArray [ 0 ] = paramPSObj ;
405
+ }
406
+
396
407
PSObject [ ] prmtArray = ( PSObject [ ] ) LanguagePrimitives . ConvertTo (
397
- prmts . Properties [ "parameter" ] . Value ,
408
+ paramAsPSObjArray [ 0 ] != null ? paramAsPSObjArray : param ,
398
409
typeof ( PSObject [ ] ) ,
399
410
CultureInfo . InvariantCulture ) ;
400
411
Original file line number Diff line number Diff line change @@ -503,6 +503,45 @@ Describe "Get-Help should accept arrays as the -Parameter parameter value" -Tags
503
503
}
504
504
}
505
505
506
+ Describe " Get-Help for function parameter should be consistent" - Tags ' CI' {
507
+ BeforeAll {
508
+ $test1 = @'
509
+ function test1 {
510
+ param (
511
+ $First
512
+ )
513
+ }
514
+ '@
515
+ $test2 = @'
516
+ function test2 {
517
+ param (
518
+ $First,
519
+ $Second
520
+ )
521
+ }
522
+ '@
523
+ $test1Path = Join-Path $TestDrive " test1.ps1"
524
+ Set-Content - Path $test1Path - Value $test1
525
+
526
+ $test2Path = Join-Path $TestDrive " test2.ps1"
527
+ Set-Content - Path $test2Path - Value $test2
528
+
529
+ Import-Module $test1Path
530
+ Import-Module $test2Path
531
+ }
532
+
533
+ AfterAll {
534
+ Remove-Module - Name " test1"
535
+ Remove-Module - Name " test2"
536
+ }
537
+
538
+ It " Get-Help for function parameter should be consistent" {
539
+ $test1HelpPSType = (Get-Help test1 - Parameter First).PSTypeNames
540
+ $test2HelpPSType = (Get-Help test2 - Parameter First).PSTypeNames
541
+ $test1HelpPSType | Should - BeExactly $test2HelpPSType
542
+ }
543
+ }
544
+
506
545
Describe " Help failure cases" - Tags Feature {
507
546
It " An error is returned for a topic that doesn't exist: <command>" - TestCases @ (
508
547
@ { command = " help" },
You can’t perform that action at this time.
0 commit comments