Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/functions/assertions/Should.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,}(?<Operator>[^\-\@\s]+)') {
if ($myLine -match '^\s{0,}should[\s\`]{1,}(?<Operator>[^\-\@\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
}
Expand Down
22 changes: 22 additions & 0 deletions tst/functions/assertions/Should.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 -<Operator> but that's more obvious user error.
}
}