@@ -1048,18 +1048,6 @@ func (lockedStdout) Write(b []byte) (int, error) {
1048
1048
return os .Stdout .Write (b )
1049
1049
}
1050
1050
1051
- type outputChecker struct {
1052
- w io.Writer
1053
- anyOutput bool
1054
- }
1055
-
1056
- func (o * outputChecker ) Write (p []byte ) (int , error ) {
1057
- if ! o .anyOutput && len (bytes .TrimSpace (p )) > 0 {
1058
- o .anyOutput = true
1059
- }
1060
- return o .w .Write (p )
1061
- }
1062
-
1063
1051
// builderRunTest is the action for running a test binary.
1064
1052
func (c * runCache ) builderRunTest (b * work.Builder , a * work.Action ) error {
1065
1053
if a .Failed {
@@ -1079,7 +1067,6 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
1079
1067
}
1080
1068
1081
1069
var buf bytes.Buffer
1082
- buffered := false
1083
1070
if len (pkgArgs ) == 0 || testBench {
1084
1071
// Stream test output (no buffering) when no package has
1085
1072
// been given on the command line (implicit current directory)
@@ -1106,16 +1093,9 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
1106
1093
stdout = io .MultiWriter (stdout , & buf )
1107
1094
} else {
1108
1095
stdout = & buf
1109
- buffered = true
1110
1096
}
1111
1097
}
1112
1098
1113
- // Keep track of whether we've seen any output at all. This is useful
1114
- // later, to avoid succeeding if the test binary did nothing or didn't
1115
- // reach the end of testing.M.Run.
1116
- outCheck := outputChecker {w : stdout }
1117
- stdout = & outCheck
1118
-
1119
1099
if c .buf == nil {
1120
1100
// We did not find a cached result using the link step action ID,
1121
1101
// so we ran the link step. Try again now with the link output
@@ -1129,7 +1109,7 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
1129
1109
c .tryCacheWithID (b , a , a .Deps [0 ].BuildContentID ())
1130
1110
}
1131
1111
if c .buf != nil {
1132
- if ! buffered {
1112
+ if stdout != & buf {
1133
1113
stdout .Write (c .buf .Bytes ())
1134
1114
c .buf .Reset ()
1135
1115
}
@@ -1227,19 +1207,6 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
1227
1207
1228
1208
mergeCoverProfile (cmd .Stdout , a .Objdir + "_cover_.out" )
1229
1209
1230
- if err == nil && ! testList && ! outCheck .anyOutput {
1231
- // If a test does os.Exit(0) by accident, 'go test' may succeed
1232
- // and it can take a while for a human to notice the package's
1233
- // tests didn't actually pass.
1234
- //
1235
- // If a test binary ran without error, it should have at least
1236
- // printed something, such as a PASS line.
1237
- //
1238
- // The only exceptions are when no tests have run, and the
1239
- // -test.list flag, which just prints the names of tests
1240
- // matching a pattern.
1241
- err = fmt .Errorf ("test binary succeeded but did not print anything" )
1242
- }
1243
1210
if err == nil {
1244
1211
norun := ""
1245
1212
if ! testShowPass && ! testJSON {
@@ -1260,7 +1227,7 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
1260
1227
fmt .Fprintf (cmd .Stdout , "FAIL\t %s\t %s\n " , a .Package .ImportPath , t )
1261
1228
}
1262
1229
1263
- if ! buffered {
1230
+ if cmd . Stdout != & buf {
1264
1231
buf .Reset () // cmd.Stdout was going to os.Stdout already
1265
1232
}
1266
1233
return nil
0 commit comments