-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_test.go
54 lines (46 loc) · 1.16 KB
/
script_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 (
"flag"
"os"
"testing"
"github.com/rogpeppe/go-internal/testscript"
)
var updateFlag = flag.Bool("update", false, "update the second argument of any failing cmp commands in a testscript")
func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(goModerateTestingMain{m}, map[string]func() int{
"gomoderate": goModerateMain,
}))
}
func TestScripts(t *testing.T) {
p := testscript.Params{
Dir: "testscripts",
UpdateScripts: *updateFlag,
Setup: func(e *testscript.Env) error {
e.Vars = append(e.Vars, "GOMODERATE_TEST_APPKEY="+os.Getenv("GOMODERATE_TEST_APPKEY"))
return nil
},
// future:
// Testscripts default to HOME=/no-home
// Setup: func(e *testscript.Env) error {
// home, err := os.UserHomeDir()
// if err != nil {
// log.Fatal(err)
// }
// return nil
// },
}
testscript.Run(t, p)
}
type goModerateTestingMain struct {
m *testing.M
}
func (m goModerateTestingMain) Run() int {
// could do additional setup here if needed (e.g., check or set env vars, etc.)
return m.m.Run()
}
// func homeEnvVar() string {
// if runtime.GOOS == "windows" {
// return "USERPROFILE"
// }
// return "HOME"
// }