From: Dmitri Shuralyov Date: Fri, 21 Jul 2023 17:49:06 +0000 (-0400) Subject: cmd/dist: handle -json flag in runPending (minimal) X-Git-Tag: go1.22rc1~1504 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=68d50ca271ec160d8b1284b3aa294e876be1dc71;p=gostls13.git cmd/dist: handle -json flag in runPending (minimal) The -json flag is new to Go 1.21, but missed skips in runPending. This CL adds minimal code to fix that. CL 512115 cleans up a bit. For #37486. Fixes (via backport) #61557. Change-Id: I53e426c9a5585b2703f0ff6661a0470e1993f960 Reviewed-on: https://go-review.googlesource.com/c/go/+/512719 TryBot-Result: Gopher Robot Run-TryBot: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Reviewed-by: Austin Clements Auto-Submit: Dmitri Shuralyov --- diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 8fea9fc76e..1db76a8e9a 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -91,6 +91,29 @@ type work struct { end chan bool } +// printSkip prints a skip message for all of work. +func (w *work) printSkip(t *tester, msg string) { + if t.json { + type event struct { + Time time.Time + Action string + Package string + Output string `json:",omitempty"` + } + enc := json.NewEncoder(&w.out) + ev := event{Time: time.Now(), Package: w.dt.name, Action: "start"} + enc.Encode(ev) + ev.Action = "output" + ev.Output = msg + enc.Encode(ev) + ev.Action = "skip" + ev.Output = "" + enc.Encode(ev) + return + } + fmt.Fprintln(&w.out, msg) +} + // A distTest is a test run by dist test. // Each test has a unique name and belongs to a group (heading) type distTest struct { @@ -1265,7 +1288,7 @@ func (t *tester) runPending(nextTest *distTest) { go func(w *work) { if !<-w.start { timelog("skip", w.dt.name) - w.out.WriteString("skipped due to earlier error\n") + w.printSkip(t, "skipped due to earlier error") } else { timelog("start", w.dt.name) w.err = w.cmd.Run() @@ -1276,7 +1299,7 @@ func (t *tester) runPending(nextTest *distTest) { if isUnsupportedVMASize(w) { timelog("skip", w.dt.name) w.out.Reset() - w.out.WriteString("skipped due to unsupported VMA\n") + w.printSkip(t, "skipped due to unsupported VMA") w.err = nil } }