cmd/testwrapper: handle build failures
`go test -json` outputs invalid JSON when a build fails. Handle that case by reseting the json.Decode and continuing to read. Updates #8493 Signed-off-by: Maisem Ali <maisem@tailscale.com>maisem/flake3
parent
0c427f23bd
commit
f13243a811
|
@ -81,6 +81,7 @@ func runTests(ctx context.Context, attempt int, pt *packageTests, otherArgs []st
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error creating stdout pipe: %v", err)
|
log.Printf("error creating stdout pipe: %v", err)
|
||||||
}
|
}
|
||||||
|
defer r.Close()
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
@ -104,6 +105,15 @@ func runTests(ctx context.Context, attempt int, pt *packageTests, otherArgs []st
|
||||||
if errors.Is(err, io.EOF) || errors.Is(err, os.ErrClosed) {
|
if errors.Is(err, io.EOF) || errors.Is(err, os.ErrClosed) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `go test -json` outputs invalid JSON when a build fails.
|
||||||
|
// In that case, discard the the output and start reading again.
|
||||||
|
// The build error will be printed to stderr.
|
||||||
|
// See: https://github.com/golang/go/issues/35169
|
||||||
|
if _, ok := err.(*json.SyntaxError); ok {
|
||||||
|
jd = json.NewDecoder(r)
|
||||||
|
continue
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if goOutput.Test == "" {
|
if goOutput.Test == "" {
|
||||||
|
|
Loading…
Reference in New Issue