Skip to content

Commit 0c5cfec

Browse files
committed
cmd/internal/test2json: support subtests containing colons
The "updates" lines, such as RUN, do not contain a colon. However, test2json looked for one anyway, meaning that it would be thrown off if it encountered a line like: === RUN TestWithColons/[::1] In that case, it must not use the first colon it encounters to separate the action from the test name. Fixes #23920. Change-Id: I82eff23e24b83dae183c0cf9f85fc5f409f51c25 Reviewed-on: https://go-review.googlesource.com/98445 Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 32409a2 commit 0c5cfec

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/cmd/internal/test2json/test2json.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (c *converter) handleInputLine(line []byte) {
175175
// "=== RUN "
176176
// "=== PAUSE "
177177
// "=== CONT "
178+
actionColon := false
178179
origLine := line
179180
ok := false
180181
indent := 0
@@ -196,6 +197,7 @@ func (c *converter) handleInputLine(line []byte) {
196197
}
197198
for _, magic := range reports {
198199
if bytes.HasPrefix(line, magic) {
200+
actionColon = true
199201
ok = true
200202
break
201203
}
@@ -209,7 +211,10 @@ func (c *converter) handleInputLine(line []byte) {
209211
}
210212

211213
// Parse out action and test name.
212-
i := bytes.IndexByte(line, ':') + 1
214+
i := 0
215+
if actionColon {
216+
i = bytes.IndexByte(line, ':') + 1
217+
}
213218
if i == 0 {
214219
i = len(updates[0])
215220
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{"Action":"run","Test":"TestWithColons"}
2+
{"Action":"output","Test":"TestWithColons","Output":"=== RUN TestWithColons\n"}
3+
{"Action":"run","Test":"TestWithColons/[::1]"}
4+
{"Action":"output","Test":"TestWithColons/[::1]","Output":"=== RUN TestWithColons/[::1]\n"}
5+
{"Action":"run","Test":"TestWithColons/127.0.0.1:0"}
6+
{"Action":"output","Test":"TestWithColons/127.0.0.1:0","Output":"=== RUN TestWithColons/127.0.0.1:0\n"}
7+
{"Action":"output","Test":"TestWithColons","Output":"--- PASS: TestWithColons (0.00s)\n"}
8+
{"Action":"output","Test":"TestWithColons/[::1]","Output":" --- PASS: TestWithColons/[::1] (0.00s)\n"}
9+
{"Action":"pass","Test":"TestWithColons/[::1]"}
10+
{"Action":"output","Test":"TestWithColons/127.0.0.1:0","Output":" --- PASS: TestWithColons/127.0.0.1:0 (0.00s)\n"}
11+
{"Action":"pass","Test":"TestWithColons/127.0.0.1:0"}
12+
{"Action":"pass","Test":"TestWithColons"}
13+
{"Action":"output","Output":"PASS\n"}
14+
{"Action":"pass"}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== RUN TestWithColons
2+
=== RUN TestWithColons/[::1]
3+
=== RUN TestWithColons/127.0.0.1:0
4+
--- PASS: TestWithColons (0.00s)
5+
--- PASS: TestWithColons/[::1] (0.00s)
6+
--- PASS: TestWithColons/127.0.0.1:0 (0.00s)
7+
PASS

0 commit comments

Comments
 (0)