Skip to content

Commit

Permalink
fix: strip ansi char from output
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jun 5, 2023
1 parent 124f5fc commit 613b2f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 2 additions & 0 deletions junit/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package junit
import (
"encoding/xml"
"fmt"
"github.com/acarl005/stripansi"
"io"
"strings"
"time"
Expand Down Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions junit/junit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 613b2f8

Please sign in to comment.