Skip to content

Commit 6df6e61

Browse files
dmitshurgopherbot
authored andcommitted
[release-branch.go1.21] 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 #61557. Change-Id: I53e426c9a5585b2703f0ff6661a0470e1993f960 Reviewed-on: https://go-review.googlesource.com/c/go/+/513761 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent b25266c commit 6df6e61

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/cmd/dist/test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ type work struct {
9191
end chan bool
9292
}
9393

94+
// printSkip prints a skip message for all of work.
95+
func (w *work) printSkip(t *tester, msg string) {
96+
if t.json {
97+
type event struct {
98+
Time time.Time
99+
Action string
100+
Package string
101+
Output string `json:",omitempty"`
102+
}
103+
enc := json.NewEncoder(&w.out)
104+
ev := event{Time: time.Now(), Package: w.dt.name, Action: "start"}
105+
enc.Encode(ev)
106+
ev.Action = "output"
107+
ev.Output = msg
108+
enc.Encode(ev)
109+
ev.Action = "skip"
110+
ev.Output = ""
111+
enc.Encode(ev)
112+
return
113+
}
114+
fmt.Fprintln(&w.out, msg)
115+
}
116+
94117
// A distTest is a test run by dist test.
95118
// Each test has a unique name and belongs to a group (heading)
96119
type distTest struct {
@@ -1238,7 +1261,7 @@ func (t *tester) runPending(nextTest *distTest) {
12381261
go func(w *work) {
12391262
if !<-w.start {
12401263
timelog("skip", w.dt.name)
1241-
w.out.WriteString("skipped due to earlier error\n")
1264+
w.printSkip(t, "skipped due to earlier error")
12421265
} else {
12431266
timelog("start", w.dt.name)
12441267
w.err = w.cmd.Run()
@@ -1249,7 +1272,7 @@ func (t *tester) runPending(nextTest *distTest) {
12491272
if isUnsupportedVMASize(w) {
12501273
timelog("skip", w.dt.name)
12511274
w.out.Reset()
1252-
w.out.WriteString("skipped due to unsupported VMA\n")
1275+
w.printSkip(t, "skipped due to unsupported VMA")
12531276
w.err = nil
12541277
}
12551278
}

0 commit comments

Comments
 (0)