Skip to content

Commit

Permalink
cmd/internal/test2json: support subtests containing colons
Browse files Browse the repository at this point in the history
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 golang#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]>
  • Loading branch information
mvdan committed Mar 10, 2018
1 parent 32409a2 commit 0c5cfec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cmd/internal/test2json/test2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (c *converter) handleInputLine(line []byte) {
// "=== RUN "
// "=== PAUSE "
// "=== CONT "
actionColon := false
origLine := line
ok := false
indent := 0
Expand All @@ -196,6 +197,7 @@ func (c *converter) handleInputLine(line []byte) {
}
for _, magic := range reports {
if bytes.HasPrefix(line, magic) {
actionColon = true
ok = true
break
}
Expand All @@ -209,7 +211,10 @@ func (c *converter) handleInputLine(line []byte) {
}

// Parse out action and test name.
i := bytes.IndexByte(line, ':') + 1
i := 0
if actionColon {
i = bytes.IndexByte(line, ':') + 1
}
if i == 0 {
i = len(updates[0])
}
Expand Down
14 changes: 14 additions & 0 deletions src/cmd/internal/test2json/testdata/issue23920.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{"Action":"run","Test":"TestWithColons"}
{"Action":"output","Test":"TestWithColons","Output":"=== RUN TestWithColons\n"}
{"Action":"run","Test":"TestWithColons/[::1]"}
{"Action":"output","Test":"TestWithColons/[::1]","Output":"=== RUN TestWithColons/[::1]\n"}
{"Action":"run","Test":"TestWithColons/127.0.0.1:0"}
{"Action":"output","Test":"TestWithColons/127.0.0.1:0","Output":"=== RUN TestWithColons/127.0.0.1:0\n"}
{"Action":"output","Test":"TestWithColons","Output":"--- PASS: TestWithColons (0.00s)\n"}
{"Action":"output","Test":"TestWithColons/[::1]","Output":" --- PASS: TestWithColons/[::1] (0.00s)\n"}
{"Action":"pass","Test":"TestWithColons/[::1]"}
{"Action":"output","Test":"TestWithColons/127.0.0.1:0","Output":" --- PASS: TestWithColons/127.0.0.1:0 (0.00s)\n"}
{"Action":"pass","Test":"TestWithColons/127.0.0.1:0"}
{"Action":"pass","Test":"TestWithColons"}
{"Action":"output","Output":"PASS\n"}
{"Action":"pass"}
7 changes: 7 additions & 0 deletions src/cmd/internal/test2json/testdata/issue23920.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== RUN TestWithColons
=== RUN TestWithColons/[::1]
=== RUN TestWithColons/127.0.0.1:0
--- PASS: TestWithColons (0.00s)
--- PASS: TestWithColons/[::1] (0.00s)
--- PASS: TestWithColons/127.0.0.1:0 (0.00s)
PASS

0 comments on commit 0c5cfec

Please sign in to comment.