parser/gotest,gtr: Move Event type to package gtr

This commit is contained in:
Joël Stemmer 2018-06-09 00:04:33 +01:00
parent 72cd8b3697
commit ff2fc90eeb
5 changed files with 179 additions and 173 deletions

View File

@ -1,3 +1,20 @@
package gtr package gtr
// TODO: define gtop.Event here for easy re-use across different parser import "time"
// TODO: provide some common types, or have a custom type (e.g.
// identifier:type, where identifier is a unique identifier for a particular
// parser.)
// Event is a single event in a test or benchmark.
type Event struct {
Type string
Name string
Result string
Duration time.Duration
Data string
Indent int
CovPct float64
CovPackages []string
}

View File

@ -7,7 +7,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
"github.com/jstemmer/go-junit-report/v2/pkg/junit" "github.com/jstemmer/go-junit-report/v2/pkg/junit"
) )
@ -68,7 +67,7 @@ type Test struct {
} }
// FromEvents creates a Report from the given list of events. // FromEvents creates a Report from the given list of events.
func FromEvents(events []gotest.Event) Report { func FromEvents(events []Event) Report {
report := NewReportBuilder() report := NewReportBuilder()
for _, ev := range events { for _, ev := range events {
switch ev.Type { switch ev.Type {

View File

@ -4,23 +4,21 @@ import (
"testing" "testing"
"time" "time"
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
) )
func TestFromEvents(t *testing.T) { func TestFromEvents(t *testing.T) {
events := []gtop.Event{ events := []Event{
{Type: "run_test", Id: 1, Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "output", Data: "\tHello"}, {Type: "output", Data: "\tHello"},
{Type: "end_test", Id: 1, Name: "TestOne", Result: "PASS", Duration: 1 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 1 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "run_test", Id: 2, Name: "TestSkip"}, {Type: "run_test", Name: "TestSkip"},
{Type: "end_test", Id: 2, Name: "TestSkip", Result: "SKIP", Duration: 1 * time.Millisecond}, {Type: "end_test", Name: "TestSkip", Result: "SKIP", Duration: 1 * time.Millisecond},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 1 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 1 * time.Millisecond},
{Type: "run_test", Id: 3, Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "output", Data: "\tfile_test.go:10: error"}, {Type: "output", Data: "\tfile_test.go:10: error"},
{Type: "end_test", Id: 3, Name: "TestOne", Result: "FAIL", Duration: 1 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 1 * time.Millisecond},
{Type: "status", Result: "FAIL"}, {Type: "status", Result: "FAIL"},
{Type: "summary", Result: "FAIL", Name: "package/name2", Duration: 1 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "package/name2", Duration: 1 * time.Millisecond},
} }

View File

@ -9,20 +9,10 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/jstemmer/go-junit-report/v2/pkg/gtr"
) )
type Event struct {
Type string
Name string
Result string
Duration time.Duration
Data string
Indent int
CovPct float64
CovPackages []string
}
var ( var (
regexEndTest = regexp.MustCompile(`((?: )*)--- (PASS|FAIL|SKIP): ([^ ]+) \((\d+\.\d+)(?: seconds|s)\)`) regexEndTest = regexp.MustCompile(`((?: )*)--- (PASS|FAIL|SKIP): ([^ ]+) \((\d+\.\d+)(?: seconds|s)\)`)
regexStatus = regexp.MustCompile(`^(PASS|FAIL|SKIP)$`) regexStatus = regexp.MustCompile(`^(PASS|FAIL|SKIP)$`)
@ -33,7 +23,7 @@ var (
) )
// Parse parses Go test output from the given io.Reader r. // Parse parses Go test output from the given io.Reader r.
func Parse(r io.Reader) ([]Event, error) { func Parse(r io.Reader) ([]gtr.Event, error) {
p := &parser{} p := &parser{}
s := bufio.NewScanner(r) s := bufio.NewScanner(r)
@ -48,7 +38,7 @@ func Parse(r io.Reader) ([]Event, error) {
} }
type parser struct { type parser struct {
events []Event events []gtr.Event
} }
func (p *parser) parseLine(line string) { func (p *parser) parseLine(line string) {
@ -71,20 +61,20 @@ func (p *parser) parseLine(line string) {
} }
} }
func (p *parser) add(event Event) { func (p *parser) add(event gtr.Event) {
p.events = append(p.events, event) p.events = append(p.events, event)
} }
func (p *parser) runTest(name string) { func (p *parser) runTest(name string) {
p.add(Event{Type: "run_test", Name: name}) p.add(gtr.Event{Type: "run_test", Name: name})
} }
func (p *parser) pauseTest(name string) { func (p *parser) pauseTest(name string) {
p.add(Event{Type: "pause_test", Name: name}) p.add(gtr.Event{Type: "pause_test", Name: name})
} }
func (p *parser) contTest(name string) { func (p *parser) contTest(name string) {
p.add(Event{Type: "cont_test", Name: name}) p.add(gtr.Event{Type: "cont_test", Name: name})
} }
func (p *parser) endTest(line, indent, result, name, duration string) { func (p *parser) endTest(line, indent, result, name, duration string) {
@ -92,7 +82,7 @@ func (p *parser) endTest(line, indent, result, name, duration string) {
p.output(line[:idx]) p.output(line[:idx])
} }
_, n := stripIndent(indent) _, n := stripIndent(indent)
p.add(Event{ p.add(gtr.Event{
Type: "end_test", Type: "end_test",
Name: name, Name: name,
Result: result, Result: result,
@ -102,11 +92,11 @@ func (p *parser) endTest(line, indent, result, name, duration string) {
} }
func (p *parser) status(result string) { func (p *parser) status(result string) {
p.add(Event{Type: "status", Result: result}) p.add(gtr.Event{Type: "status", Result: result})
} }
func (p *parser) summary(result, name, duration, data, covpct, packages string) { func (p *parser) summary(result, name, duration, data, covpct, packages string) {
p.add(Event{ p.add(gtr.Event{
Type: "summary", Type: "summary",
Result: result, Result: result,
Name: name, Name: name,
@ -118,7 +108,7 @@ func (p *parser) summary(result, name, duration, data, covpct, packages string)
} }
func (p *parser) coverage(percent, packages string) { func (p *parser) coverage(percent, packages string) {
p.add(Event{ p.add(gtr.Event{
Type: "coverage", Type: "coverage",
CovPct: parseCoverage(percent), CovPct: parseCoverage(percent),
CovPackages: parsePackages(packages), CovPackages: parsePackages(packages),
@ -126,7 +116,7 @@ func (p *parser) coverage(percent, packages string) {
} }
func (p *parser) output(line string) { func (p *parser) output(line string) {
p.add(Event{Type: "output", Data: line}) p.add(gtr.Event{Type: "output", Data: line})
} }
func parseSeconds(s string) time.Duration { func parseSeconds(s string) time.Duration {

View File

@ -6,6 +6,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/jstemmer/go-junit-report/v2/pkg/gtr"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
) )
@ -13,175 +15,175 @@ const testdataRoot = "../../../testdata/"
var tests = []struct { var tests = []struct {
in string in string
expected []Event expected []gtr.Event
}{ }{
{"01-pass", {"01-pass",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestZ"}, {Type: "run_test", Name: "TestZ"},
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond}, {Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
{Type: "run_test", Name: "TestA"}, {Type: "run_test", Name: "TestA"},
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
}}, }},
{"02-fail", {"02-fail",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond},
{Type: "output", Data: "\tfile_test.go:11: Error message"}, {Type: "output", Data: "\tfile_test.go:11: Error message"},
{Type: "output", Data: "\tfile_test.go:11: Longer"}, {Type: "output", Data: "\tfile_test.go:11: Longer"},
{Type: "output", Data: "\t\terror"}, {Type: "output", Data: "\t\terror"},
{Type: "output", Data: "\t\tmessage."}, {Type: "output", Data: "\t\tmessage."},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
{Type: "status", Result: "FAIL"}, {Type: "status", Result: "FAIL"},
{Type: "output", Data: "exit status 1"}, {Type: "output", Data: "exit status 1"},
{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 151 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "package/name", Duration: 151 * time.Millisecond},
}}, }},
{"03-skip", {"03-skip",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "SKIP", Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "SKIP", Duration: 20 * time.Millisecond},
{Type: "output", Data: "\tfile_test.go:11: Skip message"}, {Type: "output", Data: "\tfile_test.go:11: Skip message"},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 150 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 150 * time.Millisecond},
}}, }},
{"04-go_1_4", {"04-go_1_4",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
}}, }},
// Test 05 is skipped, because it was actually testing XML output // Test 05 is skipped, because it was actually testing XML output
{"06-mixed", {"06-mixed",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name1", Duration: 160 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name1", Duration: 160 * time.Millisecond},
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond},
{Type: "output", Data: "\tfile_test.go:11: Error message"}, {Type: "output", Data: "\tfile_test.go:11: Error message"},
{Type: "output", Data: "\tfile_test.go:11: Longer"}, {Type: "output", Data: "\tfile_test.go:11: Longer"},
{Type: "output", Data: "\t\terror"}, {Type: "output", Data: "\t\terror"},
{Type: "output", Data: "\t\tmessage."}, {Type: "output", Data: "\t\tmessage."},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
{Type: "status", Result: "FAIL"}, {Type: "status", Result: "FAIL"},
{Type: "output", Data: "exit status 1"}, {Type: "output", Data: "exit status 1"},
{Type: "summary", Result: "FAIL", Name: "package/name2", Duration: 151 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "package/name2", Duration: 151 * time.Millisecond},
}}, }},
{"07-compiled_test", {"07-compiled_test",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
}}, }},
{"08-parallel", {"08-parallel",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestDoFoo"}, {Type: "run_test", Name: "TestDoFoo"},
{Type: "run_test", Name: "TestDoFoo2"}, {Type: "run_test", Name: "TestDoFoo2"},
{Type: "end_test", Name: "TestDoFoo", Result: "PASS", Duration: 270 * time.Millisecond}, {Type: "end_test", Name: "TestDoFoo", Result: "PASS", Duration: 270 * time.Millisecond},
{Type: "output", Data: "\tcov_test.go:10: DoFoo log 1"}, {Type: "output", Data: "\tcov_test.go:10: DoFoo log 1"},
{Type: "output", Data: "\tcov_test.go:10: DoFoo log 2"}, {Type: "output", Data: "\tcov_test.go:10: DoFoo log 2"},
{Type: "end_test", Name: "TestDoFoo2", Result: "PASS", Duration: 160 * time.Millisecond}, {Type: "end_test", Name: "TestDoFoo2", Result: "PASS", Duration: 160 * time.Millisecond},
{Type: "output", Data: "\tcov_test.go:21: DoFoo2 log 1"}, {Type: "output", Data: "\tcov_test.go:21: DoFoo2 log 1"},
{Type: "output", Data: "\tcov_test.go:21: DoFoo2 log 2"}, {Type: "output", Data: "\tcov_test.go:21: DoFoo2 log 2"},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 440 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 440 * time.Millisecond},
}}, }},
{"09-coverage", {"09-coverage",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestZ"}, {Type: "run_test", Name: "TestZ"},
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond}, {Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
{Type: "run_test", Name: "TestA"}, {Type: "run_test", Name: "TestA"},
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "coverage", CovPct: 13.37}, {Type: "coverage", CovPct: 13.37},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
}}, }},
{"10-multipkg-coverage", {"10-multipkg-coverage",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestA"}, {Type: "run_test", Name: "TestA"},
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "run_test", Name: "TestB"}, {Type: "run_test", Name: "TestB"},
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond}, {Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "coverage", CovPct: 10}, {Type: "coverage", CovPct: 10},
{Type: "summary", Result: "ok", Name: "package1/foo", Duration: 400 * time.Millisecond, CovPct: 10}, {Type: "summary", Result: "ok", Name: "package1/foo", Duration: 400 * time.Millisecond, CovPct: 10},
{Type: "run_test", Name: "TestC"}, {Type: "run_test", Name: "TestC"},
{Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond}, {Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "coverage", CovPct: 99.8}, {Type: "coverage", CovPct: 99.8},
{Type: "summary", Result: "ok", Name: "package2/bar", Duration: 4200 * time.Millisecond, CovPct: 99.8}, {Type: "summary", Result: "ok", Name: "package2/bar", Duration: 4200 * time.Millisecond, CovPct: 99.8},
}}, }},
{"11-go_1_5", {"11-go_1_5",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 20 * time.Millisecond},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 30 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 30 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 50 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 50 * time.Millisecond},
}}, }},
{"12-go_1_7", {"12-go_1_7",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "run_test", Name: "TestOne/Child"}, {Type: "run_test", Name: "TestOne/Child"},
{Type: "run_test", Name: "TestOne/Child#01"}, {Type: "run_test", Name: "TestOne/Child#01"},
{Type: "run_test", Name: "TestOne/Child=02"}, {Type: "run_test", Name: "TestOne/Child=02"},
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 10 * time.Millisecond}, {Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 10 * time.Millisecond},
{Type: "end_test", Name: "TestOne/Child", Result: "PASS", Indent: 1, Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestOne/Child", Result: "PASS", Indent: 1, Duration: 20 * time.Millisecond},
{Type: "end_test", Name: "TestOne/Child#01", Result: "PASS", Indent: 1, Duration: 30 * time.Millisecond}, {Type: "end_test", Name: "TestOne/Child#01", Result: "PASS", Indent: 1, Duration: 30 * time.Millisecond},
{Type: "end_test", Name: "TestOne/Child=02", Result: "PASS", Indent: 1, Duration: 40 * time.Millisecond}, {Type: "end_test", Name: "TestOne/Child=02", Result: "PASS", Indent: 1, Duration: 40 * time.Millisecond},
{Type: "run_test", Name: "TestTwo"}, {Type: "run_test", Name: "TestTwo"},
{Type: "run_test", Name: "TestTwo/Child"}, {Type: "run_test", Name: "TestTwo/Child"},
{Type: "run_test", Name: "TestTwo/Child#01"}, {Type: "run_test", Name: "TestTwo/Child#01"},
{Type: "run_test", Name: "TestTwo/Child=02"}, {Type: "run_test", Name: "TestTwo/Child=02"},
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 10 * time.Millisecond}, {Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 10 * time.Millisecond},
{Type: "end_test", Name: "TestTwo/Child", Result: "PASS", Indent: 1, Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestTwo/Child", Result: "PASS", Indent: 1, Duration: 20 * time.Millisecond},
{Type: "end_test", Name: "TestTwo/Child#01", Result: "PASS", Indent: 1, Duration: 30 * time.Millisecond}, {Type: "end_test", Name: "TestTwo/Child#01", Result: "PASS", Indent: 1, Duration: 30 * time.Millisecond},
{Type: "end_test", Name: "TestTwo/Child=02", Result: "PASS", Indent: 1, Duration: 40 * time.Millisecond}, {Type: "end_test", Name: "TestTwo/Child=02", Result: "PASS", Indent: 1, Duration: 40 * time.Millisecond},
{Type: "run_test", Name: "TestThree"}, {Type: "run_test", Name: "TestThree"},
{Type: "run_test", Name: "TestThree/a#1"}, {Type: "run_test", Name: "TestThree/a#1"},
{Type: "run_test", Name: "TestThree/a#1/b#1"}, {Type: "run_test", Name: "TestThree/a#1/b#1"},
{Type: "run_test", Name: "TestThree/a#1/b#1/c#1"}, {Type: "run_test", Name: "TestThree/a#1/b#1/c#1"},
{Type: "end_test", Name: "TestThree", Result: "PASS", Duration: 10 * time.Millisecond}, {Type: "end_test", Name: "TestThree", Result: "PASS", Duration: 10 * time.Millisecond},
{Type: "end_test", Name: "TestThree/a#1", Result: "PASS", Indent: 1, Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestThree/a#1", Result: "PASS", Indent: 1, Duration: 20 * time.Millisecond},
{Type: "end_test", Name: "TestThree/a#1/b#1", Result: "PASS", Indent: 2, Duration: 30 * time.Millisecond}, {Type: "end_test", Name: "TestThree/a#1/b#1", Result: "PASS", Indent: 2, Duration: 30 * time.Millisecond},
{Type: "end_test", Name: "TestThree/a#1/b#1/c#1", Result: "PASS", Indent: 3, Duration: 40 * time.Millisecond}, {Type: "end_test", Name: "TestThree/a#1/b#1/c#1", Result: "PASS", Indent: 3, Duration: 40 * time.Millisecond},
{Type: "run_test", Name: "TestFour"}, {Type: "run_test", Name: "TestFour"},
{Type: "run_test", Name: "TestFour/#00"}, {Type: "run_test", Name: "TestFour/#00"},
{Type: "run_test", Name: "TestFour/#01"}, {Type: "run_test", Name: "TestFour/#01"},
{Type: "run_test", Name: "TestFour/#02"}, {Type: "run_test", Name: "TestFour/#02"},
{Type: "end_test", Name: "TestFour", Result: "FAIL", Duration: 20 * time.Millisecond}, {Type: "end_test", Name: "TestFour", Result: "FAIL", Duration: 20 * time.Millisecond},
{Type: "end_test", Name: "TestFour/#00", Result: "FAIL", Indent: 1, Duration: 0}, {Type: "end_test", Name: "TestFour/#00", Result: "FAIL", Indent: 1, Duration: 0},
{Type: "output", Data: " \texample.go:12: Expected abc OBTAINED:"}, {Type: "output", Data: " \texample.go:12: Expected abc OBTAINED:"},
{Type: "output", Data: " \t\txyz"}, {Type: "output", Data: " \t\txyz"},
{Type: "output", Data: " \texample.go:123: Expected and obtained are different."}, {Type: "output", Data: " \texample.go:123: Expected and obtained are different."},
{Type: "end_test", Name: "TestFour/#01", Result: "SKIP", Indent: 1, Duration: 0}, {Type: "end_test", Name: "TestFour/#01", Result: "SKIP", Indent: 1, Duration: 0},
{Type: "output", Data: " \texample.go:1234: Not supported yet."}, {Type: "output", Data: " \texample.go:1234: Not supported yet."},
{Type: "end_test", Name: "TestFour/#02", Result: "PASS", Indent: 1, Duration: 0}, {Type: "end_test", Name: "TestFour/#02", Result: "PASS", Indent: 1, Duration: 0},
{Type: "run_test", Name: "TestFive"}, {Type: "run_test", Name: "TestFive"},
{Type: "end_test", Name: "TestFive", Result: "SKIP", Duration: 0}, {Type: "end_test", Name: "TestFive", Result: "SKIP", Duration: 0},
{Type: "output", Data: "\texample.go:1392: Not supported yet."}, {Type: "output", Data: "\texample.go:1392: Not supported yet."},
{Type: "run_test", Name: "TestSix"}, {Type: "run_test", Name: "TestSix"},
{Type: "end_test", Name: "TestSix", Result: "FAIL", Duration: 0}, {Type: "end_test", Name: "TestSix", Result: "FAIL", Duration: 0},
{Type: "output", Data: "\texample.go:371: This should not fail!"}, {Type: "output", Data: "\texample.go:371: This should not fail!"},
{Type: "status", Result: "FAIL"}, {Type: "status", Result: "FAIL"},
{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 50 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "package/name", Duration: 50 * time.Millisecond},
}}, }},
{"13-syntax-error", {"13-syntax-error",
[]Event{ []gtr.Event{
{Type: "output", Data: "# package/name/failing1"}, {Type: "output", Data: "# package/name/failing1"},
{Type: "output", Data: "failing1/failing_test.go:15: undefined: x"}, {Type: "output", Data: "failing1/failing_test.go:15: undefined: x"},
{Type: "output", Data: "# package/name/failing2"}, {Type: "output", Data: "# package/name/failing2"},
@ -191,12 +193,12 @@ var tests = []struct {
{Type: "output", Data: " /path/vendor (vendor tree)"}, {Type: "output", Data: " /path/vendor (vendor tree)"},
{Type: "output", Data: " /path/go/root (from $GOROOT)"}, {Type: "output", Data: " /path/go/root (from $GOROOT)"},
{Type: "output", Data: " /path/go/path (from $GOPATH)"}, {Type: "output", Data: " /path/go/path (from $GOPATH)"},
{Type: "run_test", Name: "TestA"}, {Type: "run_test", Name: "TestA"},
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name/passing1", Duration: 100 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name/passing1", Duration: 100 * time.Millisecond},
{Type: "run_test", Name: "TestB"}, {Type: "run_test", Name: "TestB"},
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestB", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name/passing2", Duration: 100 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name/passing2", Duration: 100 * time.Millisecond},
{Type: "summary", Result: "FAIL", Name: "package/name/failing1", Data: "[build failed]"}, {Type: "summary", Result: "FAIL", Name: "package/name/failing1", Data: "[build failed]"},
@ -204,7 +206,7 @@ var tests = []struct {
{Type: "summary", Result: "FAIL", Name: "package/name/setupfailing1", Data: "[setup failed]"}, {Type: "summary", Result: "FAIL", Name: "package/name/setupfailing1", Data: "[setup failed]"},
}}, }},
{"14-panic", {"14-panic",
[]Event{ []gtr.Event{
{Type: "output", Data: "panic: init"}, {Type: "output", Data: "panic: init"},
{Type: "output", Data: "stacktrace"}, {Type: "output", Data: "stacktrace"},
{Type: "summary", Result: "FAIL", Name: "package/panic", Duration: 3 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "package/panic", Duration: 3 * time.Millisecond},
@ -213,25 +215,25 @@ var tests = []struct {
{Type: "summary", Result: "FAIL", Name: "package/panic2", Duration: 3 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "package/panic2", Duration: 3 * time.Millisecond},
}}, }},
{"15-empty", {"15-empty",
[]Event{ []gtr.Event{
{Type: "output", Data: "testing: warning: no tests to run"}, {Type: "output", Data: "testing: warning: no tests to run"},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/empty", Duration: 1 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/empty", Duration: 1 * time.Millisecond},
}}, }},
{"16-repeated-names", {"16-repeated-names",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestRepeat"}, {Type: "run_test", Name: "TestRepeat"},
{Type: "end_test", Name: "TestRepeat", Result: "PASS"}, {Type: "end_test", Name: "TestRepeat", Result: "PASS"},
{Type: "run_test", Name: "TestRepeat"}, {Type: "run_test", Name: "TestRepeat"},
{Type: "end_test", Name: "TestRepeat", Result: "PASS"}, {Type: "end_test", Name: "TestRepeat", Result: "PASS"},
{Type: "run_test", Name: "TestRepeat"}, {Type: "run_test", Name: "TestRepeat"},
{Type: "end_test", Name: "TestRepeat", Result: "PASS"}, {Type: "end_test", Name: "TestRepeat", Result: "PASS"},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/repeated-names", Duration: 1 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/repeated-names", Duration: 1 * time.Millisecond},
}}, }},
{"17-race", {"17-race",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestRace"}, {Type: "run_test", Name: "TestRace"},
{Type: "output", Data: "test output"}, {Type: "output", Data: "test output"},
{Type: "output", Data: "2 0xc4200153d0"}, {Type: "output", Data: "2 0xc4200153d0"},
{Type: "output", Data: "=================="}, {Type: "output", Data: "=================="},
@ -266,68 +268,68 @@ var tests = []struct {
{Type: "output", Data: " main.main()"}, {Type: "output", Data: " main.main()"},
{Type: "output", Data: " _test/_testmain.go:52 +0x20f"}, {Type: "output", Data: " _test/_testmain.go:52 +0x20f"},
{Type: "output", Data: "=================="}, {Type: "output", Data: "=================="},
{Type: "end_test", Name: "TestRace", Result: "FAIL"}, {Type: "end_test", Name: "TestRace", Result: "FAIL"},
{Type: "output", Data: "\ttesting.go:610: race detected during execution of test"}, {Type: "output", Data: "\ttesting.go:610: race detected during execution of test"},
{Type: "status", Result: "FAIL"}, {Type: "status", Result: "FAIL"},
{Type: "output", Data: "exit status 1"}, {Type: "output", Data: "exit status 1"},
{Type: "summary", Result: "FAIL", Name: "race_test", Duration: 15 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "race_test", Duration: 15 * time.Millisecond},
}}, }},
{"18-coverpkg", {"18-coverpkg",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestA"}, {Type: "run_test", Name: "TestA"},
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "run_test", Name: "TestB"}, {Type: "run_test", Name: "TestB"},
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond}, {Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "coverage", CovPct: 10, CovPackages: []string{"fmt", "encoding/xml"}}, {Type: "coverage", CovPct: 10, CovPackages: []string{"fmt", "encoding/xml"}},
{Type: "summary", Result: "ok", Name: "package1/foo", Duration: 400 * time.Millisecond, CovPct: 10, CovPackages: []string{"fmt", "encoding/xml"}}, {Type: "summary", Result: "ok", Name: "package1/foo", Duration: 400 * time.Millisecond, CovPct: 10, CovPackages: []string{"fmt", "encoding/xml"}},
{Type: "run_test", Name: "TestC"}, {Type: "run_test", Name: "TestC"},
{Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond}, {Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "coverage", CovPct: 99.8, CovPackages: []string{"fmt", "encoding/xml"}}, {Type: "coverage", CovPct: 99.8, CovPackages: []string{"fmt", "encoding/xml"}},
{Type: "summary", Result: "ok", Name: "package2/bar", Duration: 4200 * time.Millisecond, CovPct: 99.8, CovPackages: []string{"fmt", "encoding/xml"}}, {Type: "summary", Result: "ok", Name: "package2/bar", Duration: 4200 * time.Millisecond, CovPct: 99.8, CovPackages: []string{"fmt", "encoding/xml"}},
}}, }},
{"19-pass", {"19-pass",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestZ"}, {Type: "run_test", Name: "TestZ"},
{Type: "output", Data: "some inline text"}, {Type: "output", Data: "some inline text"},
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond}, {Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
{Type: "run_test", Name: "TestA"}, {Type: "run_test", Name: "TestA"},
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond}, {Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond}, {Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
}}, }},
{"20-parallel", {"20-parallel",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "FirstTest"}, {Type: "run_test", Name: "FirstTest"},
{Type: "output", Data: "Message from first"}, {Type: "output", Data: "Message from first"},
{Type: "pause_test", Name: "FirstTest"}, {Type: "pause_test", Name: "FirstTest"},
{Type: "run_test", Name: "SecondTest"}, {Type: "run_test", Name: "SecondTest"},
{Type: "output", Data: "Message from second"}, {Type: "output", Data: "Message from second"},
{Type: "pause_test", Name: "SecondTest"}, {Type: "pause_test", Name: "SecondTest"},
{Type: "cont_test", Name: "FirstTest"}, {Type: "cont_test", Name: "FirstTest"},
{Type: "output", Data: "Supplemental from first"}, {Type: "output", Data: "Supplemental from first"},
{Type: "run_test", Name: "ThirdTest"}, {Type: "run_test", Name: "ThirdTest"},
{Type: "output", Data: "Message from third"}, {Type: "output", Data: "Message from third"},
{Type: "end_test", Name: "ThirdTest", Result: "FAIL", Duration: 10 * time.Millisecond}, {Type: "end_test", Name: "ThirdTest", Result: "FAIL", Duration: 10 * time.Millisecond},
{Type: "output", Data: "\tparallel_test.go:32: ThirdTest error"}, {Type: "output", Data: "\tparallel_test.go:32: ThirdTest error"},
{Type: "end_test", Name: "FirstTest", Result: "FAIL", Duration: 2 * time.Second}, {Type: "end_test", Name: "FirstTest", Result: "FAIL", Duration: 2 * time.Second},
{Type: "output", Data: "\tparallel_test.go:14: FirstTest error"}, {Type: "output", Data: "\tparallel_test.go:14: FirstTest error"},
{Type: "end_test", Name: "SecondTest", Result: "FAIL", Duration: 1 * time.Second}, {Type: "end_test", Name: "SecondTest", Result: "FAIL", Duration: 1 * time.Second},
{Type: "output", Data: "\tparallel_test.go:23: SecondTest error"}, {Type: "output", Data: "\tparallel_test.go:23: SecondTest error"},
{Type: "status", Result: "FAIL"}, {Type: "status", Result: "FAIL"},
{Type: "output", Data: "exit status 1"}, {Type: "output", Data: "exit status 1"},
{Type: "summary", Result: "FAIL", Name: "pkg/parallel", Duration: 3010 * time.Millisecond}, {Type: "summary", Result: "FAIL", Name: "pkg/parallel", Duration: 3010 * time.Millisecond},
}}, }},
{"21-cached", {"21-cached",
[]Event{ []gtr.Event{
{Type: "run_test", Name: "TestOne"}, {Type: "run_test", Name: "TestOne"},
{Type: "end_test", Name: "TestOne", Result: "PASS"}, {Type: "end_test", Name: "TestOne", Result: "PASS"},
{Type: "status", Result: "PASS"}, {Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/one", Data: "(cached)"}, {Type: "summary", Result: "ok", Name: "package/one", Data: "(cached)"},
}}, }},
{"22-whitespace", {"22-whitespace",
[]Event{}}, []gtr.Event{}},
} }
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
@ -338,7 +340,7 @@ func TestParse(t *testing.T) {
} }
} }
func testParse(t *testing.T, name string, expected []Event) { func testParse(t *testing.T, name string, expected []gtr.Event) {
if len(expected) == 0 { if len(expected) == 0 {
t.SkipNow() t.SkipNow()
return return