Skip to content

Commit 78203ac

Browse files
aclementsgopherbot
authored andcommitted
cmd/dist: tweaks to -json mode
These are some follow-up tweaks to CL 494958. This CL drops a stale and unnecessary check and passes through trailing non-JSON output. Updates #37486. Change-Id: I7cdb73a103f9cd49767d5491812d5ad011ee5c14 Reviewed-on: https://go-review.googlesource.com/c/go/+/496297 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Austin Clements <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Austin Clements <[email protected]>
1 parent b5515ee commit 78203ac

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/cmd/dist/test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ func (opts *goTest) bgCommand(t *tester, stdout, stderr io.Writer) *exec.Cmd {
349349
// Rewrite Package in the JSON output to be pkg:variant. For sharded
350350
// variants, pkg.TestName is already unambiguous, so we don't need to
351351
// rewrite the Package field.
352-
if len(opts.pkgs) != 0 {
353-
panic("cannot combine multiple packages with variants")
354-
}
352+
//
355353
// We only want to process JSON on the child's stdout. Ideally if
356354
// stdout==stderr, we would also use the same testJSONFilter for
357355
// cmd.Stdout and cmd.Stderr in order to keep the underlying

src/cmd/dist/testjson.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ func (f *testJSONFilter) process(line []byte) {
9292
// Should never happen.
9393
panic(fmt.Sprintf("failed to round-trip JSON %q: %s", string(line), err))
9494
}
95-
data = append(data, '\n')
95+
// Copy any trailing text. We expect at most a "\n" here, but
96+
// there could be other text and we want to feed that through.
97+
extra, _ := io.ReadAll(dec.Buffered())
98+
data = append(data, extra...)
9699
f.w.Write(data)
97100
return
98101
}

src/cmd/dist/testjson_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ more text
3131
const want = `unexpected text
3232
{"Package":"abc:variant"}
3333
more text
34-
{"Package":"abc:variant"}
34+
{"Package":"abc:variant"}trailing text
3535
{not json}
3636
`
37-
// Note that currently we won't round-trip trailing text after a valid JSON
38-
// line. That might be a mistake.
3937
checkJSONFilter(t, in, want)
4038
}
4139

0 commit comments

Comments
 (0)