added a prefix option to separate test results

This commit is contained in:
Erik Brakkee 2024-11-22 21:34:52 +01:00
parent e20795e7b9
commit 74383ddcc0
2 changed files with 17 additions and 13 deletions

View File

@ -99,8 +99,8 @@ func main() {
testsuites := Testsuites{} testsuites := Testsuites{}
if len(os.Args) != 2 { if len(os.Args) != 2 && len(os.Args) != 3 {
fmt.Fprintf(os.Stderr, "Usage: go2junit <outputdir> \n") fmt.Fprintf(os.Stderr, "Usage: go2junit <outputdir> [<prefix>]\n")
os.Exit(1) os.Exit(1)
} }
path := os.Args[1] path := os.Args[1]
@ -109,6 +109,10 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
prefix := ""
if len(os.Args) == 3 {
prefix = os.Args[2]
}
var file = os.Stdin var file = os.Stdin
@ -127,26 +131,28 @@ func main() {
//.fmt.Printf("Parsed %d:\n%v\n\n", lineno, item) //.fmt.Printf("Parsed %d:\n%v\n\n", lineno, item)
pkg := prefix + item.Package
switch item.Action { switch item.Action {
case "start": case "start":
testsuites.Suite(item.Time, item.Package) testsuites.Suite(item.Time, pkg)
case "run": case "run":
testsuites.Test(item.Time, item.Package, item.Test) fmt.Println()
testsuites.Test(item.Time, pkg, item.Test)
case "output": case "output":
testsuites.Output(item.Time, item.Package, item.Test, item.Output) testsuites.Output(item.Time, pkg, item.Test, item.Output)
fmt.Printf("%s", item.Output) fmt.Printf("%s", item.Output)
case "pause": case "pause":
testsuites.Output(item.Time, item.Package, item.Test, "PAUSED") testsuites.Output(item.Time, pkg, item.Test, "PAUSED")
case "cont": case "cont":
testsuites.Output(item.Time, item.Package, item.Test, "CONTINUED") testsuites.Output(item.Time, pkg, item.Test, "CONTINUED")
case "pass": case "pass":
testsuites.Pass(item.Time, item.Package, item.Test, item.Elapsed) testsuites.Pass(item.Time, pkg, item.Test, item.Elapsed)
case "bench": case "bench":
testsuites.Bench(item.Time, item.Package, item.Test, item.Output, item.Elapsed) testsuites.Bench(item.Time, pkg, item.Test, item.Output, item.Elapsed)
case "fail": case "fail":
testsuites.Fail(item.Time, item.Package, item.Test, item.Elapsed) testsuites.Fail(item.Time, pkg, item.Test, item.Elapsed)
case "skip": case "skip":
testsuites.Skip(item.Time, item.Package, item.Test) testsuites.Skip(item.Time, pkg, item.Test)
} }
} }
testsuites.Complete() testsuites.Complete()

View File

@ -2,7 +2,6 @@ package main
import ( import (
"encoding/xml" "encoding/xml"
"log"
"strings" "strings"
"time" "time"
) )
@ -76,7 +75,6 @@ func (testsuites *Testsuites) getRootSuite(t time.Time, pkg string, create bool)
Skipped: 0, Skipped: 0,
Timestamp: t, Timestamp: t,
} }
log.Printf("Adding suite %s", pkg)
testsuites.Suites = append(testsuites.Suites, &suite) testsuites.Suites = append(testsuites.Suites, &suite)
return &suite return &suite
} }