-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
63 lines (49 loc) · 1017 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"os"
"os/exec"
"testing"
)
// build wasmexec.
func build(t *testing.T) {
t.Helper()
// build wasmexec.
err := exec.Command("go", "build").Run()
if err != nil {
t.Fatal(err)
}
}
func run(t *testing.T, name string, args ...string) {
t.Helper()
// run the test using wasmexec as the executor.
cmd := exec.Command(name, args...)
// pipe the output.
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
home, err := os.UserHomeDir()
if err != nil {
t.Fatal(err)
}
// set the build to target wasm/js.
cmd.Env = []string{
"HOME=" + home,
"GOOS=js",
"GOARCH=wasm",
}
// set the testdata folder as our directory.
cmd.Dir = "./testdata"
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
}
// run a test with wasmexec as the executor.
func TestTest(t *testing.T) {
build(t)
run(t, "go", "test", "-exec", "../wasmexec", "-v")
}
// run a test with wasmexec as the executor.
func TestRun(t *testing.T) {
build(t)
run(t, "go", "run", "-exec", "../wasmexec", ".")
}