Skip to content
Open
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
12 changes: 6 additions & 6 deletions executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ func (tt *ExecutorTest) run(t *testing.T) {
t.Helper()
f := func(t *testing.T) {
t.Helper()
var buf bytes.Buffer
var buffer SyncBuffer

opts := append(
tt.executorOpts,
task.WithStdout(&buf),
task.WithStderr(&buf),
task.WithStdout(&buffer),
task.WithStderr(&buffer),
)

// If the test has input, create a reader for it and add it to the
Expand All @@ -172,7 +172,7 @@ func (tt *ExecutorTest) run(t *testing.T) {
if err := e.Setup(); tt.wantSetupError {
require.Error(t, err)
tt.writeFixtureErrSetup(t, g, err)
tt.writeFixtureBuffer(t, g, buf)
tt.writeFixtureBuffer(t, g, buffer.buf)
return
} else {
require.NoError(t, err)
Expand All @@ -193,7 +193,7 @@ func (tt *ExecutorTest) run(t *testing.T) {
if err := e.Run(ctx, call); tt.wantRunError {
require.Error(t, err)
tt.writeFixtureErrRun(t, g, err)
tt.writeFixtureBuffer(t, g, buf)
tt.writeFixtureBuffer(t, g, buffer.buf)
return
} else {
require.NoError(t, err)
Expand All @@ -206,7 +206,7 @@ func (tt *ExecutorTest) run(t *testing.T) {
}
}

tt.writeFixtureBuffer(t, g, buf)
tt.writeFixtureBuffer(t, g, buffer.buf)
}

// Run the test (with a name if it has one)
Expand Down
9 changes: 7 additions & 2 deletions internal/output/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ func (gw *groupWriter) close() error {
// don't print begin/end messages if there's no buffered entries
return nil
}
if _, err := io.WriteString(gw.writer, gw.begin); err != nil {
return err
if len(gw.begin) > 0 {
// Rewrite the gw.buff with the beginning text.
s := gw.buff.String()
gw.buff.Reset()
gw.buff.WriteString(gw.begin)
gw.buff.WriteString(s)
}
gw.buff.WriteString(gw.end)
// Return the entire gw.buff to ensure the group is written atomically to stdout.
_, err := io.Copy(gw.writer, &gw.buff)
return err
}
Loading