github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/emscripten/emscripten_test.go (about) 1 package emscripten 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/bananabytelabs/wazero/api" 8 "github.com/bananabytelabs/wazero/experimental/wazerotest" 9 "github.com/bananabytelabs/wazero/internal/testing/require" 10 ) 11 12 func Test_callOnPanic(t *testing.T) { 13 const exists = "f" 14 var called bool 15 f := wazerotest.NewFunction(func(context.Context, api.Module) { called = true }) 16 f.ExportNames = []string{exists} 17 m := wazerotest.NewModule(nil, f) 18 t.Run("exists", func(t *testing.T) { 19 callOrPanic(context.Background(), m, exists, nil) 20 require.True(t, called) 21 }) 22 t.Run("not exist", func(t *testing.T) { 23 err := require.CapturePanic(func() { callOrPanic(context.Background(), m, "not-exist", nil) }) 24 require.EqualError(t, err, "not-exist not exported") 25 }) 26 }