Skip to content
Open
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
8 changes: 8 additions & 0 deletions zaptest/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package zaptest

import (
"bytes"
"testing"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -137,6 +138,7 @@ func (w TestingWriter) WithMarkFailed(v bool) TestingWriter {

// Write writes bytes from p to the underlying testing.TB.
func (w TestingWriter) Write(p []byte) (n int, err error) {
w.IsHelper()
n = len(p)

// Strip trailing newline because t.Log always adds one.
Expand All @@ -155,3 +157,9 @@ func (w TestingWriter) Write(p []byte) (n int, err error) {
func (w TestingWriter) Sync() error {
return nil
}

func (w TestingWriter) IsHelper() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of issues with this:

  • This method doesn't need to be exported
  • Calling tb.Helper() from inside of this method probably won't do anything for the caller Write method which I thought was the point. Can you include output verifying that this works as expected before/after this change.

if tb, ok := w.t.(testing.TB); ok {
tb.Helper()
}
}