diff --git a/go.mod b/go.mod index 40de11d1..30082839 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/jstemmer/go-junit-report/v2 go 1.13 -require github.com/google/go-cmp v0.5.8 +require ( + github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect + github.com/google/go-cmp v0.5.8 +) diff --git a/go.sum b/go.sum index e9b099ce..9541a1ca 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ +github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= +github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/junit/junit.go b/junit/junit.go index e87b6ed0..faed21b9 100644 --- a/junit/junit.go +++ b/junit/junit.go @@ -5,6 +5,7 @@ package junit import ( "encoding/xml" "fmt" + "github.com/acarl005/stripansi" "io" "strings" "time" @@ -255,6 +256,7 @@ func formatOutput(output []string) string { } func escapeIllegalChars(str string) string { + str = stripansi.Strip(str) return strings.Map(func(r rune) rune { if isInCharacterRange(r) { return r diff --git a/junit/junit_test.go b/junit/junit_test.go index b1fd4e57..ff6d7978 100644 --- a/junit/junit_test.go +++ b/junit/junit_test.go @@ -32,6 +32,11 @@ func TestCreateFromReport(t *testing.T) { Result: gtr.Pass, Output: []string{"\x00\v\f \t\\"}, }, + { + Name: "StripANSI", + Result: gtr.Pass, + Output: []string{"\x1b[38;5;140m foo\x1b[0m bar"}, + }, { Name: "TestFail", Result: gtr.Fail, @@ -53,14 +58,14 @@ func TestCreateFromReport(t *testing.T) { } want := Testsuites{ - Tests: 7, + Tests: 8, Errors: 3, Failures: 1, Skipped: 1, Suites: []Testsuite{ { Name: "package/name", - Tests: 7, + Tests: 8, Errors: 3, ID: 0, Failures: 1, @@ -84,6 +89,12 @@ func TestCreateFromReport(t *testing.T) { Time: "0.000", SystemOut: &Output{Data: `��� \`}, }, + { + Name: "StripANSI", + Classname: "package/name", + Time: "0.000", + SystemOut: &Output{Data: " foo bar"}, + }, { Name: "TestFail", Classname: "package/name", @@ -193,8 +204,8 @@ func TestWriteXML(t *testing.T) { var suites Testsuites - ts := Testsuite{Name:"Example"} - ts.AddTestcase(Testcase{Name: "Test", }) + ts := Testsuite{Name: "Example"} + ts.AddTestcase(Testcase{Name: "Test"}) suites.AddSuite(ts) var buf bytes.Buffer