-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
48 lines (42 loc) · 1.01 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
package main
import (
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/bep/helpers/envhelpers"
"github.com/rogpeppe/go-internal/testscript"
)
func TestScripts(t *testing.T) {
setup := testSetupFunc()
testscript.Run(t, testscript.Params{
Dir: "testscripts",
// UpdateScripts: true, // Uncomment to rewrite the test scripts with
// TestWork: true, // Uncomment to keep the test work dir.
Setup: func(env *testscript.Env) error {
return setup(env)
},
})
}
func TestMain(m *testing.M) {
os.Exit(
testscript.RunMain(m, map[string]func() int{
"gomaintemplate": func() int {
fmt.Println(strings.Join(os.Args[1:], " "))
time.Sleep(10 * time.Millisecond)
return 0
},
}),
)
}
func testSetupFunc() func(env *testscript.Env) error {
sourceDir, _ := os.Getwd()
return func(env *testscript.Env) error {
var keyVals []string
// Add some environment variables to the test script.
keyVals = append(keyVals, "SOURCE", sourceDir)
envhelpers.SetEnvVars(&env.Vars, keyVals...)
return nil
}
}