Skip to content

Commit 08b5885

Browse files
committed
Switch to GOTEST_SKIPNOTESTS instead of the -skipnotest
Filtering out the flags and arguments are making it harder to maintain the tool and we don't have comphensive testing to capture all the significant failure modes. Switching to an environment variable.
1 parent a44cddc commit 08b5885

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

main.go

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package main
88

99
import (
1010
"bufio"
11-
"flag"
1211
"fmt"
1312
"io"
1413
"log"
@@ -23,37 +22,24 @@ import (
2322
)
2423

2524
var (
26-
pass = color.FgGreen
27-
skip = color.FgYellow
28-
fail = color.FgHiRed
29-
ignore *bool
25+
pass = color.FgGreen
26+
skip = color.FgYellow
27+
fail = color.FgHiRed
28+
29+
skipnotest bool
3030
)
3131

32-
const paletteEnv = "GOTEST_PALETTE"
32+
const (
33+
paletteEnv = "GOTEST_PALETTE"
34+
skipNoTestsEnv = "GOTEST_SKIPNOTESTS"
35+
)
3336

3437
func main() {
35-
setPalette()
38+
enablePalette()
39+
enableSkipNoTests()
3640
enableOnCI()
3741

38-
flagSet := flag.NewFlagSet("gotestFlags", flag.ContinueOnError)
39-
ignore = flagSet.Bool("skipnotest", false, "skip packages with no test files")
40-
gotestFlags := make([]string, 0)
41-
args := make([]string, 0)
42-
43-
//separate program specific flags from go test flags
44-
for _, arg := range os.Args[1:] {
45-
// if the argument is in gotest flags the add it to gotestFlags
46-
lookup := flagSet.Lookup(strings.Trim(arg, "-"))
47-
if lookup != nil {
48-
gotestFlags = append(gotestFlags, arg)
49-
} else {
50-
args = append(args, arg)
51-
}
52-
}
53-
54-
flagSet.Parse(gotestFlags)
55-
os.Exit(gotest(args))
56-
42+
os.Exit(gotest(os.Args[1:]))
5743
}
5844

5945
func gotest(args []string) int {
@@ -121,16 +107,12 @@ func parse(line string) {
121107

122108
var c color.Attribute
123109
switch {
124-
case strings.HasPrefix(trimmed, "=== RUN"):
125-
fallthrough
126-
case strings.HasPrefix(trimmed, "?"):
127-
if *ignore {
110+
case strings.Contains(trimmed, "[no test files]"):
111+
if skipnotest {
128112
return
129113
}
130-
color.Unset()
131114

132-
// passed
133-
case strings.HasPrefix(trimmed, "--- PASS"):
115+
case strings.HasPrefix(trimmed, "--- PASS"): // passed
134116
fallthrough
135117
case strings.HasPrefix(trimmed, "ok"):
136118
fallthrough
@@ -168,7 +150,7 @@ func enableOnCI() {
168150
}
169151
}
170152

171-
func setPalette() {
153+
func enablePalette() {
172154
v := os.Getenv(paletteEnv)
173155
if v == "" {
174156
return
@@ -185,6 +167,15 @@ func setPalette() {
185167
}
186168
}
187169

170+
func enableSkipNoTests() {
171+
v := os.Getenv(skipNoTestsEnv)
172+
if v == "" {
173+
return
174+
}
175+
v = strings.ToLower(v)
176+
skipnotest = v == "true"
177+
}
178+
188179
var colors = map[string]color.Attribute{
189180
"black": color.FgBlack,
190181
"hiblack": color.FgHiBlack,

0 commit comments

Comments
 (0)