mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-05 05:00:15 -05:00
parser/gotest,gtr: Move Event type to package gtr
This commit is contained in:
parent
72cd8b3697
commit
ff2fc90eeb
@ -1,3 +1,20 @@
|
||||
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
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
|
||||
"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.
|
||||
func FromEvents(events []gotest.Event) Report {
|
||||
func FromEvents(events []Event) Report {
|
||||
report := NewReportBuilder()
|
||||
for _, ev := range events {
|
||||
switch ev.Type {
|
||||
|
@ -4,23 +4,21 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestFromEvents(t *testing.T) {
|
||||
events := []gtop.Event{
|
||||
{Type: "run_test", Id: 1, Name: "TestOne"},
|
||||
events := []Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{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: "run_test", Id: 2, Name: "TestSkip"},
|
||||
{Type: "end_test", Id: 2, Name: "TestSkip", Result: "SKIP", Duration: 1 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestSkip"},
|
||||
{Type: "end_test", Name: "TestSkip", Result: "SKIP", 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: "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: "summary", Result: "FAIL", Name: "package/name2", Duration: 1 * time.Millisecond},
|
||||
}
|
||||
|
@ -9,20 +9,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"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 (
|
||||
regexEndTest = regexp.MustCompile(`((?: )*)--- (PASS|FAIL|SKIP): ([^ ]+) \((\d+\.\d+)(?: seconds|s)\)`)
|
||||
regexStatus = regexp.MustCompile(`^(PASS|FAIL|SKIP)$`)
|
||||
@ -33,7 +23,7 @@ var (
|
||||
)
|
||||
|
||||
// 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{}
|
||||
|
||||
s := bufio.NewScanner(r)
|
||||
@ -48,7 +38,7 @@ func Parse(r io.Reader) ([]Event, error) {
|
||||
}
|
||||
|
||||
type parser struct {
|
||||
events []Event
|
||||
events []gtr.Event
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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) {
|
||||
p.add(Event{Type: "pause_test", Name: name})
|
||||
p.add(gtr.Event{Type: "pause_test", Name: name})
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -92,7 +82,7 @@ func (p *parser) endTest(line, indent, result, name, duration string) {
|
||||
p.output(line[:idx])
|
||||
}
|
||||
_, n := stripIndent(indent)
|
||||
p.add(Event{
|
||||
p.add(gtr.Event{
|
||||
Type: "end_test",
|
||||
Name: name,
|
||||
Result: result,
|
||||
@ -102,11 +92,11 @@ func (p *parser) endTest(line, indent, result, name, duration 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) {
|
||||
p.add(Event{
|
||||
p.add(gtr.Event{
|
||||
Type: "summary",
|
||||
Result: result,
|
||||
Name: name,
|
||||
@ -118,7 +108,7 @@ func (p *parser) summary(result, name, duration, data, covpct, packages string)
|
||||
}
|
||||
|
||||
func (p *parser) coverage(percent, packages string) {
|
||||
p.add(Event{
|
||||
p.add(gtr.Event{
|
||||
Type: "coverage",
|
||||
CovPct: parseCoverage(percent),
|
||||
CovPackages: parsePackages(packages),
|
||||
@ -126,7 +116,7 @@ func (p *parser) coverage(percent, packages 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 {
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jstemmer/go-junit-report/v2/pkg/gtr"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
@ -13,175 +15,175 @@ const testdataRoot = "../../../testdata/"
|
||||
|
||||
var tests = []struct {
|
||||
in string
|
||||
expected []Event
|
||||
expected []gtr.Event
|
||||
}{
|
||||
{"01-pass",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestZ"},
|
||||
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestZ"},
|
||||
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
|
||||
}},
|
||||
{"02-fail",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{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: Longer"},
|
||||
{Type: "output", Data: "\t\terror"},
|
||||
{Type: "output", Data: "\t\tmessage."},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
|
||||
{Type: "status", Result: "FAIL"},
|
||||
{Type: "output", Data: "exit status 1"},
|
||||
{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 151 * time.Millisecond},
|
||||
}},
|
||||
{"03-skip",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "SKIP", Duration: 20 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "SKIP", Duration: 20 * time.Millisecond},
|
||||
{Type: "output", Data: "\tfile_test.go:11: Skip message"},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name", Duration: 150 * time.Millisecond},
|
||||
}},
|
||||
{"04-go_1_4",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
|
||||
}},
|
||||
// Test 05 is skipped, because it was actually testing XML output
|
||||
{"06-mixed",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name1", Duration: 160 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 20 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{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: Longer"},
|
||||
{Type: "output", Data: "\t\terror"},
|
||||
{Type: "output", Data: "\t\tmessage."},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 130 * time.Millisecond},
|
||||
{Type: "status", Result: "FAIL"},
|
||||
{Type: "output", Data: "exit status 1"},
|
||||
{Type: "summary", Result: "FAIL", Name: "package/name2", Duration: 151 * time.Millisecond},
|
||||
}},
|
||||
{"07-compiled_test",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
}},
|
||||
{"08-parallel",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestDoFoo"},
|
||||
{Type: "run_test", Name: "TestDoFoo2"},
|
||||
{Type: "end_test", Name: "TestDoFoo", Result: "PASS", Duration: 270 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestDoFoo"},
|
||||
{Type: "run_test", Name: "TestDoFoo2"},
|
||||
{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 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 2"},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name", Duration: 440 * time.Millisecond},
|
||||
}},
|
||||
{"09-coverage",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestZ"},
|
||||
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestZ"},
|
||||
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "coverage", CovPct: 13.37},
|
||||
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
|
||||
}},
|
||||
{"10-multipkg-coverage",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestB"},
|
||||
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestB"},
|
||||
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "coverage", CovPct: 10},
|
||||
{Type: "summary", Result: "ok", Name: "package1/foo", Duration: 400 * time.Millisecond, CovPct: 10},
|
||||
{Type: "run_test", Name: "TestC"},
|
||||
{Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestC"},
|
||||
{Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "coverage", CovPct: 99.8},
|
||||
{Type: "summary", Result: "ok", Name: "package2/bar", Duration: 4200 * time.Millisecond, CovPct: 99.8},
|
||||
}},
|
||||
{"11-go_1_5",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 20 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 30 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 20 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestTwo"},
|
||||
{Type: "end_test", Name: "TestTwo", Result: "PASS", Duration: 30 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name", Duration: 50 * time.Millisecond},
|
||||
}},
|
||||
{"12-go_1_7",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "run_test", Name: "TestOne/Child"},
|
||||
{Type: "run_test", Name: "TestOne/Child#01"},
|
||||
{Type: "run_test", Name: "TestOne/Child=02"},
|
||||
{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#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: "run_test", Name: "TestTwo"},
|
||||
{Type: "run_test", Name: "TestTwo/Child"},
|
||||
{Type: "run_test", Name: "TestTwo/Child#01"},
|
||||
{Type: "run_test", Name: "TestTwo/Child=02"},
|
||||
{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#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: "run_test", Name: "TestThree"},
|
||||
{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/c#1"},
|
||||
{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/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: "run_test", Name: "TestFour"},
|
||||
{Type: "run_test", Name: "TestFour/#00"},
|
||||
{Type: "run_test", Name: "TestFour/#01"},
|
||||
{Type: "run_test", Name: "TestFour/#02"},
|
||||
{Type: "end_test", Name: "TestFour", Result: "FAIL", Duration: 20 * time.Millisecond},
|
||||
{Type: "end_test", Name: "TestFour/#00", Result: "FAIL", Indent: 1, Duration: 0},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "run_test", Name: "TestOne/Child"},
|
||||
{Type: "run_test", Name: "TestOne/Child#01"},
|
||||
{Type: "run_test", Name: "TestOne/Child=02"},
|
||||
{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#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: "run_test", Name: "TestTwo"},
|
||||
{Type: "run_test", Name: "TestTwo/Child"},
|
||||
{Type: "run_test", Name: "TestTwo/Child#01"},
|
||||
{Type: "run_test", Name: "TestTwo/Child=02"},
|
||||
{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#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: "run_test", Name: "TestThree"},
|
||||
{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/c#1"},
|
||||
{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/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: "run_test", Name: "TestFour"},
|
||||
{Type: "run_test", Name: "TestFour/#00"},
|
||||
{Type: "run_test", Name: "TestFour/#01"},
|
||||
{Type: "run_test", Name: "TestFour/#02"},
|
||||
{Type: "end_test", Name: "TestFour", Result: "FAIL", Duration: 20 * time.Millisecond},
|
||||
{Type: "end_test", Name: "TestFour/#00", Result: "FAIL", Indent: 1, Duration: 0},
|
||||
{Type: "output", Data: " \texample.go:12: Expected abc OBTAINED:"},
|
||||
{Type: "output", Data: " \t\txyz"},
|
||||
{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: "end_test", Name: "TestFour/#02", Result: "PASS", Indent: 1, Duration: 0},
|
||||
{Type: "run_test", Name: "TestFive"},
|
||||
{Type: "end_test", Name: "TestFive", Result: "SKIP", Duration: 0},
|
||||
{Type: "end_test", Name: "TestFour/#02", Result: "PASS", Indent: 1, Duration: 0},
|
||||
{Type: "run_test", Name: "TestFive"},
|
||||
{Type: "end_test", Name: "TestFive", Result: "SKIP", Duration: 0},
|
||||
{Type: "output", Data: "\texample.go:1392: Not supported yet."},
|
||||
{Type: "run_test", Name: "TestSix"},
|
||||
{Type: "end_test", Name: "TestSix", Result: "FAIL", Duration: 0},
|
||||
{Type: "run_test", Name: "TestSix"},
|
||||
{Type: "end_test", Name: "TestSix", Result: "FAIL", Duration: 0},
|
||||
{Type: "output", Data: "\texample.go:371: This should not fail!"},
|
||||
{Type: "status", Result: "FAIL"},
|
||||
{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 50 * time.Millisecond},
|
||||
}},
|
||||
{"13-syntax-error",
|
||||
[]Event{
|
||||
[]gtr.Event{
|
||||
{Type: "output", Data: "# package/name/failing1"},
|
||||
{Type: "output", Data: "failing1/failing_test.go:15: undefined: x"},
|
||||
{Type: "output", Data: "# package/name/failing2"},
|
||||
@ -191,12 +193,12 @@ var tests = []struct {
|
||||
{Type: "output", Data: " /path/vendor (vendor tree)"},
|
||||
{Type: "output", Data: " /path/go/root (from $GOROOT)"},
|
||||
{Type: "output", Data: " /path/go/path (from $GOPATH)"},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name/passing1", Duration: 100 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestB"},
|
||||
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestB"},
|
||||
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name/passing2", Duration: 100 * time.Millisecond},
|
||||
{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]"},
|
||||
}},
|
||||
{"14-panic",
|
||||
[]Event{
|
||||
[]gtr.Event{
|
||||
{Type: "output", Data: "panic: init"},
|
||||
{Type: "output", Data: "stacktrace"},
|
||||
{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},
|
||||
}},
|
||||
{"15-empty",
|
||||
[]Event{
|
||||
[]gtr.Event{
|
||||
{Type: "output", Data: "testing: warning: no tests to run"},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/empty", Duration: 1 * time.Millisecond},
|
||||
}},
|
||||
{"16-repeated-names",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestRepeat"},
|
||||
{Type: "end_test", Name: "TestRepeat", Result: "PASS"},
|
||||
{Type: "run_test", Name: "TestRepeat"},
|
||||
{Type: "end_test", Name: "TestRepeat", Result: "PASS"},
|
||||
{Type: "run_test", Name: "TestRepeat"},
|
||||
{Type: "end_test", Name: "TestRepeat", Result: "PASS"},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestRepeat"},
|
||||
{Type: "end_test", Name: "TestRepeat", Result: "PASS"},
|
||||
{Type: "run_test", Name: "TestRepeat"},
|
||||
{Type: "end_test", Name: "TestRepeat", Result: "PASS"},
|
||||
{Type: "run_test", Name: "TestRepeat"},
|
||||
{Type: "end_test", Name: "TestRepeat", Result: "PASS"},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/repeated-names", Duration: 1 * time.Millisecond},
|
||||
}},
|
||||
{"17-race",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestRace"},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestRace"},
|
||||
{Type: "output", Data: "test output"},
|
||||
{Type: "output", Data: "2 0xc4200153d0"},
|
||||
{Type: "output", Data: "=================="},
|
||||
@ -266,68 +268,68 @@ var tests = []struct {
|
||||
{Type: "output", Data: " main.main()"},
|
||||
{Type: "output", Data: " _test/_testmain.go:52 +0x20f"},
|
||||
{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: "status", Result: "FAIL"},
|
||||
{Type: "output", Data: "exit status 1"},
|
||||
{Type: "summary", Result: "FAIL", Name: "race_test", Duration: 15 * time.Millisecond},
|
||||
}},
|
||||
{"18-coverpkg",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestB"},
|
||||
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestB"},
|
||||
{Type: "end_test", Name: "TestB", Result: "PASS", Duration: 300 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{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: "run_test", Name: "TestC"},
|
||||
{Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestC"},
|
||||
{Type: "end_test", Name: "TestC", Result: "PASS", Duration: 4200 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{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"}},
|
||||
}},
|
||||
{"19-pass",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestZ"},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestZ"},
|
||||
{Type: "output", Data: "some inline text"},
|
||||
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "end_test", Name: "TestZ", Result: "PASS", Duration: 60 * time.Millisecond},
|
||||
{Type: "run_test", Name: "TestA"},
|
||||
{Type: "end_test", Name: "TestA", Result: "PASS", Duration: 100 * time.Millisecond},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/name", Duration: 160 * time.Millisecond},
|
||||
}},
|
||||
{"20-parallel",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "FirstTest"},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "FirstTest"},
|
||||
{Type: "output", Data: "Message from first"},
|
||||
{Type: "pause_test", Name: "FirstTest"},
|
||||
{Type: "run_test", Name: "SecondTest"},
|
||||
{Type: "pause_test", Name: "FirstTest"},
|
||||
{Type: "run_test", Name: "SecondTest"},
|
||||
{Type: "output", Data: "Message from second"},
|
||||
{Type: "pause_test", Name: "SecondTest"},
|
||||
{Type: "cont_test", Name: "FirstTest"},
|
||||
{Type: "pause_test", Name: "SecondTest"},
|
||||
{Type: "cont_test", Name: "FirstTest"},
|
||||
{Type: "output", Data: "Supplemental from first"},
|
||||
{Type: "run_test", Name: "ThirdTest"},
|
||||
{Type: "run_test", Name: "ThirdTest"},
|
||||
{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: "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: "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: "status", Result: "FAIL"},
|
||||
{Type: "output", Data: "exit status 1"},
|
||||
{Type: "summary", Result: "FAIL", Name: "pkg/parallel", Duration: 3010 * time.Millisecond},
|
||||
}},
|
||||
{"21-cached",
|
||||
[]Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS"},
|
||||
[]gtr.Event{
|
||||
{Type: "run_test", Name: "TestOne"},
|
||||
{Type: "end_test", Name: "TestOne", Result: "PASS"},
|
||||
{Type: "status", Result: "PASS"},
|
||||
{Type: "summary", Result: "ok", Name: "package/one", Data: "(cached)"},
|
||||
}},
|
||||
{"22-whitespace",
|
||||
[]Event{}},
|
||||
[]gtr.Event{}},
|
||||
}
|
||||
|
||||
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 {
|
||||
t.SkipNow()
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user