Skip to content

Commit e144d26

Browse files
committed
Add ErrorMatches/PanicMatches tests for pre-compiled regexp
- 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`
1 parent 677534e commit e144d26

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

checker_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,49 @@ got args:
13111311
want args:
13121312
regexp
13131313
`,
1314+
}, {
1315+
about: "ErrorMatches: match with pre-compiled regexp",
1316+
checker: qt.ErrorMatches,
1317+
got: errBadWolf,
1318+
args: []interface{}{regexp.MustCompile("bad (wolf|dog)")},
1319+
expectedNegateFailure: `
1320+
error:
1321+
unexpected success
1322+
got error:
1323+
bad wolf
1324+
file:line
1325+
regexp:
1326+
s"bad (wolf|dog)"
1327+
`,
1328+
}, {
1329+
about: "ErrorMatches: match with pre-compiled multi-line regexp",
1330+
checker: qt.ErrorMatches,
1331+
got: errBadWolfMultiLine,
1332+
args: []interface{}{regexp.MustCompile(`bad (wolf|dog)\nfaulty (logic|statement)`)},
1333+
expectedNegateFailure: `
1334+
error:
1335+
unexpected success
1336+
got error:
1337+
bad wolf
1338+
faulty logic
1339+
file:line
1340+
regexp:
1341+
s"bad (wolf|dog)\\nfaulty (logic|statement)"
1342+
`,
1343+
}, {
1344+
about: "ErrorMatches: mismatch with pre-compiled regexp",
1345+
checker: qt.ErrorMatches,
1346+
got: errBadWolf,
1347+
args: []interface{}{regexp.MustCompile("good (wolf|dog)")},
1348+
expectedCheckFailure: `
1349+
error:
1350+
error does not match regexp
1351+
got error:
1352+
bad wolf
1353+
file:line
1354+
regexp:
1355+
s"good (wolf|dog)"
1356+
`,
13141357
}, {
13151358
about: "PanicMatches: perfect match",
13161359
checker: qt.PanicMatches,
@@ -1428,6 +1471,51 @@ panic value:
14281471
regexp:
14291472
nil
14301473
`,
1474+
}, {
1475+
about: "PanicMatches: match with pre-compiled regexp",
1476+
checker: qt.PanicMatches,
1477+
got: func() { panic("error: bad wolf") },
1478+
args: []interface{}{regexp.MustCompile("error: bad (wolf|dog)")},
1479+
expectedNegateFailure: `
1480+
error:
1481+
unexpected success
1482+
panic value:
1483+
"error: bad wolf"
1484+
function:
1485+
func() {...}
1486+
regexp:
1487+
s"error: bad (wolf|dog)"
1488+
`,
1489+
}, {
1490+
about: "PanicMatches: match with pre-compiled multi-line regexp",
1491+
checker: qt.PanicMatches,
1492+
got: func() { panic("error: bad wolf\nfaulty logic") },
1493+
args: []interface{}{regexp.MustCompile(`error: bad (wolf|dog)\nfaulty (logic|statement)`)},
1494+
expectedNegateFailure: `
1495+
error:
1496+
unexpected success
1497+
panic value:
1498+
"error: bad wolf\nfaulty logic"
1499+
function:
1500+
func() {...}
1501+
regexp:
1502+
s"error: bad (wolf|dog)\\nfaulty (logic|statement)"
1503+
`,
1504+
}, {
1505+
about: "PanicMatches: mismatch with pre-compiled regexp",
1506+
checker: qt.PanicMatches,
1507+
got: func() { panic("error: bad wolf") },
1508+
args: []interface{}{regexp.MustCompile("good (wolf|dog)")},
1509+
expectedCheckFailure: `
1510+
error:
1511+
panic value does not match regexp
1512+
panic value:
1513+
"error: bad wolf"
1514+
function:
1515+
func() {...}
1516+
regexp:
1517+
s"good (wolf|dog)"
1518+
`,
14311519
}, {
14321520
about: "PanicMatches: not a function",
14331521
checker: qt.PanicMatches,

error_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ var errBadWolf = &errTest{
3030
formatted: true,
3131
}
3232

33+
var errBadWolfMultiLine = &errTest{
34+
msg: "bad wolf\nfaulty logic",
35+
formatted: true,
36+
}
37+
3338
// errTest is an error type used in tests.
3439
type errTest struct {
3540
msg string

0 commit comments

Comments
 (0)