-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build TinyGo module without docker. Disable Wasmer tests. Fix linter …
…issues. (#63)
- Loading branch information
Showing
8 changed files
with
134 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
package wasmer | ||
|
||
import ( | ||
"context" | ||
"log" | ||
// import ( | ||
// "context" | ||
// "log" | ||
|
||
"github.com/wasmerio/wasmer-go/wasmer" | ||
// "github.com/wasmerio/wasmer-go/wasmer" | ||
|
||
"github.com/wapc/wapc-go" | ||
) | ||
// "github.com/wapc/wapc-go" | ||
// ) | ||
|
||
// This shows how to customize the underlying wasmer engine used by waPC. | ||
func Example_custom() { | ||
// Set up the context used to instantiate the engine. | ||
ctx := context.Background() | ||
// // This shows how to customize the underlying wasmer engine used by waPC. | ||
// func Example_custom() { | ||
// // Set up the context used to instantiate the engine. | ||
// ctx := context.Background() | ||
|
||
// Configure waPC to use a specific wasmer feature. | ||
e := EngineWithRuntime(func() (*wasmer.Engine, error) { | ||
return wasmer.NewEngineWithConfig(wasmer.NewConfig().UseDylibEngine()), nil | ||
}) | ||
// // Configure waPC to use a specific wasmer feature. | ||
// e := EngineWithRuntime(func() (*wasmer.Engine, error) { | ||
// return wasmer.NewEngineWithConfig(wasmer.NewConfig().UseDylibEngine()), nil | ||
// }) | ||
|
||
// Instantiate a module normally. | ||
m, err := e.New(ctx, wapc.NoOpHostCallHandler, guest, mc) | ||
if err != nil { | ||
log.Panicf("Error creating module - %v\n", err) | ||
} | ||
defer m.Close(ctx) | ||
// // Instantiate a module normally. | ||
// m, err := e.New(ctx, wapc.NoOpHostCallHandler, guest, mc) | ||
// if err != nil { | ||
// log.Panicf("Error creating module - %v\n", err) | ||
// } | ||
// defer m.Close(ctx) | ||
|
||
// Output: | ||
} | ||
// // Output: | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,98 @@ | ||
package wasmer | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/wasmerio/wasmer-go/wasmer" | ||
|
||
"github.com/wapc/wapc-go" | ||
) | ||
|
||
// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors. | ||
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary") | ||
|
||
var guest []byte | ||
var mc = &wapc.ModuleConfig{ | ||
Logger: wapc.PrintlnLogger, | ||
Stdout: os.Stdout, | ||
Stderr: os.Stderr, | ||
} | ||
|
||
// TestMain ensures we can read the example wasm prior to running unit tests. | ||
func TestMain(m *testing.M) { | ||
var err error | ||
guest, err = os.ReadFile("../../testdata/go/hello.wasm") | ||
if err != nil { | ||
log.Panicln(err) | ||
} | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestEngine_WithEngine(t *testing.T) { | ||
t.Run("ok", func(t *testing.T) { | ||
expected := wasmer.NewEngine() | ||
|
||
e := EngineWithRuntime(func() (*wasmer.Engine, error) { | ||
return expected, nil | ||
}) | ||
|
||
m, err := e.New(testCtx, wapc.NoOpHostCallHandler, guest, mc) | ||
if err != nil { | ||
t.Errorf("Error creating module - %v", err) | ||
} | ||
defer m.Close(testCtx) | ||
|
||
if have := m.(*Module).engine; have != expected { | ||
t.Errorf("Unexpected engine, have %v, expected %v", have, expected) | ||
} | ||
}) | ||
|
||
t.Run("nil not ok", func(t *testing.T) { | ||
expectedErr := "function set by WithEngine returned nil" | ||
e := EngineWithRuntime(func() (*wasmer.Engine, error) { | ||
return nil, errors.New(expectedErr) | ||
}) | ||
|
||
if _, err := e.New(testCtx, wapc.NoOpHostCallHandler, guest, mc); err.Error() != expectedErr { | ||
t.Errorf("Unexpected error, have %v, expected %v", err, expectedErr) | ||
} | ||
}) | ||
} | ||
|
||
func TestModule_Unwrap(t *testing.T) { | ||
m, err := EngineWithRuntime(DefaultRuntime).New(testCtx, wapc.NoOpHostCallHandler, guest, mc) | ||
if err != nil { | ||
t.Errorf("Error creating module - %v", err) | ||
} | ||
defer m.Close(testCtx) | ||
|
||
mod := m.(*Module) | ||
expected := mod.module | ||
if have := mod.Unwrap(); have != expected { | ||
t.Errorf("Unexpected module, have %v, expected %v", have, expected) | ||
} | ||
} | ||
|
||
func TestInstance_Unwrap(t *testing.T) { | ||
m, err := EngineWithRuntime(DefaultRuntime).New(testCtx, wapc.NoOpHostCallHandler, guest, mc) | ||
if err != nil { | ||
t.Errorf("Error creating module - %v", err) | ||
} | ||
defer m.Close(testCtx) | ||
|
||
i, err := m.Instantiate(testCtx) | ||
if err != nil { | ||
t.Errorf("Error creating instance - %v", err) | ||
} | ||
defer m.Close(testCtx) | ||
|
||
inst := i.(*Instance) | ||
expected := inst.inst | ||
if have := inst.Unwrap(); have != expected { | ||
t.Errorf("Unexpected instance, have %v, expected %v", have, expected) | ||
} | ||
} | ||
// import ( | ||
// "context" | ||
// "errors" | ||
// "log" | ||
// "os" | ||
// "testing" | ||
|
||
// "github.com/wasmerio/wasmer-go/wasmer" | ||
|
||
// "github.com/wapc/wapc-go" | ||
// ) | ||
|
||
// // testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors. | ||
// var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary") | ||
|
||
// var guest []byte | ||
// var mc = &wapc.ModuleConfig{ | ||
// Logger: wapc.PrintlnLogger, | ||
// Stdout: os.Stdout, | ||
// Stderr: os.Stderr, | ||
// } | ||
|
||
// // TestMain ensures we can read the example wasm prior to running unit tests. | ||
// func TestMain(m *testing.M) { | ||
// var err error | ||
// guest, err = os.ReadFile("../../testdata/go/hello.wasm") | ||
// if err != nil { | ||
// log.Panicln(err) | ||
// } | ||
// os.Exit(m.Run()) | ||
// } | ||
|
||
// func TestEngine_WithEngine(t *testing.T) { | ||
// t.Run("ok", func(t *testing.T) { | ||
// expected := wasmer.NewEngine() | ||
|
||
// e := EngineWithRuntime(func() (*wasmer.Engine, error) { | ||
// return expected, nil | ||
// }) | ||
|
||
// m, err := e.New(testCtx, wapc.NoOpHostCallHandler, guest, mc) | ||
// if err != nil { | ||
// t.Errorf("Error creating module - %v", err) | ||
// } | ||
// defer m.Close(testCtx) | ||
|
||
// if have := m.(*Module).engine; have != expected { | ||
// t.Errorf("Unexpected engine, have %v, expected %v", have, expected) | ||
// } | ||
// }) | ||
|
||
// t.Run("nil not ok", func(t *testing.T) { | ||
// expectedErr := "function set by WithEngine returned nil" | ||
// e := EngineWithRuntime(func() (*wasmer.Engine, error) { | ||
// return nil, errors.New(expectedErr) | ||
// }) | ||
|
||
// if _, err := e.New(testCtx, wapc.NoOpHostCallHandler, guest, mc); err.Error() != expectedErr { | ||
// t.Errorf("Unexpected error, have %v, expected %v", err, expectedErr) | ||
// } | ||
// }) | ||
// } | ||
|
||
// func TestModule_Unwrap(t *testing.T) { | ||
// m, err := EngineWithRuntime(DefaultRuntime).New(testCtx, wapc.NoOpHostCallHandler, guest, mc) | ||
// if err != nil { | ||
// t.Errorf("Error creating module - %v", err) | ||
// } | ||
// defer m.Close(testCtx) | ||
|
||
// mod := m.(*Module) | ||
// expected := mod.module | ||
// if have := mod.Unwrap(); have != expected { | ||
// t.Errorf("Unexpected module, have %v, expected %v", have, expected) | ||
// } | ||
// } | ||
|
||
// func TestInstance_Unwrap(t *testing.T) { | ||
// m, err := EngineWithRuntime(DefaultRuntime).New(testCtx, wapc.NoOpHostCallHandler, guest, mc) | ||
// if err != nil { | ||
// t.Errorf("Error creating module - %v", err) | ||
// } | ||
// defer m.Close(testCtx) | ||
|
||
// i, err := m.Instantiate(testCtx) | ||
// if err != nil { | ||
// t.Errorf("Error creating instance - %v", err) | ||
// } | ||
// defer m.Close(testCtx) | ||
|
||
// inst := i.(*Instance) | ||
// expected := inst.inst | ||
// if have := inst.Unwrap(); have != expected { | ||
// t.Errorf("Unexpected instance, have %v, expected %v", have, expected) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters