Skip to content
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
2 changes: 1 addition & 1 deletion internal/core/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Step struct {
Cmd string
Exit int
Took time.Duration
Tail string // last 40 lines of combined output
Tail string // first failure and last 40 lines of combined output
Log string // full log path under the state dir
Skipped string // reason it did not run, "" if it ran
}
Expand Down
4 changes: 2 additions & 2 deletions internal/eco/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestMavenImports(t *testing.T) {
}

// TestMavenBumpReal checks that a bumped multi-module build still validates.
// The validate phase binds no plugins, so it runs offline.
// The validate phase binds no plugins, but it does fetch the imported BOM.
func TestMavenBumpReal(t *testing.T) {
if !have("mvn") {
t.Skip("mvn not found")
Expand All @@ -254,7 +254,7 @@ func TestMavenBumpReal(t *testing.T) {
if _, err := (maven{}).Bump(context.Background(), root, d, "2.17.0", ""); err != nil {
t.Fatal(err)
}
if out, err := run(context.Background(), root, nil, "mvn -q -B -o validate"); err != nil {
if out, err := run(context.Background(), root, nil, "mvn -q -B validate"); err != nil {
t.Fatalf("%v\n%s", err, out)
}
if d := depIn(t, maven{}, root, "api/pom.xml", d.Name, true); d.Version != "2.17.0" {
Expand Down
42 changes: 34 additions & 8 deletions internal/verify/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
"strings"
"time"
Expand Down Expand Up @@ -237,16 +238,23 @@ func logName(cmd string) string {
}

const (
tailLines = 40
lineMax = 4096
tailLines = 40
firstLines = 10
lineMax = 4096
)

// failRe spots the line where a run first goes wrong.
var failRe = regexp.MustCompile(`(?i)^\s*not ok\b|\b(error|fail|failed|failure|panic)\b`)

// tail keeps the last tailLines lines written to it in a fixed ring, so a
// multi-gigabyte build log costs the same memory as a short one.
// multi-gigabyte build log costs the same memory as a short one. It also keeps
// the first failure, which long stack traces can push out of the ring.
type tail struct {
ring [tailLines]string
n int
curr []byte
ring [tailLines]string
n int
curr []byte
first []string
firstAt int
}

func (t *tail) Write(p []byte) (int, error) {
Expand All @@ -258,13 +266,23 @@ func (t *tail) Write(p []byte) (int, error) {
return len(p), nil
}
t.add(rest[:i])
t.ring[t.n%tailLines] = string(t.curr)
t.n++
t.line(string(t.curr))
t.curr = t.curr[:0]
rest = rest[i+1:]
}
}

func (t *tail) line(s string) {
if t.first == nil && failRe.MatchString(s) {
t.firstAt = t.n
}
if (t.first != nil || failRe.MatchString(s)) && len(t.first) < firstLines {
t.first = append(t.first, s)
}
t.ring[t.n%tailLines] = s
t.n++
}

func (t *tail) add(b []byte) {
if room := lineMax - len(t.curr); room > 0 {
t.curr = append(t.curr, b[:min(len(b), room)]...)
Expand All @@ -282,5 +300,13 @@ func (t *tail) String() string {
if len(res) > tailLines {
res = res[len(res)-tailLines:]
}
start := t.n + min(len(t.curr), 1) - len(res)
if t.first != nil && t.firstAt < start {
head := slices.Clone(t.first[:min(len(t.first), start-t.firstAt)])
if t.firstAt+len(head) < start {
head = append(head, "...")
}
res = append(head, res...)
}
return strings.Join(res, "\n")
}
23 changes: 23 additions & 0 deletions internal/verify/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ func TestTailBounds(t *testing.T) {
}
}

func TestTailKeepsFirstFailure(t *testing.T) {
var tl tail
fmt.Fprintln(&tl, "TAP version 13")
fmt.Fprintln(&tl, "not ok 1 - charge")
fmt.Fprintln(&tl, " error: reading 'create'")
for i := range 100 {
fmt.Fprintf(&tl, " at frame %d\n", i)
}
lines := strings.Split(tl.String(), "\n")
if lines[0] != "not ok 1 - charge" || lines[1] != " error: reading 'create'" || lines[firstLines] != "..." {
t.Errorf("tail lost the first failure:\n%s", strings.Join(lines[:firstLines+1], "\n"))
}
if len(lines) != firstLines+1+tailLines || lines[len(lines)-1] != " at frame 99" {
t.Errorf("tail kept %d lines, last %q", len(lines), lines[len(lines)-1])
}

var near tail
fmt.Fprint(&near, "ok\nnot ok 1\nmore")
if got := near.String(); got != "ok\nnot ok 1\nmore" {
t.Errorf("a failure inside the window was repeated: %q", got)
}
}

func TestRunStream(t *testing.T) {
var buf bytes.Buffer
_, err := Run(context.Background(), &Worktree{Dir: t.TempDir()}, Options{
Expand Down
Loading