Skip to content

Commit

Permalink
Add ErrorMatches/PanicMatches tests for pre-compiled regexp
Browse files Browse the repository at this point in the history
 - 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`
  • Loading branch information
pajlada committed Nov 22, 2022
1 parent 677534e commit e144d26
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
88 changes: 88 additions & 0 deletions checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,49 @@ got args:
want args:
regexp
`,
}, {
about: "ErrorMatches: match with pre-compiled regexp",
checker: qt.ErrorMatches,
got: errBadWolf,
args: []interface{}{regexp.MustCompile("bad (wolf|dog)")},
expectedNegateFailure: `
error:
unexpected success
got error:
bad wolf
file:line
regexp:
s"bad (wolf|dog)"
`,
}, {
about: "ErrorMatches: match with pre-compiled multi-line regexp",
checker: qt.ErrorMatches,
got: errBadWolfMultiLine,
args: []interface{}{regexp.MustCompile(`bad (wolf|dog)\nfaulty (logic|statement)`)},
expectedNegateFailure: `
error:
unexpected success
got error:
bad wolf
faulty logic
file:line
regexp:
s"bad (wolf|dog)\\nfaulty (logic|statement)"
`,
}, {
about: "ErrorMatches: mismatch with pre-compiled regexp",
checker: qt.ErrorMatches,
got: errBadWolf,
args: []interface{}{regexp.MustCompile("good (wolf|dog)")},
expectedCheckFailure: `
error:
error does not match regexp
got error:
bad wolf
file:line
regexp:
s"good (wolf|dog)"
`,
}, {
about: "PanicMatches: perfect match",
checker: qt.PanicMatches,
Expand Down Expand Up @@ -1428,6 +1471,51 @@ panic value:
regexp:
nil
`,
}, {
about: "PanicMatches: match with pre-compiled regexp",
checker: qt.PanicMatches,
got: func() { panic("error: bad wolf") },
args: []interface{}{regexp.MustCompile("error: bad (wolf|dog)")},
expectedNegateFailure: `
error:
unexpected success
panic value:
"error: bad wolf"
function:
func() {...}
regexp:
s"error: bad (wolf|dog)"
`,
}, {
about: "PanicMatches: match with pre-compiled multi-line regexp",
checker: qt.PanicMatches,
got: func() { panic("error: bad wolf\nfaulty logic") },
args: []interface{}{regexp.MustCompile(`error: bad (wolf|dog)\nfaulty (logic|statement)`)},
expectedNegateFailure: `
error:
unexpected success
panic value:
"error: bad wolf\nfaulty logic"
function:
func() {...}
regexp:
s"error: bad (wolf|dog)\\nfaulty (logic|statement)"
`,
}, {
about: "PanicMatches: mismatch with pre-compiled regexp",
checker: qt.PanicMatches,
got: func() { panic("error: bad wolf") },
args: []interface{}{regexp.MustCompile("good (wolf|dog)")},
expectedCheckFailure: `
error:
panic value does not match regexp
panic value:
"error: bad wolf"
function:
func() {...}
regexp:
s"good (wolf|dog)"
`,
}, {
about: "PanicMatches: not a function",
checker: qt.PanicMatches,
Expand Down
5 changes: 5 additions & 0 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ var errBadWolf = &errTest{
formatted: true,
}

var errBadWolfMultiLine = &errTest{
msg: "bad wolf\nfaulty logic",
formatted: true,
}

// errTest is an error type used in tests.
type errTest struct {
msg string
Expand Down

0 comments on commit e144d26

Please sign in to comment.