File tree Expand file tree Collapse file tree 5 files changed +39
-5
lines changed
parser/gotest/internal/collector Expand file tree Collapse file tree 5 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,24 @@ package collector
4
4
5
5
import (
6
6
"sort"
7
+ "strings"
7
8
"time"
9
+ "unicode"
8
10
)
9
11
10
12
// line is a single line of output captured at some point in time.
11
13
type line struct {
12
14
Timestamp time.Time
13
- Text string
15
+ text string
16
+ }
17
+
18
+ func (l line ) SafeText () string {
19
+ return strings .Map (func (r rune ) rune {
20
+ if unicode .IsControl (r ) && ! unicode .IsSpace (r ) {
21
+ return - 1
22
+ }
23
+ return r
24
+ }, l .text )
14
25
}
15
26
16
27
// Output stores output lines grouped by id. Output can be retrieved for one or
@@ -44,7 +55,7 @@ func (o *Output) Contains(id int) bool {
44
55
func (o * Output ) Get (id int ) []string {
45
56
var lines []string
46
57
for _ , line := range o .m [id ] {
47
- lines = append (lines , line .Text )
58
+ lines = append (lines , line .SafeText () )
48
59
}
49
60
return lines
50
61
}
@@ -61,7 +72,7 @@ func (o *Output) GetAll(ids ...int) []string {
61
72
})
62
73
var lines []string
63
74
for _ , line := range output {
64
- lines = append (lines , line .Text )
75
+ lines = append (lines , line .SafeText () )
65
76
}
66
77
return lines
67
78
}
Original file line number Diff line number Diff line change @@ -89,3 +89,12 @@ func TestMerge(t *testing.T) {
89
89
t .Errorf ("Get(2) after Merge(2, 1) incorrect (-want +got):\n %s" , diff )
90
90
}
91
91
}
92
+
93
+ func TestSafeText (t * testing.T ) {
94
+ l := line {text : "\t x\x00 y\x1b z\n " }
95
+ got := l .SafeText ()
96
+ want := "\t xyz\n "
97
+ if diff := cmp .Diff (want , got ); diff != "" {
98
+ t .Errorf ("SafeText() for %q incorrect (-want +got):\n %s" , l .text , diff )
99
+ }
100
+ }
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
- <testsuites tests =" 9 " >
3
- <testsuite name =" package/whitespace" tests =" 9 " failures =" 0" errors =" 0" id =" 0" hostname =" hostname" time =" 0.001" timestamp =" 2022-01-01T00:00:00Z" >
2
+ <testsuites tests =" 11 " >
3
+ <testsuite name =" package/whitespace" tests =" 11 " failures =" 0" errors =" 0" id =" 0" hostname =" hostname" time =" 0.001" timestamp =" 2022-01-01T00:00:00Z" >
4
4
<properties >
5
5
<property name =" go.version" value =" 1.0" ></property >
6
6
</properties >
@@ -45,6 +45,10 @@ one-newline
45
45
two-newlines
46
46
two-newlines
47
47
two-newlines]]> </system-out >
48
+ </testcase >
49
+ <testcase name =" TestControl" classname =" package/whitespace" time =" 0.000" >
50
+ <system-out ><![CDATA[ whitespace_test.go:49: log control
51
+ printf control]]> </system-out >
48
52
</testcase >
49
53
<testcase name =" TestSubTests" classname =" package/whitespace" time =" 0.000" ></testcase >
50
54
<testcase name =" TestSubTests/TestFlat" classname =" package/whitespace" time =" 0.000" >
@@ -89,5 +93,9 @@ two-newlines
89
93
two-newlines
90
94
two-newlines]]> </system-out >
91
95
</testcase >
96
+ <testcase name =" TestSubTests/TestControl" classname =" package/whitespace" time =" 0.000" >
97
+ <system-out ><![CDATA[ whitespace_test.go:49: log control
98
+ printf control]]> </system-out >
99
+ </testcase >
92
100
</testsuite >
93
101
</testsuites >
Original file line number Diff line number Diff line change @@ -45,9 +45,15 @@ func TestWithNewlinesFlat(t *testing.T) {
45
45
fmt .Println ("two-newlines\n two-newlines\n two-newlines" )
46
46
}
47
47
48
+ func TestControl (t * testing.T ) {
49
+ t .Logf ("log\x00 control" )
50
+ fmt .Printf ("printf\x00 control\n " )
51
+ }
52
+
48
53
func TestSubTests (t * testing.T ) {
49
54
t .Run ("TestFlat" , TestFlat )
50
55
t .Run ("TestWithSpace" , TestWithSpace )
51
56
t .Run ("TestWithTab" , TestWithTab )
52
57
t .Run ("TestWithNewlinesFlat" , TestWithNewlinesFlat )
58
+ t .Run ("TestControl" , TestControl )
53
59
}
You can’t perform that action at this time.
0 commit comments