Files
wazero/internal/testing/require/require_test.go
Crypt Keeper ce1052a097 Isolates testify to one file, so that it is easier to remove (#460)
This starts the process of removing all dependencies from wazero, by
isolating all assertions we use into a single file. This allows us to
port those assertions as we have time, and when twitchy is gone, the
project literally has no dependencies except go!

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-14 10:05:38 +08:00

53 lines
1015 B
Go

package require
import (
"errors"
"testing"
)
func TestCapturePanic(t *testing.T) {
tests := []struct {
name string
panics func()
expectedErr string
}{
{
name: "doesn't panic",
panics: func() {},
expectedErr: "",
},
{
name: "panics with error",
panics: func() { panic(errors.New("error")) },
expectedErr: "error",
},
{
name: "panics with string",
panics: func() { panic("crash") },
expectedErr: "crash",
},
{
name: "panics with object",
panics: func() { panic(struct{}{}) },
expectedErr: "{}",
},
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
captured := CapturePanic(tc.panics)
if tc.expectedErr == "" {
if captured != nil {
t.Fatalf("expected no error, but found %v", captured)
}
} else {
if captured.Error() != tc.expectedErr {
t.Fatalf("expected %s, but found %s", tc.expectedErr, captured.Error())
}
}
})
}
}