Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

also write test stderr to json (xml) output file #3300

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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