gtr: Add default package name to report

This commit is contained in:
Joël Stemmer 2019-10-06 17:44:31 +01:00
parent 79753fd332
commit 77ad1709cf
4 changed files with 16 additions and 11 deletions

View File

@ -53,7 +53,7 @@ func main() {
fmt.Printf("%02d: %#v\n", i, ev)
}
}
report := gtr.FromEvents(events)
report := gtr.FromEvents(events, *packageName)
if !*noXMLHeader {
fmt.Fprintf(os.Stdout, xml.Header)

View File

@ -1574,12 +1574,12 @@ func TestNewOutput(t *testing.T) {
}
t.Run(testCase.name, func(t *testing.T) {
testNewParser(testCase.name, testCase.reportName, t)
testNewParser(testCase.name, testCase.reportName, testCase.packageName, t)
})
}
}
func testNewParser(input, reportFile string, t *testing.T) {
func testNewParser(input, reportFile, packageName string, t *testing.T) {
file, err := os.Open("testdata/" + input)
if err != nil {
t.Fatal(err)
@ -1591,7 +1591,7 @@ func testNewParser(input, reportFile string, t *testing.T) {
t.Fatal(err)
}
report := gtr.FromEvents(events)
actual := gtr.JUnit(gtr.FromEvents(events, packageName))
actual, err := toXML(gtr.JUnit(report))
if err != nil {

View File

@ -15,19 +15,23 @@ type ReportBuilder struct {
nextId int // next free id
lastId int // last test id // TODO: stack?
output []string
// defaults
packageName string
}
func NewReportBuilder() *ReportBuilder {
func NewReportBuilder(packageName string) *ReportBuilder {
return &ReportBuilder{
tests: make(map[int]Test),
benchmarks: make(map[int]Benchmark),
nextId: 1,
packageName: packageName,
}
}
func (b *ReportBuilder) flush() {
if len(b.tests) > 0 {
b.CreatePackage("unknown", 0)
b.CreatePackage(b.packageName, 0)
}
}

View File

@ -59,8 +59,9 @@ type Benchmark struct {
}
// FromEvents creates a Report from the given list of events.
func FromEvents(events []Event) Report {
report := NewReportBuilder()
// TODO: make packageName optional option
func FromEvents(events []Event, packageName string) Report {
report := NewReportBuilder(packageName)
for _, ev := range events {
switch ev.Type {
case "run_test":