github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/emscripten/emscripten_test.go (about) 1 package emscripten 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/wasilibs/wazerox/api" 8 "github.com/wasilibs/wazerox/experimental/wazerotest" 9 "github.com/wasilibs/wazerox/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 }