Hint at unescaped wildcards on Should-Throw -ExceptionMessage - #2970
Merged
Conversation
Should-Throw filters -ExceptionMessage with -like, so [ ] * ? are wildcards. When the actual message is identical to the expected one treated literally, the match fails only because of unescaped wildcard characters, and the two messages look the same in the failure. Detect that case and add a hint, same as the v5 Should -Throw does since pester#2956. To carry the hint I added an optional Hint key to the ShouldAssertion.Fail data. When present it overrides the default Get-AssertionGotcha hint and is appended with the standard "Hint: <text>" format the other v6 assertions use, so no new formatting path is introduced. Fixes pester#2968 Fixes pester#2966 🤖
fflaten
reviewed
Aug 10, 2026
Co-authored-by: Frode Flaten <3436158+fflaten@users.noreply.github.com>
nohwnd
enabled auto-merge (squash)
August 11, 2026 17:18
nohwnd
disabled auto-merge
August 11, 2026 17:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Should-Throwmatches-ExceptionMessagewith-like, so[ ] * ?are wildcards. When the actual message is identical to the expected one treated literally, the match fails only because those characters were not escaped, and the failure shows two messages that look the same. This is the v6 counterpart of #2956, which added the same hint to the v5Should -Throw.To carry the hint I added an optional
Hintkey to theShouldAssertion.Faildata (issue #2968 suggested makingHintoverridable). When present it overrides the defaultGet-AssertionGotchahint and is appended with the standardHint: <text>format the other v6 assertions already use, so #2966 is covered without a new formatting path.Fixes #2968
Fixes #2966
🤖