diff --git a/src/System.Management.Automation/help/HelpCommentsParser.cs b/src/System.Management.Automation/help/HelpCommentsParser.cs index 833a8cb2097..50d884bf9c2 100644 --- a/src/System.Management.Automation/help/HelpCommentsParser.cs +++ b/src/System.Management.Automation/help/HelpCommentsParser.cs @@ -1154,10 +1154,10 @@ private static List GetParameterComments(Language.Token[] tokens, IParam // $sb = { } // set-item function:foo $sb // help foo - startTokenIndex = savedStartIndex = FirstTokenInExtent(tokens, ast.Extent) - 1; + startTokenIndex = savedStartIndex = FirstTokenInExtent(tokens, ast.Extent) + 1; lastTokenIndex = LastTokenInExtent(tokens, ast.Extent, startTokenIndex); - Diagnostics.Assert(tokens[startTokenIndex + 1].Kind == TokenKind.LCurly, + Diagnostics.Assert(tokens[startTokenIndex - 1].Kind == TokenKind.LCurly, "Unexpected first token in script block"); Diagnostics.Assert(tokens[lastTokenIndex].Kind == TokenKind.RCurly, "Unexpected last token in script block"); diff --git a/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1 b/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1 index 5536ea745f2..588e58a043d 100644 --- a/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1 +++ b/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1 @@ -80,6 +80,57 @@ Describe 'get-help HelpFunc1' -Tags "Feature" { # Useless # function helpFunc1 {} + + Set-Item function:dynamicHelpFunc1 -Value { + # .SYNOPSIS + # + # A relatively useless function. + # + # .DESCRIPTION + # + # A description + # + # with indented text and a blank line. + # + # .NOTES + # + # This function is mostly harmless. + # + # .LINK + # + # http://blogs.msdn.com/powershell + # + # .LINK + # + # other commands + # + # .EXAMPLE + # + # If you need an example, you're hopeless. + # + # .INPUTS + # + # Anything you like. + # + # .OUTPUTS + # + # Nothing. + # + # .COMPONENT + # + # Something + # + # .ROLE + # + # CrazyUser + # + # .FUNCTIONALITY + # + # Useless + # + + process { } + } } Context 'Get-Help helpFunc1' { @@ -87,6 +138,11 @@ Describe 'get-help HelpFunc1' -Tags "Feature" { TestHelpFunc1 $x } + Context 'Get-Help dynamicHelpFunc1' { + $x = get-help dynamicHelpFunc1 + TestHelpFunc1 $x + } + Context 'get-help helpFunc1 -component blah' { $x = get-help helpFunc1 -component blah -ErrorAction SilentlyContinue -ErrorVariable e TestHelpError $x $e 'HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand'