Skip to content

Commit

Permalink
Fix index error when using Get-Command on Should (pester#1804)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Dec 6, 2020
1 parent 4157c9f commit 1335279
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/functions/assertions/Should.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ function Should {

dynamicparam {
# Figuring out if we are using the old syntax is 'easy'
$myLine = # we can use $myInvocation.Line to get the surrounding context
# we can use $myInvocation.Line to get the surrounding context
$myLine = if ($null -ne $MyInvocation -and 0 -le ($MyInvocation.OffsetInLine - 1)) {
$MyInvocation.Line.Substring($MyInvocation.OffsetInLine - 1)
}

# A bit of Regex lets us know if the line used the old form
if ($myLine -match '^\s{0,}should\s{1,}(?<Operator>[^\-\@\s]+)')
Expand Down
6 changes: 6 additions & 0 deletions tst/functions/assertions/Should.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,10 @@ InPesterModuleScope {
{ throw "abc" } | Should -ErrorId "abc" # -Throw is not used
}
}

Describe 'Using Should without MyInvocation when generating help' {
It 'Get-Command Should -Syntax should show all help' {
Get-Command Should -Syntax | Should -Not -BeNullOrEmpty
}
}
}

0 comments on commit 1335279

Please sign in to comment.