Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ce73b8db9 | ||
|
|
fe733f96d6 | ||
|
|
7cf5827f22 | ||
|
|
09fd2cb2a4 | ||
|
|
74383ddcc0 |
+24
-14
@@ -5,16 +5,18 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *Test) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
func (t *Test) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||||
if len(t.Tests) == 0 {
|
if len(t.Tests) == 0 {
|
||||||
start.Name = xml.Name{Local: "testcase"}
|
start.Name = xml.Name{Local: "testcase"}
|
||||||
classname := ""
|
classname := ""
|
||||||
if t.Parent != nil {
|
if t.parent != nil {
|
||||||
classname = t.Parent.Name
|
classname = t.parent.Name
|
||||||
}
|
}
|
||||||
var skipped *Result
|
var skipped *Result
|
||||||
if t.Skipped > 0 {
|
if t.Skipped > 0 {
|
||||||
@@ -28,8 +30,10 @@ func (t *Test) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|||||||
Message: "failed",
|
Message: "failed",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Printf("TIME %f", t.Time)
|
||||||
|
parts := strings.Split(t.Name, "/")
|
||||||
tc := Testcase{
|
tc := Testcase{
|
||||||
Name: t.Name,
|
Name: parts[len(parts)-1],
|
||||||
// parent class name
|
// parent class name
|
||||||
Classname: classname,
|
Classname: classname,
|
||||||
Time: t.Time,
|
Time: t.Time,
|
||||||
@@ -99,8 +103,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 +113,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 +135,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.Start(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)
|
||||||
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)
|
||||||
case "fail":
|
case "fail":
|
||||||
testsuites.Fail(item.Time, item.Package, item.Test, item.Elapsed)
|
testsuites.Fail(item.Time, pkg, item.Test)
|
||||||
case "skip":
|
case "skip":
|
||||||
testsuites.Skip(item.Time, item.Package, item.Test)
|
testsuites.Skip(item.Time, pkg, item.Test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testsuites.Complete()
|
testsuites.Complete()
|
||||||
|
|||||||
+16
-37
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -40,7 +39,8 @@ type Test struct {
|
|||||||
Tests []*Test `xml:"testsuite,omitempty"`
|
Tests []*Test `xml:"testsuite,omitempty"`
|
||||||
SystemOut string `xml:"system-out,omitempty"`
|
SystemOut string `xml:"system-out,omitempty"`
|
||||||
|
|
||||||
Parent *Test `xml:"-"`
|
parent *Test
|
||||||
|
t0 time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
@@ -75,8 +75,8 @@ func (testsuites *Testsuites) getRootSuite(t time.Time, pkg string, create bool)
|
|||||||
Name: pkg,
|
Name: pkg,
|
||||||
Skipped: 0,
|
Skipped: 0,
|
||||||
Timestamp: t,
|
Timestamp: t,
|
||||||
|
t0: t,
|
||||||
}
|
}
|
||||||
log.Printf("Adding suite %s", pkg)
|
|
||||||
testsuites.Suites = append(testsuites.Suites, &suite)
|
testsuites.Suites = append(testsuites.Suites, &suite)
|
||||||
return &suite
|
return &suite
|
||||||
}
|
}
|
||||||
@@ -90,12 +90,16 @@ func (suite *Test) getSuite(t time.Time, name string) *Test {
|
|||||||
s := Test{
|
s := Test{
|
||||||
Name: suite.Name + "/" + name,
|
Name: suite.Name + "/" + name,
|
||||||
Timestamp: t,
|
Timestamp: t,
|
||||||
|
t0: t,
|
||||||
}
|
}
|
||||||
suite.Tests = append(suite.Tests, &s)
|
suite.Tests = append(suite.Tests, &s)
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *Test) getTest(t time.Time, testname string) *Test {
|
func (suite *Test) getTest(t time.Time, testname string) *Test {
|
||||||
|
if testname == "" {
|
||||||
|
return suite
|
||||||
|
}
|
||||||
suitename := suite.Name
|
suitename := suite.Name
|
||||||
path := strings.Split(testname, "/")
|
path := strings.Split(testname, "/")
|
||||||
for i := 0; i < len(path); i++ {
|
for i := 0; i < len(path); i++ {
|
||||||
@@ -111,7 +115,7 @@ func (testsuites *Testsuites) getTest(t time.Time, pkg string, testname string)
|
|||||||
return test
|
return test
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testsuites *Testsuites) Suite(t time.Time, pkg string) {
|
func (testsuites *Testsuites) Start(t time.Time, pkg string) {
|
||||||
testsuites.getRootSuite(t, pkg, true)
|
testsuites.getRootSuite(t, pkg, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,54 +125,29 @@ func (testsuites *Testsuites) Test(t time.Time, pkg string, test string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (testsuites *Testsuites) Output(t time.Time, pkg string, test string, output string) {
|
func (testsuites *Testsuites) Output(t time.Time, pkg string, test string, output string) {
|
||||||
if test == "" {
|
|
||||||
ts := testsuites.getRootSuite(t, pkg, true)
|
|
||||||
ts.SystemOut = ts.SystemOut + output
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ts := testsuites.getRootSuite(t, pkg+"/"+test, false)
|
|
||||||
if ts != nil {
|
|
||||||
ts.SystemOut = ts.SystemOut + output
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tc := testsuites.getTest(t, pkg, test)
|
tc := testsuites.getTest(t, pkg, test)
|
||||||
tc.SystemOut = tc.SystemOut + output
|
tc.SystemOut = tc.SystemOut + output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testsuites *Testsuites) Pass(t time.Time, pkg string, test string, elapsed float64) {
|
func (testsuites *Testsuites) Pass(t time.Time, pkg string, test string) {
|
||||||
if test == "" {
|
tc := testsuites.getTest(t, pkg, test)
|
||||||
return
|
tc.Time = float64(t.Sub(tc.t0).Nanoseconds()) / 1000_000_000.0
|
||||||
}
|
|
||||||
if testsuites.getRootSuite(t, pkg+"/"+test, false) != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testsuites *Testsuites) Bench(t time.Time, pkg string, test string, output string, elapsed float64) {
|
func (testsuites *Testsuites) Bench(t time.Time, pkg string, test string, output string) {
|
||||||
tc := testsuites.getTest(t, pkg, test)
|
tc := testsuites.getTest(t, pkg, test)
|
||||||
tc.SystemOut = tc.SystemOut + output + "\n"
|
tc.SystemOut = tc.SystemOut + output + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testsuites *Testsuites) Fail(t time.Time, pkg string, test string, elapsed float64) {
|
func (testsuites *Testsuites) Fail(t time.Time, pkg string, test string) {
|
||||||
if test == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if testsuites.getRootSuite(t, pkg+"/"+test, false) != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tc := testsuites.getTest(t, pkg, test)
|
tc := testsuites.getTest(t, pkg, test)
|
||||||
tc.Time = elapsed
|
tc.Time = float64(t.Sub(tc.t0).Nanoseconds()) / 1000_000_000.0
|
||||||
tc.Failures = 1
|
tc.Failures = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testsuites *Testsuites) Skip(t time.Time, pkg string, test string) {
|
func (testsuites *Testsuites) Skip(t time.Time, pkg string, test string) {
|
||||||
if test == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if testsuites.getRootSuite(t, pkg+"/"+test, false) != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tc := testsuites.getTest(t, pkg, test)
|
tc := testsuites.getTest(t, pkg, test)
|
||||||
|
tc.Time = float64(t.Sub(tc.t0).Nanoseconds()) / 1000_000_000.0
|
||||||
tc.Skipped = 1
|
tc.Skipped = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +169,7 @@ func (suite *Test) Complete() {
|
|||||||
suite.Errors += ts.Errors
|
suite.Errors += ts.Errors
|
||||||
suite.Disabled += ts.Disabled
|
suite.Disabled += ts.Disabled
|
||||||
suite.Skipped += ts.Skipped
|
suite.Skipped += ts.Skipped
|
||||||
ts.Parent = suite
|
ts.parent = suite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user