Skip to content

Commit

Permalink
feat: remove ANSI escape sequences from output (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: ZexDC <[email protected]>
  • Loading branch information
joschi and ZexDC authored Jun 27, 2024
1 parent 534452a commit ad9f925
Show file tree
Hide file tree
Showing 4 changed files with 24 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=
3 changes: 3 additions & 0 deletions junit/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"time"

"github.com/acarl005/stripansi"

"github.com/jstemmer/go-junit-report/v2/gtr"
)

Expand Down Expand Up @@ -255,6 +257,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: "TestRemoveOutputANSI",
Result: gtr.Pass,
Output: []string{"This contains some", "\x1b[38;5;140mANSI\x1b[0m", "sequence"},
},
{
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: "TestRemoveOutputANSI",
Classname: "package/name",
Time: "0.000",
SystemOut: &Output{Data: "This contains some\nANSI\nsequence"},
},
{
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 ad9f925

Please sign in to comment.