@@ -15,15 +15,16 @@ import (
15
15
)
16
16
17
17
type PkgTracker struct {
18
- lastPkg string
19
- col int
18
+ withWallTime bool
19
+ lastPkg string
20
+ col int
20
21
21
22
startTime time.Time
22
23
pkgs map [string ]* pkgLine
23
24
}
24
25
25
26
type pkgLine struct {
26
- pkg string
27
+ path string
27
28
event TestEvent
28
29
lastUpdate time.Time
29
30
}
@@ -40,24 +41,11 @@ func shouldJoinPkgs(lastPkg, pkg string) (join bool, commonPrefix string) {
40
41
return false , ""
41
42
}
42
43
43
- func isEmpty (event TestEvent , exec * Execution ) bool {
44
- pkg := exec .Package (event .Package )
45
- switch event .Action {
46
- case ActionSkip :
47
- return true
48
- case ActionPass :
49
- if pkg .Total == 0 {
50
- return true
51
- }
52
- }
53
- return false
54
- }
55
-
56
44
var colorRe = regexp .MustCompile (`\x1b\[[0-9;]*m` )
57
45
58
46
func multiPkgNameFormat (out io.Writer , opts FormatOptions , withFailures , withWallTime bool ) eventFormatterFunc {
59
47
buf := bufio .NewWriter (out )
60
- pkgTracker := & PkgTracker {startTime : time .Now ()}
48
+ pt := & PkgTracker {startTime : time .Now (), withWallTime : withWallTime }
61
49
62
50
w , _ , err := term .GetSize (int (os .Stdout .Fd ()))
63
51
if err != nil || w == 0 {
@@ -67,10 +55,10 @@ func multiPkgNameFormat(out io.Writer, opts FormatOptions, withFailures, withWal
67
55
return func (event TestEvent , exec * Execution ) error {
68
56
if ! event .PackageEvent () {
69
57
if event .Action == ActionFail && withFailures {
70
- if pkgTracker .col > 0 {
58
+ if pt .col > 0 {
71
59
buf .WriteString ("\n " )
72
60
}
73
- pkgTracker .col = 0
61
+ pt .col = 0
74
62
pkg := exec .Package (event .Package )
75
63
tc := pkg .LastFailedByName (event .Test )
76
64
pkg .WriteOutputTo (buf , tc .ID ) // nolint:errcheck
@@ -79,57 +67,62 @@ func multiPkgNameFormat(out io.Writer, opts FormatOptions, withFailures, withWal
79
67
return nil
80
68
}
81
69
82
- // Remove newline from shortFormatPackageEvent
70
+ pkgPath := RelativePackagePath (event .Package )
71
+
83
72
eventStr := strings .TrimSuffix (shortFormatPackageEvent (opts , event , exec ), "\n " )
84
73
if eventStr == "" {
85
74
return nil
86
75
}
87
- //eventStr = fmt.Sprintf("%d/%d %s", pkgTracker.col, w, eventStr)
88
76
89
- pkgPath := RelativePackagePath ( event . Package )
90
- join , commonPrefix := shouldJoinPkgs ( pkgTracker . lastPkg , pkgPath )
91
- if event . Action == ActionFail {
92
- join = false
93
- }
77
+ elapsed := time . Since ( pt . startTime ). Round ( time . Millisecond )
78
+ pt . writeEventStr ( pkgPath , eventStr , event , w , buf , elapsed )
79
+ return buf . Flush ()
80
+ }
81
+ }
94
82
95
- if join {
96
- eventStrJoin := strings .ReplaceAll (eventStr , commonPrefix , "" )
97
- eventStrJoin = strings .ReplaceAll (eventStrJoin , " " , " " )
98
- noColorJoinStr := colorRe .ReplaceAllString (eventStr , "" )
99
- if pkgTracker .col == 0 || pkgTracker .col + len ([]rune (noColorJoinStr )) >= w {
100
- join = false
101
- eventStr = strings .ReplaceAll (eventStr , commonPrefix , "…/" )
102
- } else {
103
- eventStr = eventStrJoin
104
- }
105
- }
106
- if join {
107
- buf .WriteString (" " )
108
- pkgTracker .col ++
109
- } else {
110
- buf .WriteString ("\n " )
111
- pkgTracker .col = 0
83
+ func (pt * PkgTracker ) writeEventStr (pkgPath string , eventStr string , event TestEvent , w int , buf io.StringWriter , elapsed time.Duration ) {
84
+ join , commonPrefix := shouldJoinPkgs (pt .lastPkg , pkgPath )
85
+ pt .lastPkg = pkgPath
86
+ if event .Action == ActionFail {
87
+ // put failures on new lines, to include full package name
88
+ join = false
89
+ }
112
90
113
- if withWallTime {
114
- elapsed := time .Since (pkgTracker .startTime ).Round (time .Millisecond )
115
- eventStr = fmtElapsed (elapsed , false ) + eventStr
116
- }
91
+ if join {
92
+ eventStrJoin := strings .ReplaceAll (eventStr , commonPrefix , "" )
93
+ eventStrJoin = strings .ReplaceAll (eventStrJoin , " " , " " )
94
+ noColorJoinStr := colorRe .ReplaceAllString (eventStr , "" )
95
+ if pt .col == 0 || pt .col + len ([]rune (noColorJoinStr )) >= w {
96
+ join = false
97
+ eventStr = strings .ReplaceAll (eventStr , commonPrefix , "…/" )
98
+ } else {
99
+ eventStr = eventStrJoin
117
100
}
118
- pkgTracker .lastPkg = pkgPath
119
- noColorStr := colorRe .ReplaceAllString (eventStr , "" )
120
- pkgTracker .col += len ([]rune (noColorStr ))
101
+ }
102
+ if join {
103
+ buf .WriteString (" " )
104
+ pt .col ++
105
+ } else {
106
+ buf .WriteString ("\n " )
107
+ pt .col = 0
121
108
122
- buf .WriteString (eventStr ) // nolint:errcheck
123
- return buf .Flush ()
109
+ if pt .withWallTime {
110
+ eventStr = fmtElapsed (elapsed , false ) + eventStr
111
+ }
124
112
}
113
+ noColorStr := colorRe .ReplaceAllString (eventStr , "" )
114
+ pt .col += len ([]rune (noColorStr ))
115
+
116
+ buf .WriteString (eventStr ) // nolint:errcheck
125
117
}
126
118
127
119
// ---
128
120
129
121
func multiPkgNameFormat2 (out io.Writer , opts FormatOptions , withFailures , withWallTime bool ) eventFormatterFunc {
130
122
pkgTracker := & PkgTracker {
131
- startTime : time .Now (),
132
- pkgs : map [string ]* pkgLine {},
123
+ startTime : time .Now (),
124
+ withWallTime : withWallTime ,
125
+ pkgs : map [string ]* pkgLine {},
133
126
}
134
127
135
128
writer := dotwriter .New (out )
@@ -143,7 +136,7 @@ func multiPkgNameFormat2(out io.Writer, opts FormatOptions, withFailures, withWa
143
136
failBuf := bufio .NewWriter (writer )
144
137
pkg .WriteOutputTo (failBuf , tc .ID ) // nolint:errcheck
145
138
failBuf .Flush () // nolint:errcheck
146
- writer .Flush ()
139
+ writer .Flush () // nolint:errcheck
147
140
writer = dotwriter .New (out )
148
141
// continue to mark the package as failed early
149
142
//return pkgTracker.flush(writer, opts, exec, withWallTime)
@@ -164,7 +157,7 @@ func multiPkgNameFormat2(out io.Writer, opts FormatOptions, withFailures, withWa
164
157
}
165
158
166
159
pkgTracker .pkgs [pkgPath ] = & pkgLine {
167
- pkg : pkgPath ,
160
+ path : pkgPath ,
168
161
event : event ,
169
162
lastUpdate : time .Now (),
170
163
}
@@ -174,9 +167,9 @@ func multiPkgNameFormat2(out io.Writer, opts FormatOptions, withFailures, withWa
174
167
175
168
func (pt * PkgTracker ) flush (writer * dotwriter.Writer , opts FormatOptions , exec * Execution ,
176
169
withWallTime bool ) error {
177
- writer .Write ([]byte ("\n \n " ))
170
+ // writer.Write([]byte("\n"))
178
171
179
- var pkgPaths []string
172
+ var pkgPaths []string // nolint:prealloc
180
173
for pkgPath := range pt .pkgs {
181
174
pkgPaths = append (pkgPaths , pkgPath )
182
175
}
@@ -195,7 +188,7 @@ func (pt *PkgTracker) flush(writer *dotwriter.Writer, opts FormatOptions, exec *
195
188
lastPkg = pkgPath
196
189
}
197
190
198
- var groupPaths []string
191
+ var groupPaths []string // nolint:prealloc
199
192
for groupPath := range groupPkgs {
200
193
groupPaths = append (groupPaths , groupPath )
201
194
}
@@ -210,55 +203,23 @@ func (pt *PkgTracker) flush(writer *dotwriter.Writer, opts FormatOptions, exec *
210
203
211
204
for _ , groupPath := range groupPaths {
212
205
pkgs := groupPkgs [groupPath ]
213
- lastPkg := ""
214
- col := 0
215
- for pkgI , pkg := range pkgs {
216
- join , commonPrefix := shouldJoinPkgs (lastPkg , pkg .pkg )
217
- lastPkg = pkg .pkg
218
- if pkg .event .Action == ActionFail {
219
- // put failures on new lines, to include full package name
220
- join = false
221
- }
222
-
223
- eventStr := strings .TrimSuffix (shortFormatPackageEvent (opts , pkg .event , exec ), "\n " )
224
- if join {
225
- eventStrJoin := strings .ReplaceAll (eventStr , commonPrefix , "" )
226
- eventStrJoin = strings .ReplaceAll (eventStrJoin , " " , " " )
227
- noColorJoinStr := colorRe .ReplaceAllString (eventStr , "" )
228
- if col + len ([]rune (noColorJoinStr )) >= w {
229
- join = false
230
- eventStr = strings .ReplaceAll (eventStr , commonPrefix , "…/" )
231
- } else {
232
- eventStr = eventStrJoin
233
- }
234
- }
235
- if join {
236
- buf .WriteString (" " )
237
- col ++
238
- } else {
239
- if pkgI > 0 {
240
- buf .WriteString ("\n " )
241
- }
242
- col = 0
243
-
244
- if withWallTime {
245
- var lastUpdatePkg * pkgLine
246
- for _ , p := range pkgs {
247
- if lastUpdatePkg == nil || p .lastUpdate .After (lastUpdatePkg .lastUpdate ) {
248
- lastUpdatePkg = p
249
- }
250
- }
251
- elapsed := lastUpdatePkg .lastUpdate .Sub (pt .startTime )
252
- eventStr = fmtElapsed (elapsed , false ) + eventStr
206
+ pt .lastPkg = ""
207
+ pt .col = 0
208
+ for _ , pkg := range pkgs {
209
+ var lastUpdatePkg * pkgLine
210
+ for _ , p := range pkgs {
211
+ if lastUpdatePkg == nil || p .lastUpdate .After (lastUpdatePkg .lastUpdate ) {
212
+ lastUpdatePkg = p
253
213
}
254
214
}
255
- noColorStr := colorRe .ReplaceAllString (eventStr , "" )
256
- col += len ([]rune (noColorStr ))
215
+ elapsed := lastUpdatePkg .lastUpdate .Sub (pt .startTime ).Round (time .Millisecond )
257
216
258
- buf .WriteString (eventStr ) // nolint:errcheck
217
+ event := pkg .event
218
+ eventStr := strings .TrimSuffix (shortFormatPackageEvent (opts , event , exec ), "\n " )
219
+ pt .writeEventStr (pkg .path , eventStr , event , w , buf , elapsed )
259
220
}
260
- buf .WriteString ("\n " )
261
221
}
222
+ buf .WriteString ("\n " )
262
223
buf .Flush () // nolint:errcheck
263
224
PrintSummary (writer , exec , SummarizeNone )
264
225
return writer .Flush ()
0 commit comments