Atlas › Test

uses_last_gomock_style_block

Exact test identity: go.temporal.io/server/tools/testrunner/TestParseFailureDetails/uses_last_gomock_style_block

Package
go.temporal.io/server/tools/testrunner
Suite / test hierarchy
TestParseFailureDetails/uses_last_gomock_style_block
Test
uses_last_gomock_style_block
Introduced at
log.go ×2 Frontier kind: Joint frontier
Covered ranges
15
Covered lines
37
Covered files
1

Co-introduced tests

1 other test enter at the same concept.

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/tools/testrunner/log.go 37 covered LOC · 15 ranges

Open complete file

344
345 // parseFailureDetails extracts the actionable part of a JUnit failure Data block.
346 > func parseFailureDetails(data string) string { log.go
347 > lines := normalizedFailureLines(data)
348 >
349 > // Prefer assertion blocks because they contain the useful testify failure
350 > // detail and can be selected from the end while ignoring trailing logs.
351 > if block, ok := findLastAssertionFailureBlock(lines); ok {
352 return block
353 }
354 // Some failures, such as gomock errors, do not include an Error Trace.
355 // Fall back to the last Go test output block in those cases.
356 > if start, end, ok := findLastTestOutputFailureBlock(lines); ok { log.go
357 > return strings.Join(lines[start:end], "\n") log.go
358 > }
359 return noFailureDetails
360 }
361
362 > func normalizedFailureLines(data string) []string { log.go
363 > lines := strings.Split(strings.ReplaceAll(data, "\r\n", "\n"), "\n")
364 > for len(lines) > 0 {
365 > t := strings.TrimSpace(lines[len(lines)-1])
366 > if t != "" && t != "FAIL" {
367 > break log.go
368 }
369 > lines = lines[:len(lines)-1] log.go
370 }
371 > return lines log.go
372 }
373
374 > func findLastAssertionFailureBlock(lines []string) (string, bool) { log.go
375 > var failLine string
376 > for i := len(lines) - 1; i >= 0; i-- {
377 > line := strings.TrimSpace(lines[i]) log.go
378 > if failLine == "" && strings.HasPrefix(line, goTestFailLinePrefix) {
379 // Keep the final Go test failure line because it carries the test duration.
380 failLine = line
381 continue
382 }
383 > if !strings.Contains(lines[i], "Error Trace:") { log.go
384 > continue
385 }
386
400 return strings.Join(out, "\n"), true
401 }
402 > return "", false log.go
403 }
404
422 }
423
424 > func findLastTestOutputFailureBlock(lines []string) (start, end int, ok bool) { log.go
425 > for start := len(lines) - 1; start >= 0; start-- {
426 > if !isTestOutputLine(lines[start]) { log.go
427 > continue
428 }
429 > end := start + 1 log.go
430 > for end < len(lines) && !isTestOutputLine(lines[end]) && lines[end] != "" {
431 > end++
432 > }
433 > return start, end, true
434 }
435 return 0, 0, false
440 // Testify assertion content is indented further (8+ spaces or tabs), so this
441 // distinguishes log entries from assertion block content.
442 > func isTestOutputLine(line string) bool { log.go
443 > return len(line) > 4 && line[:4] == " " && line[4] != ' ' && line[4] != '\t'
444 > }