-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
main_test.go
58 lines (49 loc) · 1.2 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
55
56
57
58
// Copyright (c) 2019, Daniel Martí <[email protected]>
// See LICENSE for licensing information
package main
import (
"encoding/json"
"flag"
"os"
"os/exec"
"path/filepath"
"testing"
"github.com/go-quicktest/qt"
"github.com/rogpeppe/go-internal/gotooltest"
"github.com/rogpeppe/go-internal/testscript"
)
func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"gofumpt": main1,
}))
}
var update = flag.Bool("u", false, "update testscript output files")
func TestScript(t *testing.T) {
t.Parallel()
var goEnv struct {
GOCACHE string
GOMODCACHE string
GOMOD string
}
out, err := exec.Command("go", "env", "-json").CombinedOutput()
if err != nil {
t.Fatal(err)
}
if err := json.Unmarshal(out, &goEnv); err != nil {
t.Fatal(err)
}
p := testscript.Params{
Dir: filepath.Join("testdata", "script"),
UpdateScripts: *update,
RequireExplicitExec: true,
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
},
}
err = gotooltest.Setup(&p)
qt.Assert(t, qt.IsNil(err))
testscript.Run(t, p)
}