Skip to content

Commit

Permalink
also write test stderr to json (xml) output file (#3300)
Browse files Browse the repository at this point in the history
Without this, people are forced to look in the test.log file for output
to stderr, rather than test.xml.
  • Loading branch information
rickystewart authored Sep 16, 2022
1 parent 4d4a245 commit cd9a99a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions go/tools/bzltestutil/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
)

// TestWrapperAbnormalExit is used by Wrap to indicate the child
Expand Down Expand Up @@ -61,6 +62,7 @@ func shouldAddTestV() bool {
func Wrap(pkg string) error {
var jsonBuffer bytes.Buffer
jsonConverter := NewConverter(&jsonBuffer, pkg, Timestamp)
pipeRead, pipeWrite := io.Pipe()

args := os.Args[1:]
if shouldAddTestV() {
Expand All @@ -72,9 +74,20 @@ func Wrap(pkg string) error {
}
cmd := exec.Command(exePath, args...)
cmd.Env = append(os.Environ(), "GO_TEST_WRAP=0")
cmd.Stderr = os.Stderr
cmd.Stdout = io.MultiWriter(os.Stdout, jsonConverter)
cmd.Stderr = io.MultiWriter(os.Stderr, pipeWrite)
cmd.Stdout = io.MultiWriter(os.Stdout, pipeWrite)
var wg sync.WaitGroup
wg.Add(1)
go func() {
_, err := io.Copy(jsonConverter, pipeRead)
if err != nil {
panic(err)
}
wg.Done()
}()
err := cmd.Run()
pipeWrite.Close()
wg.Wait()
jsonConverter.Close()
if out, ok := os.LookupEnv("XML_OUTPUT_FILE"); ok {
werr := writeReport(jsonBuffer, pkg, out)
Expand Down

0 comments on commit cd9a99a

Please sign in to comment.