declareLogNoise declares that t is expected to emit the following noisy phrases, even on success. Those phrases will be filtered from log output and only be shown if *verbose_logs or t ends up failing. The returned restore function should be called with defer to be run before the test ends.
(t *testing.T, phrases ...string)
| 5125 | // only be shown if *verbose_logs or t ends up failing. The returned restore |
| 5126 | // function should be called with defer to be run before the test ends. |
| 5127 | func declareLogNoise(t *testing.T, phrases ...string) (restore func()) { |
| 5128 | if *verboseLogs { |
| 5129 | return noop |
| 5130 | } |
| 5131 | fw := &filterWriter{dst: os.Stderr, filter: phrases} |
| 5132 | testLogOutput.setWriter(fw) |
| 5133 | return func() { |
| 5134 | if t.Failed() { |
| 5135 | fw.mu.Lock() |
| 5136 | defer fw.mu.Unlock() |
| 5137 | if fw.buf.Len() > 0 { |
| 5138 | t.Logf("Complete log output:\n%s", fw.buf.Bytes()) |
| 5139 | } |
| 5140 | } |
| 5141 | testLogOutput.setWriter(os.Stderr) |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | type filterWriter struct { |
| 5146 | dst io.Writer |