mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-04 20:50:14 -05:00
parser/gotest: Set unique Test, Benchmark and Error ID's
This will be used later to collect and store output for the right tests.
This commit is contained in:
parent
5d691c7896
commit
2f7bf7c3bc
@ -251,6 +251,7 @@ func TestReport(t *testing.T) {
|
||||
Timestamp: testTimestamp,
|
||||
Tests: []gtr.Test{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "TestOne",
|
||||
Duration: 1 * time.Millisecond,
|
||||
Result: gtr.Pass,
|
||||
@ -259,6 +260,7 @@ func TestReport(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: 2,
|
||||
Name: "TestSkip",
|
||||
Duration: 1 * time.Millisecond,
|
||||
Result: gtr.Skip,
|
||||
@ -271,6 +273,7 @@ func TestReport(t *testing.T) {
|
||||
Timestamp: testTimestamp,
|
||||
Tests: []gtr.Test{
|
||||
{
|
||||
ID: 3,
|
||||
Name: "TestOne",
|
||||
Duration: 1 * time.Millisecond,
|
||||
Result: gtr.Fail,
|
||||
@ -286,11 +289,13 @@ func TestReport(t *testing.T) {
|
||||
Timestamp: testTimestamp,
|
||||
Benchmarks: []gtr.Benchmark{
|
||||
{
|
||||
ID: 4,
|
||||
Name: "BenchmarkOne",
|
||||
Result: gtr.Pass,
|
||||
NsPerOp: 100,
|
||||
},
|
||||
{
|
||||
ID: 5,
|
||||
Name: "BenchmarkTwo",
|
||||
Result: gtr.Fail,
|
||||
},
|
||||
@ -301,6 +306,7 @@ func TestReport(t *testing.T) {
|
||||
Name: "package/failing1",
|
||||
Timestamp: testTimestamp,
|
||||
BuildError: gtr.Error{
|
||||
ID: 6,
|
||||
Name: "package/failing1",
|
||||
Cause: "[build failed]",
|
||||
Output: []string{"error message"},
|
||||
@ -346,18 +352,21 @@ func TestSubtestModes(t *testing.T) {
|
||||
Timestamp: testTimestamp,
|
||||
Tests: []gtr.Test{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "TestParent",
|
||||
Duration: 1 * time.Millisecond,
|
||||
Result: gtr.Pass,
|
||||
Output: []string{"TestParent output"},
|
||||
},
|
||||
{
|
||||
ID: 2,
|
||||
Name: "TestParent/Subtest#1",
|
||||
Duration: 2 * time.Millisecond,
|
||||
Result: gtr.Fail,
|
||||
Output: []string{"Subtest#1 output"},
|
||||
},
|
||||
{
|
||||
ID: 3,
|
||||
Name: "TestParent/Subtest#2",
|
||||
Duration: 3 * time.Millisecond,
|
||||
Result: gtr.Pass,
|
||||
@ -379,12 +388,14 @@ func TestSubtestModes(t *testing.T) {
|
||||
Timestamp: testTimestamp,
|
||||
Tests: []gtr.Test{
|
||||
{
|
||||
ID: 2,
|
||||
Name: "TestParent/Subtest#1",
|
||||
Duration: 2 * time.Millisecond,
|
||||
Result: gtr.Fail,
|
||||
Output: []string{"Subtest#1 output"},
|
||||
},
|
||||
{
|
||||
ID: 3,
|
||||
Name: "TestParent/Subtest#2",
|
||||
Duration: 3 * time.Millisecond,
|
||||
Result: gtr.Pass,
|
||||
|
@ -78,7 +78,8 @@ func (b *reportBuilder) CreateTest(name string) {
|
||||
if parentID, ok := b.findTestParentID(name); ok {
|
||||
b.parentIDs[parentID] = struct{}{}
|
||||
}
|
||||
b.tests[b.newID()] = gtr.Test{Name: name}
|
||||
id := b.newID()
|
||||
b.tests[id] = gtr.Test{ID: id, Name: name}
|
||||
}
|
||||
|
||||
// PauseTest marks the active context as no longer active. Any results or
|
||||
@ -127,9 +128,8 @@ func (b *reportBuilder) End() {
|
||||
// most recently created benchmark will be updated. If no benchmark exists with
|
||||
// this name, a new benchmark is created.
|
||||
func (b *reportBuilder) CreateBenchmark(name string) {
|
||||
b.benchmarks[b.newID()] = gtr.Benchmark{
|
||||
Name: name,
|
||||
}
|
||||
id := b.newID()
|
||||
b.benchmarks[id] = gtr.Benchmark{ID: id, Name: name}
|
||||
}
|
||||
|
||||
// BenchmarkResult updates an existing or adds a new benchmark with the given
|
||||
@ -144,6 +144,7 @@ func (b *reportBuilder) BenchmarkResult(name string, iterations int64, nsPerOp,
|
||||
}
|
||||
|
||||
b.benchmarks[id] = gtr.Benchmark{
|
||||
ID: id,
|
||||
Name: name,
|
||||
Result: gtr.Pass,
|
||||
Iterations: iterations,
|
||||
@ -173,7 +174,8 @@ func (b *reportBuilder) EndBenchmark(name, result string) {
|
||||
|
||||
// CreateBuildError creates a new build error and marks it as active.
|
||||
func (b *reportBuilder) CreateBuildError(packageName string) {
|
||||
b.buildErrors[b.newID()] = gtr.Error{Name: packageName}
|
||||
id := b.newID()
|
||||
b.buildErrors[id] = gtr.Error{ID: id, Name: packageName}
|
||||
}
|
||||
|
||||
// CreatePackage adds a new package with the given name to the Report. This
|
||||
@ -197,6 +199,7 @@ func (b *reportBuilder) CreatePackage(name, result string, duration time.Duratio
|
||||
if len(b.tests) > 0 || len(b.benchmarks) > 0 {
|
||||
panic("unexpected tests and/or benchmarks found in build error package")
|
||||
}
|
||||
buildErr.ID = id
|
||||
buildErr.Duration = duration
|
||||
buildErr.Cause = data
|
||||
pkg.BuildError = buildErr
|
||||
@ -388,7 +391,7 @@ func groupBenchmarksByName(benchmarks []gtr.Benchmark) []gtr.Benchmark {
|
||||
byName := make(map[string][]gtr.Benchmark)
|
||||
for _, bm := range benchmarks {
|
||||
if _, ok := byName[bm.Name]; !ok {
|
||||
grouped = append(grouped, gtr.Benchmark{Name: bm.Name})
|
||||
grouped = append(grouped, gtr.Benchmark{ID: bm.ID, Name: bm.Name})
|
||||
}
|
||||
byName[bm.Name] = append(byName[bm.Name], bm)
|
||||
}
|
||||
|
@ -15,29 +15,29 @@ func TestGroupBenchmarksByName(t *testing.T) {
|
||||
}{
|
||||
{nil, nil},
|
||||
{
|
||||
[]gtr.Benchmark{{Name: "BenchmarkFailed", Result: gtr.Fail}},
|
||||
[]gtr.Benchmark{{Name: "BenchmarkFailed", Result: gtr.Fail}},
|
||||
[]gtr.Benchmark{{ID: 1, Name: "BenchmarkFailed", Result: gtr.Fail}},
|
||||
[]gtr.Benchmark{{ID: 1, Name: "BenchmarkFailed", Result: gtr.Fail}},
|
||||
},
|
||||
{
|
||||
[]gtr.Benchmark{
|
||||
{Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 10, MBPerSec: 400, BytesPerOp: 1, AllocsPerOp: 2},
|
||||
{Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 20, MBPerSec: 300, BytesPerOp: 1, AllocsPerOp: 4},
|
||||
{Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 30, MBPerSec: 200, BytesPerOp: 1, AllocsPerOp: 8},
|
||||
{Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 40, MBPerSec: 100, BytesPerOp: 5, AllocsPerOp: 2},
|
||||
{ID: 1, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 10, MBPerSec: 400, BytesPerOp: 1, AllocsPerOp: 2},
|
||||
{ID: 2, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 20, MBPerSec: 300, BytesPerOp: 1, AllocsPerOp: 4},
|
||||
{ID: 3, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 30, MBPerSec: 200, BytesPerOp: 1, AllocsPerOp: 8},
|
||||
{ID: 4, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 40, MBPerSec: 100, BytesPerOp: 5, AllocsPerOp: 2},
|
||||
},
|
||||
[]gtr.Benchmark{
|
||||
{Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 25, MBPerSec: 250, BytesPerOp: 2, AllocsPerOp: 4},
|
||||
{ID: 1, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 25, MBPerSec: 250, BytesPerOp: 2, AllocsPerOp: 4},
|
||||
},
|
||||
},
|
||||
{
|
||||
[]gtr.Benchmark{
|
||||
{Name: "BenchmarkMixed", Result: gtr.Unknown},
|
||||
{Name: "BenchmarkMixed", Result: gtr.Pass, NsPerOp: 10, MBPerSec: 400, BytesPerOp: 1, AllocsPerOp: 2},
|
||||
{Name: "BenchmarkMixed", Result: gtr.Pass, NsPerOp: 40, MBPerSec: 100, BytesPerOp: 3, AllocsPerOp: 4},
|
||||
{Name: "BenchmarkMixed", Result: gtr.Fail},
|
||||
{ID: 1, Name: "BenchmarkMixed", Result: gtr.Unknown},
|
||||
{ID: 2, Name: "BenchmarkMixed", Result: gtr.Pass, NsPerOp: 10, MBPerSec: 400, BytesPerOp: 1, AllocsPerOp: 2},
|
||||
{ID: 3, Name: "BenchmarkMixed", Result: gtr.Pass, NsPerOp: 40, MBPerSec: 100, BytesPerOp: 3, AllocsPerOp: 4},
|
||||
{ID: 4, Name: "BenchmarkMixed", Result: gtr.Fail},
|
||||
},
|
||||
[]gtr.Benchmark{
|
||||
{Name: "BenchmarkMixed", Result: gtr.Fail, NsPerOp: 25, MBPerSec: 250, BytesPerOp: 2, AllocsPerOp: 3},
|
||||
{ID: 1, Name: "BenchmarkMixed", Result: gtr.Fail, NsPerOp: 25, MBPerSec: 250, BytesPerOp: 2, AllocsPerOp: 3},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user