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>
22 lines
513 B
Go
22 lines
513 B
Go
package age_calculator
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/tetratelabs/wazero/internal/testing/maintester"
|
|
"github.com/tetratelabs/wazero/internal/testing/require"
|
|
)
|
|
|
|
// Test_main ensures the following will work:
|
|
//
|
|
// go run age-calculator.go 2000
|
|
func Test_main(t *testing.T) {
|
|
// Set ENV to ensure this test doesn't need maintenance every year.
|
|
t.Setenv("CURRENT_YEAR", "2021")
|
|
|
|
stdout, _ := maintester.TestMain(t, main, "age-calculator", "2000")
|
|
require.Equal(t, `println >> 21
|
|
log_i32 >> 21
|
|
`, stdout)
|
|
}
|