quicktest icon indicating copy to clipboard operation
quicktest copied to clipboard

Allow Matches and ErrorMatches matches to use an already-compiled regexp.Regexp

Open pajlada opened this issue 3 years ago • 1 comments

This allows users to have full control over the regular expression used for matching.

My use-case was matching a multiline string pattern, and the way MatchString was used in the match-function made that infeasible.

With this change, I was able to use the Matches matcher like this:

c.Assert("asd\nasd", qt.Matches, regexp.MustCompile(`asd.*`))

Happy to update naming of variables on request. I left naming of parameters/arguments on purpose to keep the diff minimal, but happy to change that too.

As an alternative, if this change is not acceptable, I know I could implement my own Checker handles regular expressions like this, so no worries if this change does not fit into the project!

pajlada avatar Mar 27 '22 14:03 pajlada

@frankban I've gone ahead and pushed missing tests for this functionality to maintain the 100% test coverage of checker.go, let me know if you prefer this to be rebased or something before being approved/merged in :slightly_smiling_face:

pajlada avatar Sep 18 '22 12:09 pajlada

I added the following tests: qt.ErrorMatches single-line match expectedNegateFailure qt.ErrorMatches multi-line match expectedNegateFailure qt.ErrorMatches multi-line match expectedCheckFailure qt.PanicMatches single-line match expectedNegateFailure qt.PanicMatches multi-line match expectedNegateFailure qt.PanicMatches multi-line match expectedCheckFailure

I added the following documentation: Added example for Matches checker in checker.go and in README.md Added example for ErrorMatches checker in checker.go and in README.md Added example for PanicMatches checker in checker.go and in README.md

pajlada avatar Sep 24 '22 16:09 pajlada

Released as v1.14.5

frankban avatar Apr 11 '23 22:04 frankban