MCPcopy Index your code
hub / github.com/coder/coder / summarize

Function summarize

scripts/gotestsummary/main.go:154–253  ·  view source on GitHub ↗
(ctx context.Context, r io.Reader, maxOutputBytes int, stderr io.Writer)

Source from the content-addressed store, hash-verified

152}
153
154func summarize(ctx context.Context, r io.Reader, maxOutputBytes int, stderr io.Writer) (summary, error) {
155 reader := bufio.NewReader(r)
156 buffers := map[testKey]*tailBuffer{}
157 failures := map[testKey]failure{}
158 packageFailures := map[string]struct{}{}
159 var durationSeconds float64
160 var malformedWarnings int
161
162 for lineNumber := 1; ; lineNumber++ {
163 if err := ctx.Err(); err != nil {
164 return summary{}, err
165 }
166 line, err := reader.ReadString('\n')
167 if errors.Is(err, io.EOF) && line == "" {
168 break
169 }
170 if err != nil && !errors.Is(err, io.EOF) {
171 return summary{}, xerrors.Errorf("read json line: %w", err)
172 }
173 line = strings.TrimSpace(line)
174 if line == "" {
175 if errors.Is(err, io.EOF) {
176 break
177 }
178 continue
179 }
180
181 var raw map[string]json.RawMessage
182 if err := json.Unmarshal([]byte(line), &raw); err != nil {
183 malformedWarnings++
184 writef(stderr, "warning: skipping malformed go test JSON line %d: %v\n", lineNumber, err)
185 continue
186 }
187 if raw == nil {
188 malformedWarnings++
189 writef(stderr, "warning: skipping non-object go test JSON line %d\n", lineNumber)
190 continue
191 }
192 var event testEvent
193 if err := json.Unmarshal([]byte(line), &event); err != nil {
194 malformedWarnings++
195 writef(stderr, "warning: skipping malformed go test JSON line %d: %v\n", lineNumber, err)
196 continue
197 }
198
199 key := testKey{pkg: event.Package, test: event.Test}
200 switch event.Action {
201 case "output":
202 bufferFor(buffers, key, maxOutputBytes).Append(stripANSI(event.Output))
203 case "pass", "skip":
204 delete(buffers, key)
205 delete(failures, key)
206 if event.Test == "" {
207 delete(packageFailures, event.Package)
208 if event.Action == "pass" {
209 durationSeconds += event.Elapsed
210 }
211 }

Callers 1

runFunction · 0.85

Calls 12

writefFunction · 0.85
bufferForFunction · 0.85
stripANSIFunction · 0.85
cmpStringFunction · 0.85
displayTestNameFunction · 0.85
ErrMethod · 0.80
ReadStringMethod · 0.80
IsMethod · 0.45
ErrorfMethod · 0.45
UnmarshalMethod · 0.45
AppendMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected