forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
98 lines (84 loc) · 2.36 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"flag"
"fmt"
"os"
"sort"
"github.com/constabulary/gb"
"github.com/constabulary/gb/cmd"
"github.com/constabulary/gb/debug"
"github.com/constabulary/gb/test"
)
func init() {
registerCommand(TestCmd)
}
var (
tfs []string // Arguments passed to the test binary
testProfile bool
testCover bool
testCoverMode string
testCoverPkg string
testVerbose bool // enable verbose output of test commands
)
func addTestFlags(fs *flag.FlagSet) {
addBuildFlags(fs)
fs.BoolVar(&testCover, "cover", false, "enable coverage analysis")
fs.StringVar(&testCoverMode, "covermode", "set", "Set covermode: set (default), count, atomic")
fs.StringVar(&testCoverPkg, "coverpkg", "", "enable coverage analysis")
fs.BoolVar(&testVerbose, "v", false, "enable verbose output of subcommands")
}
var TestCmd = &cmd.Command{
Name: "test",
UsageLine: "test [build flags] -v [packages] [flags for test binary]",
Short: "test packages",
Long: `
Test automates testing the packages named by the import paths.
'gb test' recompiles each package along with any files with names matching
the file pattern "*_test.go".
Flags:
-v
print output from test subprocess.
`,
Run: func(ctx *gb.Context, args []string) error {
ctx.Force = F
ctx.Install = !FF
ctx.Verbose = testVerbose
r := test.TestResolver(ctx)
// gb build builds packages in dependency order, however
// gb test tests packages in alpha order. This matches the
// expected behaviour from go test; tests are executed in
// stable order.
sort.Strings(args)
pkgs, err := resolveRootPackages(r, args...)
if err != nil {
return err
}
test, err := test.TestPackages(TestFlags(tfs), pkgs...)
if err != nil {
return err
}
if dotfile != "" {
f, err := os.Create(dotfile)
if err != nil {
return err
}
defer f.Close()
printActions(f, test)
}
startSigHandlers()
return gb.ExecuteConcurrent(test, P, interrupted)
},
AddFlags: addTestFlags,
FlagParse: func(flags *flag.FlagSet, args []string) error {
var err error
debug.Debugf("%s", args)
args, tfs, err = TestFlagsExtraParse(args[2:])
debug.Debugf("%s %s", args, tfs)
if err != nil {
fmt.Fprintf(os.Stderr, "gb test: %s\n", err)
fmt.Fprintf(os.Stderr, `run "go help test" or "go help testflag" for more information`+"\n")
exit(2)
}
return flags.Parse(args)
},
}