fixing illegal chars (just in case), copied from go-junit-report
This commit is contained in:
parent
3ce73b8db9
commit
f269c95ce4
25
cmd/go2junit/escape.go
Normal file
25
cmd/go2junit/escape.go
Normal file
@ -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)
|
||||
}
|
@ -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 {
|
||||
@ -143,7 +92,7 @@ func main() {
|
||||
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")
|
||||
@ -152,7 +101,7 @@ func main() {
|
||||
case "pass":
|
||||
testsuites.Pass(item.Time, pkg, item.Test)
|
||||
case "bench":
|
||||
testsuites.Bench(item.Time, pkg, item.Test, item.Output)
|
||||
testsuites.Bench(item.Time, pkg, item.Test, escapeIllegalChars(item.Output))
|
||||
case "fail":
|
||||
testsuites.Fail(item.Time, pkg, item.Test)
|
||||
case "skip":
|
||||
|
Loading…
Reference in New Issue
Block a user