]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: tweaks to -json mode
authorAustin Clements <austin@google.com>
Wed, 17 May 2023 21:59:49 +0000 (17:59 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 18 May 2023 21:19:05 +0000 (21:19 +0000)
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 <gobot@golang.org>
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Austin Clements <austin@google.com>

src/cmd/dist/test.go
src/cmd/dist/testjson.go
src/cmd/dist/testjson_test.go

index 04dfd22f889c17ec30aa0c114e34fd532256b824..0294a5babb0b0cbba5e310268bdd0f91471a99c9 100644 (file)
@@ -349,9 +349,7 @@ func (opts *goTest) bgCommand(t *tester, stdout, stderr io.Writer) *exec.Cmd {
                // Rewrite Package in the JSON output to be pkg:variant. For sharded
                // variants, pkg.TestName is already unambiguous, so we don't need to
                // rewrite the Package field.
-               if len(opts.pkgs) != 0 {
-                       panic("cannot combine multiple packages with variants")
-               }
+               //
                // We only want to process JSON on the child's stdout. Ideally if
                // stdout==stderr, we would also use the same testJSONFilter for
                // cmd.Stdout and cmd.Stderr in order to keep the underlying
index 261b9584cebb3dd7d0c0a2cbf35d302c361ab988..542dc8493ef47a7e5fbe219299fdede24eae6a50 100644 (file)
@@ -92,7 +92,10 @@ func (f *testJSONFilter) process(line []byte) {
                                        // Should never happen.
                                        panic(fmt.Sprintf("failed to round-trip JSON %q: %s", string(line), err))
                                }
-                               data = append(data, '\n')
+                               // Copy any trailing text. We expect at most a "\n" here, but
+                               // there could be other text and we want to feed that through.
+                               extra, _ := io.ReadAll(dec.Buffered())
+                               data = append(data, extra...)
                                f.w.Write(data)
                                return
                        }
index 2ff7bf61f5abc6a7975557c8e7a0794b0392d58d..dbd1f27ea15cb9a6dc892b19d10c29c912a4ff37 100644 (file)
@@ -31,11 +31,9 @@ more text
        const want = `unexpected text
 {"Package":"abc:variant"}
 more text
-{"Package":"abc:variant"}
+{"Package":"abc:variant"}trailing text
 {not json}
 `
-       // Note that currently we won't round-trip trailing text after a valid JSON
-       // line. That might be a mistake.
        checkJSONFilter(t, in, want)
 }