We are trying to test a function that raises an index out of range
error.
The code of the unit test is simple, something like:
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIndexOutOfRange(t *testing.T) {
assert.PanicsWithValue(t, "index out of range", func() { indexOutOfRange(9) })
}
But unfortunately the test Fails with a strange error
=== RUN TestIndexOutOfRange
--- FAIL: TestIndexOutOfRange (0.00s)
<autogenerated>:1:
Error Trace: badindex_test.go:55
Error: func (assert.PanicTestFunc)(0x1c440d0) should panic with value: "index out of range"
Panic value: "index out of range"
Test: TestIndexOutOfRange
You can see that the panic value and the error show the same, but test still fails.
Any ideas what is going on?