@@ -629,7 +629,7 @@ type common struct {
629
629
mu sync.RWMutex // guards this group of fields
630
630
output []byte // Output generated by test or benchmark.
631
631
w io.Writer // For flushToParent.
632
- o io. Writer // Writes output.
632
+ o * outputWriter // Writes output.
633
633
ran bool // Test or benchmark (or one of its subtests) was executed.
634
634
failed bool // Test or benchmark has failed.
635
635
skipped bool // Test or benchmark has been skipped.
@@ -1118,6 +1118,14 @@ func (o *outputWriter) writeLine(b []byte) {
1118
1118
}
1119
1119
}
1120
1120
1121
+ // flush outputs the contents of the buffer.
1122
+ func (o * outputWriter ) flush () {
1123
+ if len (o .b ) == 0 {
1124
+ return
1125
+ }
1126
+ o .Write ([]byte ("\n " ))
1127
+ }
1128
+
1121
1129
// Log formats its arguments using default formatting, analogous to Println,
1122
1130
// and records the text in the error log. For tests, the text will be printed only if
1123
1131
// the test fails or the -test.v flag is set. For benchmarks, the text is always
@@ -1772,6 +1780,10 @@ func tRunner(t *T, fn func(t *T)) {
1772
1780
root .duration += highPrecisionTimeSince (root .start )
1773
1781
d := root .duration
1774
1782
root .mu .Unlock ()
1783
+ // Output the outputWriter's buffer.
1784
+ if t .o != nil {
1785
+ t .o .flush ()
1786
+ }
1775
1787
root .flushToParent (root .name , "--- FAIL: %s (%s)\n " , root .name , fmtDuration (d ))
1776
1788
if r := root .parent .runCleanup (recoverAndReturnPanic ); r != nil {
1777
1789
fmt .Fprintf (root .parent .w , "cleanup panicked with %v" , r )
@@ -1819,6 +1831,10 @@ func tRunner(t *T, fn func(t *T)) {
1819
1831
// test. See comment in Run method.
1820
1832
t .tstate .release ()
1821
1833
}
1834
+ // Output the outputWriter's buffer.
1835
+ if t .o != nil {
1836
+ t .o .flush ()
1837
+ }
1822
1838
t .report () // Report after all subtests have finished.
1823
1839
1824
1840
// Do not lock t.done to allow race detector to detect race in case
0 commit comments