Skip to content

Commit

Permalink
Switch to GOTEST_SKIPNOTESTS instead of the -skipnotest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rakyll committed Jun 13, 2020
1 parent a44cddc commit 08b5885
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package main

import (
"bufio"
"flag"
"fmt"
"io"
"log"
Expand All @@ -23,37 +22,24 @@ import (
)

var (
pass = color.FgGreen
skip = color.FgYellow
fail = color.FgHiRed
ignore *bool
pass = color.FgGreen
skip = color.FgYellow
fail = color.FgHiRed

skipnotest bool
)

const paletteEnv = "GOTEST_PALETTE"
const (
paletteEnv = "GOTEST_PALETTE"
skipNoTestsEnv = "GOTEST_SKIPNOTESTS"
)

func main() {
setPalette()
enablePalette()
enableSkipNoTests()
enableOnCI()

flagSet := flag.NewFlagSet("gotestFlags", flag.ContinueOnError)
ignore = flagSet.Bool("skipnotest", false, "skip packages with no test files")
gotestFlags := make([]string, 0)
args := make([]string, 0)

//separate program specific flags from go test flags
for _, arg := range os.Args[1:] {
// if the argument is in gotest flags the add it to gotestFlags
lookup := flagSet.Lookup(strings.Trim(arg, "-"))
if lookup != nil {
gotestFlags = append(gotestFlags, arg)
} else {
args = append(args, arg)
}
}

flagSet.Parse(gotestFlags)
os.Exit(gotest(args))

os.Exit(gotest(os.Args[1:]))
}

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

var c color.Attribute
switch {
case strings.HasPrefix(trimmed, "=== RUN"):
fallthrough
case strings.HasPrefix(trimmed, "?"):
if *ignore {
case strings.Contains(trimmed, "[no test files]"):
if skipnotest {
return
}
color.Unset()

// passed
case strings.HasPrefix(trimmed, "--- PASS"):
case strings.HasPrefix(trimmed, "--- PASS"): // passed
fallthrough
case strings.HasPrefix(trimmed, "ok"):
fallthrough
Expand Down Expand Up @@ -168,7 +150,7 @@ func enableOnCI() {
}
}

func setPalette() {
func enablePalette() {
v := os.Getenv(paletteEnv)
if v == "" {
return
Expand All @@ -185,6 +167,15 @@ func setPalette() {
}
}

func enableSkipNoTests() {
v := os.Getenv(skipNoTestsEnv)
if v == "" {
return
}
v = strings.ToLower(v)
skipnotest = v == "true"
}

var colors = map[string]color.Attribute{
"black": color.FgBlack,
"hiblack": color.FgHiBlack,
Expand Down

0 comments on commit 08b5885

Please sign in to comment.