MCPcopy
hub / github.com/rs/zerolog / Write

Method Write

writer.go:160–181  ·  view source on GitHub ↗

Write to testing.TB.

(p []byte)

Source from the content-addressed store, hash-verified

158
159// Write to testing.TB.
160func (t TestWriter) Write(p []byte) (n int, err error) {
161 t.T.Helper()
162
163 n = len(p)
164
165 // Strip trailing newline because t.Log always adds one.
166 p = bytes.TrimRight(p, "\n")
167
168 // Try to correct the log file and line number to the caller.
169 if t.Frame > 0 {
170 _, origFile, origLine, _ := runtime.Caller(1)
171 _, frameFile, frameLine, ok := runtime.Caller(1 + t.Frame)
172 if ok {
173 erase := strings.Repeat("\b", len(path.Base(origFile))+len(strconv.Itoa(origLine))+3)
174 t.T.Logf("%s%s:%d: %s", erase, path.Base(frameFile), frameLine, p)
175 return n, err
176 }
177 }
178 t.T.Log(string(p))
179
180 return n, err
181}
182
183// ConsoleTestWriter creates an option that correctly sets the file frame depth for testing.TB log.
184func ConsoleTestWriter(t TestingLog) func(w *ConsoleWriter) {

Callers 1

TestTestWriterFunction · 0.95

Calls 4

HelperMethod · 0.80
LogfMethod · 0.65
LogMethod · 0.65
CallerMethod · 0.45

Tested by 1

TestTestWriterFunction · 0.76