Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f269c95ce4 | ||
|
|
3ce73b8db9 | ||
|
|
fe733f96d6 |
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "strings"
|
||||
|
||||
// copied from go-junit-report for fixing issues with chars that
|
||||
// are out of range.
|
||||
|
||||
// from encoding/xml/xml.go, replace chars by unknown char
|
||||
func isInCharacterRange(r rune) (inrange bool) {
|
||||
return r == 0x09 ||
|
||||
r == 0x0A ||
|
||||
r == 0x0D ||
|
||||
r >= 0x20 && r <= 0xD7FF ||
|
||||
r >= 0xE000 && r <= 0xFFFD ||
|
||||
r >= 0x10000 && r <= 0x10FFFF
|
||||
}
|
||||
|
||||
func escapeIllegalChars(str string) string {
|
||||
return strings.Map(func(r rune) rune {
|
||||
if isInCharacterRange(r) {
|
||||
return r
|
||||
}
|
||||
return '\uFFFD'
|
||||
}, str)
|
||||
}
|
||||
@@ -15,8 +15,8 @@ func (t *Test) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
if len(t.Tests) == 0 {
|
||||
start.Name = xml.Name{Local: "testcase"}
|
||||
classname := ""
|
||||
if t.Parent != nil {
|
||||
classname = t.Parent.Name
|
||||
if t.parent != nil {
|
||||
classname = t.parent.Name
|
||||
}
|
||||
var skipped *Result
|
||||
if t.Skipped > 0 {
|
||||
@@ -50,57 +50,6 @@ func (t *Test) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
/*
|
||||
testsuites := Testsuites{
|
||||
Time: 1.23,
|
||||
TImestamp: time.Now(),
|
||||
Suites: []*Testsuite{
|
||||
{
|
||||
Name: "hello",
|
||||
Tests: 0,
|
||||
Failures: 0,
|
||||
Errors: 0,
|
||||
Disabled: 0,
|
||||
Package: "",
|
||||
Skipped: 0,
|
||||
Time: "",
|
||||
Timestamp: time.Now(),
|
||||
Testsuites: []*Testsuite{
|
||||
{
|
||||
Name: "abc",
|
||||
Tests: 0,
|
||||
Failures: 0,
|
||||
Errors: 0,
|
||||
Disabled: 0,
|
||||
Package: "",
|
||||
Skipped: 0,
|
||||
Time: "",
|
||||
Timestamp: time.Time{},
|
||||
Testsuites: nil,
|
||||
Testcases: []*Testcase{
|
||||
{
|
||||
Name: "test",
|
||||
Classname: "",
|
||||
Time: "",
|
||||
Skipped: nil,
|
||||
Error: &Result{
|
||||
Message: "error",
|
||||
},
|
||||
Failure: nil,
|
||||
SystemOut: "",
|
||||
},
|
||||
},
|
||||
SystemOut: "ddd",
|
||||
},
|
||||
},
|
||||
Testcases: nil,
|
||||
SystemOut: "hello",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
testsuites := Testsuites{}
|
||||
|
||||
if len(os.Args) != 2 && len(os.Args) != 3 {
|
||||
@@ -138,23 +87,23 @@ func main() {
|
||||
pkg := prefix + item.Package
|
||||
switch item.Action {
|
||||
case "start":
|
||||
testsuites.Suite(item.Time, pkg)
|
||||
testsuites.Start(item.Time, pkg)
|
||||
case "run":
|
||||
fmt.Println()
|
||||
testsuites.Test(item.Time, pkg, item.Test)
|
||||
case "output":
|
||||
testsuites.Output(item.Time, pkg, item.Test, item.Output)
|
||||
testsuites.Output(item.Time, pkg, item.Test, escapeIllegalChars(item.Output))
|
||||
fmt.Printf("%s", item.Output)
|
||||
case "pause":
|
||||
testsuites.Output(item.Time, pkg, item.Test, "PAUSED")
|
||||
case "cont":
|
||||
testsuites.Output(item.Time, pkg, item.Test, "CONTINUED")
|
||||
case "pass":
|
||||
testsuites.Pass(item.Time, pkg, item.Test, item.Elapsed)
|
||||
testsuites.Pass(item.Time, pkg, item.Test)
|
||||
case "bench":
|
||||
testsuites.Bench(item.Time, pkg, item.Test, item.Output, item.Elapsed)
|
||||
testsuites.Bench(item.Time, pkg, item.Test, escapeIllegalChars(item.Output))
|
||||
case "fail":
|
||||
testsuites.Fail(item.Time, pkg, item.Test, item.Elapsed)
|
||||
testsuites.Fail(item.Time, pkg, item.Test)
|
||||
case "skip":
|
||||
testsuites.Skip(item.Time, pkg, item.Test)
|
||||
}
|
||||
|
||||
+15
-36
@@ -39,7 +39,8 @@ type Test struct {
|
||||
Tests []*Test `xml:"testsuite,omitempty"`
|
||||
SystemOut string `xml:"system-out,omitempty"`
|
||||
|
||||
Parent *Test `xml:"-"`
|
||||
parent *Test
|
||||
t0 time.Time
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
@@ -74,6 +75,7 @@ func (testsuites *Testsuites) getRootSuite(t time.Time, pkg string, create bool)
|
||||
Name: pkg,
|
||||
Skipped: 0,
|
||||
Timestamp: t,
|
||||
t0: t,
|
||||
}
|
||||
testsuites.Suites = append(testsuites.Suites, &suite)
|
||||
return &suite
|
||||
@@ -88,12 +90,16 @@ func (suite *Test) getSuite(t time.Time, name string) *Test {
|
||||
s := Test{
|
||||
Name: suite.Name + "/" + name,
|
||||
Timestamp: t,
|
||||
t0: t,
|
||||
}
|
||||
suite.Tests = append(suite.Tests, &s)
|
||||
return &s
|
||||
}
|
||||
|
||||
func (suite *Test) getTest(t time.Time, testname string) *Test {
|
||||
if testname == "" {
|
||||
return suite
|
||||
}
|
||||
suitename := suite.Name
|
||||
path := strings.Split(testname, "/")
|
||||
for i := 0; i < len(path); i++ {
|
||||
@@ -109,7 +115,7 @@ func (testsuites *Testsuites) getTest(t time.Time, pkg string, testname string)
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -119,56 +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) {
|
||||
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.SystemOut = tc.SystemOut + output
|
||||
}
|
||||
|
||||
func (testsuites *Testsuites) Pass(t time.Time, pkg string, test string, elapsed float64) {
|
||||
if test == "" {
|
||||
return
|
||||
}
|
||||
if testsuites.getRootSuite(t, pkg+"/"+test, false) != nil {
|
||||
return
|
||||
}
|
||||
func (testsuites *Testsuites) Pass(t time.Time, pkg string, test string) {
|
||||
tc := testsuites.getTest(t, pkg, test)
|
||||
tc.Time = elapsed
|
||||
tc.Time = float64(t.Sub(tc.t0).Nanoseconds()) / 1000_000_000.0
|
||||
}
|
||||
|
||||
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.SystemOut = tc.SystemOut + output + "\n"
|
||||
}
|
||||
|
||||
func (testsuites *Testsuites) Fail(t time.Time, pkg string, test string, elapsed float64) {
|
||||
if test == "" {
|
||||
return
|
||||
}
|
||||
if testsuites.getRootSuite(t, pkg+"/"+test, false) != nil {
|
||||
return
|
||||
}
|
||||
func (testsuites *Testsuites) Fail(t time.Time, pkg string, test string) {
|
||||
tc := testsuites.getTest(t, pkg, test)
|
||||
tc.Time = elapsed
|
||||
tc.Time = float64(t.Sub(tc.t0).Nanoseconds()) / 1000_000_000.0
|
||||
tc.Failures = 1
|
||||
}
|
||||
|
||||
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.Time = float64(t.Sub(tc.t0).Nanoseconds()) / 1000_000_000.0
|
||||
tc.Skipped = 1
|
||||
}
|
||||
|
||||
@@ -190,7 +169,7 @@ func (suite *Test) Complete() {
|
||||
suite.Errors += ts.Errors
|
||||
suite.Disabled += ts.Disabled
|
||||
suite.Skipped += ts.Skipped
|
||||
ts.Parent = suite
|
||||
ts.parent = suite
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user