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

View File

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