Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove ANSI escape sequences from output #5

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading