-
Notifications
You must be signed in to change notification settings - Fork 26
/
courtney.go
104 lines (90 loc) · 2.32 KB
/
courtney.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
99
100
101
102
103
104
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/pkg/errors"
"github.com/dave/courtney/scanner"
"github.com/dave/courtney/shared"
"github.com/dave/courtney/tester"
"github.com/dave/patsy"
"github.com/dave/patsy/vos"
)
func main() {
// notest
env := vos.Os()
enforceFlag := flag.Bool("e", false, "Enforce 100% code coverage")
verboseFlag := flag.Bool("v", false, "Verbose output")
shortFlag := flag.Bool("short", false, "Pass the short flag to the go test command")
timeoutFlag := flag.String("timeout", "", "Pass the timeout flag to the go test command")
outputFlag := flag.String("o", "", "Override coverage file location")
argsFlag := new(argsValue)
flag.Var(argsFlag, "t", "Argument to pass to the 'go test' command. Can be used more than once.")
loadFlag := flag.String("l", "", "Load coverage file(s) instead of running 'go test'")
flag.Parse()
setup := &shared.Setup{
Env: env,
Paths: patsy.NewCache(env),
Enforce: *enforceFlag,
Verbose: *verboseFlag,
Short: *shortFlag,
Timeout: *timeoutFlag,
Output: *outputFlag,
TestArgs: argsFlag.args,
Load: *loadFlag,
}
if err := Run(setup); err != nil {
fmt.Printf("%+v", err)
os.Exit(1)
}
}
// Run initiates the command with the provided setup
func Run(setup *shared.Setup) error {
if err := setup.Parse(flag.Args()); err != nil {
return errors.Wrapf(err, "Parse")
}
s := scanner.New(setup)
if err := s.LoadProgram(); err != nil {
return errors.Wrapf(err, "LoadProgram")
}
if err := s.ScanPackages(); err != nil {
return errors.Wrapf(err, "ScanPackages")
}
t := tester.New(setup)
if setup.Load == "" {
if err := t.Test(); err != nil {
return errors.Wrapf(err, "Test")
}
} else {
if err := t.Load(); err != nil {
return errors.Wrapf(err, "Load")
}
}
if err := t.ProcessExcludes(s.Excludes); err != nil {
return errors.Wrapf(err, "ProcessExcludes")
}
if err := t.Save(); err != nil {
return errors.Wrapf(err, "Save")
}
if err := t.Enforce(); err != nil {
return errors.Wrapf(err, "Enforce")
}
return nil
}
type argsValue struct {
args []string
}
var _ flag.Value = (*argsValue)(nil)
func (v *argsValue) String() string {
// notest
if v == nil {
return ""
}
return strings.Join(v.args, " ")
}
func (v *argsValue) Set(s string) error {
// notest
v.args = append(v.args, s)
return nil
}