-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
enhancementpkg-assertChange related to package testify/assertChange related to package testify/assert
Description
When PanicsWithError fails with a message different from the expected one, the message might not indicate very well what the error was, and what the string mismatch is exactly.
It does work in simple cases:
assert.PanicsWithError("expected message", func() {
panic(errors.New("surprising message"))
})Fails with:
func (assert.PanicTestFunc)(0x84d480) should panic with error message: "expected message"
Panic value: &errors.errorString{s:"surprising message"}
Panic stack: goroutine 19 [running]:
It does not indicate the actual error message in case the error message is not in the fields:
assert.PanicsWithError("expected message", func() {
panic(errors.Join(errors.New("surprising message")))
})Fails with:
func (assert.PanicTestFunc)(0x84d4e0) should panic with error message: "expected message"
Panic value: &errors.joinError{errs:[]error{(*errors.errorString)(0xc000119570)}}
Panic stack: goroutine 19 [running]:
A real world example here is https://pkg.go.dev/text/template#ExecError.
Since the assertion expects this to be an error and it checks on the error message only, it would suffice to replace the listing of entire "Panic value" with panicErr.Error().
ed-randall-blk and ikicic
Metadata
Metadata
Assignees
Labels
enhancementpkg-assertChange related to package testify/assertChange related to package testify/assert