Changes how examples are tested, and fixes ExitError bug (#468)
Before, we tested the examples/ directory using "ExampleXX", but this is not ideal because it literally embeds the call to `main` into example godoc output. This stops doing that for a different infrastructure. This also makes sure there's a godoc example for both the main package and wasi, so that people looking at https://pkg.go.dev see something and also a link to our real examples directory. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -1,22 +1,18 @@
|
||||
package add
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/tetratelabs/wazero/internal/testing/maintester"
|
||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||
)
|
||||
|
||||
// Example_main ensures the following will work:
|
||||
// Test_main ensures the following will work:
|
||||
//
|
||||
// go run add.go 7 9
|
||||
func Example_main() {
|
||||
|
||||
// Save the old os.Args and replace with our example input.
|
||||
oldArgs := os.Args
|
||||
os.Args = []string{"add", "7", "9"}
|
||||
defer func() { os.Args = oldArgs }()
|
||||
|
||||
main()
|
||||
|
||||
// Output:
|
||||
// wasm/math: 7 + 9 = 16
|
||||
// host/math: 7 + 9 = 16
|
||||
func Test_main(t *testing.T) {
|
||||
stdout, _ := maintester.TestMain(t, main, "add", "7", "9")
|
||||
require.Equal(t, `wasm/math: 7 + 9 = 16
|
||||
host/math: 7 + 9 = 16
|
||||
`, stdout)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user