-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
54 lines (42 loc) · 1.03 KB
/
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
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/rogpeppe/go-internal/gotooltest"
"github.com/rogpeppe/go-internal/testscript"
"github.com/stretchr/testify/require"
exec "golang.org/x/sys/execabs"
)
func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"allowtags": func() int {
main()
// Won't reach here because main will exit early.
return 0
},
}))
}
func TestScripts(t *testing.T) {
t.Parallel()
var goEnv struct {
GOCACHE string
GOMODCACHE string
GOMOD string
}
out, err := exec.Command("go", "env", "-json").CombinedOutput()
require.NoError(t, err)
require.NoError(t, json.Unmarshal(out, &goEnv))
p := testscript.Params{
Dir: filepath.Join("testdata", "script"),
Setup: func(env *testscript.Env) error {
env.Setenv("GOCACHE", goEnv.GOCACHE)
env.Setenv("GOMODCACHE", goEnv.GOMODCACHE)
env.Setenv("GOMOD_DIR", filepath.Dir(goEnv.GOMOD))
return nil
},
}
require.NoError(t, gotooltest.Setup(&p))
testscript.Run(t, p)
}