Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add summary counter failed/passed/skipped tests #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const (
skipNoTestsEnv = "GOTEST_SKIPNOTESTS"
)

type countStates struct {
pass int
skip int
fail int
}

func main() {
enablePalette()
enableSkipNoTests()
Expand Down Expand Up @@ -87,21 +93,27 @@ func gotest(args []string) int {

func consume(wg *sync.WaitGroup, r io.Reader) {
defer wg.Done()
counters := countStates{pass: 0, skip: 0, fail: 0}
reader := bufio.NewReader(r)
for {
l, _, err := reader.ReadLine()
if err == io.EOF {
return
break
}
if err != nil {
log.Print(err)
return
}
parse(string(l))
parse(string(l), &counters)
}
printCounters(counters)
}

func printCounters(c countStates) {
fmt.Printf("Pass: %d, Fail: %d, Skip: %d", c.pass, c.fail, c.skip)
}

func parse(line string) {
func parse(line string, counters *countStates) {
trimmed := strings.TrimSpace(line)
defer color.Unset()

Expand All @@ -118,16 +130,19 @@ func parse(line string) {
fallthrough
case strings.HasPrefix(trimmed, "PASS"):
c = pass
counters.pass++

// skipped
case strings.HasPrefix(trimmed, "--- SKIP"):
c = skip
counters.skip++

// failed
case strings.HasPrefix(trimmed, "--- FAIL"):
fallthrough
case strings.HasPrefix(trimmed, "FAIL"):
c = fail
counters.fail++
}

color.Set(c)
Expand Down