diff --git a/src/functions/assertions/Should.ps1 b/src/functions/assertions/Should.ps1 index 509ebc492..e6b47864a 100644 --- a/src/functions/assertions/Should.ps1 +++ b/src/functions/assertions/Should.ps1 @@ -106,7 +106,7 @@ function Should { } # A bit of Regex lets us know if the line used the old form - if ($myLine -match '^\s{0,}should\s{1,}(?[^\-\@\s]+)') { + if ($myLine -match '^\s{0,}should[\s\`]{1,}(?[^\-\@\s\`]+)') { $shouldErrorMsg = "Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4" throw $shouldErrorMsg } diff --git a/tst/functions/assertions/Should.Tests.ps1 b/tst/functions/assertions/Should.Tests.ps1 index 6b290ec4a..e870c2917 100644 --- a/tst/functions/assertions/Should.Tests.ps1 +++ b/tst/functions/assertions/Should.Tests.ps1 @@ -124,4 +124,26 @@ InPesterModuleScope { Get-Command Should -Syntax | Should -Not -BeNullOrEmpty } } + + Describe 'Legacy syntax exception' { + It 'Throws when legacy syntax is used' { + { 1 | Should Be 1 } | Should -Throw '*Legacy Should syntax*is not supported*' + } + + It 'Does not throw when using linebreak before operator-switch' { + # https://github.com/pester/Pester/issues/2138 + 1 + 1 | Should ` + -Be 2 + } + + It 'Does not throw when using splatting' { + $p = @{ + Be = $true + ExpectedValue = 2 + } + 1 + 1 | Should @p + } + + # will throw on positional parameters before - but that's more obvious user error. + } }