Skip to content

Commit ad9f925

Browse files
joschiZexDC
andauthored
feat: remove ANSI escape sequences from output (#5)
Co-authored-by: ZexDC <[email protected]>
1 parent 534452a commit ad9f925

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/jstemmer/go-junit-report/v2
22

33
go 1.13
44

5-
require github.com/google/go-cmp v0.5.8
5+
require (
6+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
7+
github.com/google/go-cmp v0.5.8
8+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
2+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
13
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
24
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

junit/junit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/acarl005/stripansi"
13+
1214
"github.com/jstemmer/go-junit-report/v2/gtr"
1315
)
1416

@@ -255,6 +257,7 @@ func formatOutput(output []string) string {
255257
}
256258

257259
func escapeIllegalChars(str string) string {
260+
str = stripansi.Strip(str)
258261
return strings.Map(func(r rune) rune {
259262
if isInCharacterRange(r) {
260263
return r

junit/junit_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func TestCreateFromReport(t *testing.T) {
3232
Result: gtr.Pass,
3333
Output: []string{"\x00\v\f \t\\"},
3434
},
35+
{
36+
Name: "TestRemoveOutputANSI",
37+
Result: gtr.Pass,
38+
Output: []string{"This contains some", "\x1b[38;5;140mANSI\x1b[0m", "sequence"},
39+
},
3540
{
3641
Name: "TestFail",
3742
Result: gtr.Fail,
@@ -53,14 +58,14 @@ func TestCreateFromReport(t *testing.T) {
5358
}
5459

5560
want := Testsuites{
56-
Tests: 7,
61+
Tests: 8,
5762
Errors: 3,
5863
Failures: 1,
5964
Skipped: 1,
6065
Suites: []Testsuite{
6166
{
6267
Name: "package/name",
63-
Tests: 7,
68+
Tests: 8,
6469
Errors: 3,
6570
ID: 0,
6671
Failures: 1,
@@ -84,6 +89,12 @@ func TestCreateFromReport(t *testing.T) {
8489
Time: "0.000",
8590
SystemOut: &Output{Data: `��� \`},
8691
},
92+
{
93+
Name: "TestRemoveOutputANSI",
94+
Classname: "package/name",
95+
Time: "0.000",
96+
SystemOut: &Output{Data: "This contains some\nANSI\nsequence"},
97+
},
8798
{
8899
Name: "TestFail",
89100
Classname: "package/name",
@@ -193,8 +204,8 @@ func TestWriteXML(t *testing.T) {
193204

194205
var suites Testsuites
195206

196-
ts := Testsuite{Name:"Example"}
197-
ts.AddTestcase(Testcase{Name: "Test", })
207+
ts := Testsuite{Name: "Example"}
208+
ts.AddTestcase(Testcase{Name: "Test"})
198209
suites.AddSuite(ts)
199210

200211
var buf bytes.Buffer

0 commit comments

Comments
 (0)