Skip to content

Commit

Permalink
Remove Should legacy syntax error (#2445)
Browse files Browse the repository at this point in the history
* Use new certificate thumbprint

* Remove Should legacy syntax warning

---------

Co-authored-by: Jakub Jareš <[email protected]>
  • Loading branch information
fflaten and nohwnd authored May 17, 2024
1 parent dd43ae2 commit 8fd708a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
15 changes: 1 addition & 14 deletions src/functions/assertions/Should.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,7 @@ function Should {
)

dynamicparam {
# Figuring out if we are using the old syntax is 'easy'
# 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]+)') {
$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
}
else {
Get-AssertionDynamicParams
}
Get-AssertionDynamicParams
}

begin {
Expand Down
18 changes: 0 additions & 18 deletions tst/Pester.RSpec.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1990,24 +1990,6 @@ i -PassThru:$PassThru {
}
}

b "Should with legacy syntax will throw" {
t "Should with legacy syntax will throw" {
$sb = {
Describe "d" {
It "i" {
1 | Should Be 1
}
}
}

$container = New-PesterContainer -ScriptBlock $sb
$r = Invoke-Pester -Container $container -PassThru
$test = $r.Containers[0].Blocks[0].Tests[0]
$test.Result | Verify-Equal "Failed"
$test.ErrorRecord[0] -like "*Legacy Should syntax (without dashes) is not supported in Pester 5.*"
}
}

b "Running Pester in Pester" {
t "Invoke-Pester can run in Invoke-Pester" {
$container = New-PesterContainer -ScriptBlock {
Expand Down

0 comments on commit 8fd708a

Please sign in to comment.