]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/test2json: fix test log output containing test output
authorRuss Cox <rsc@golang.org>
Thu, 4 Jan 2018 18:25:31 +0000 (13:25 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 4 Jan 2018 20:12:12 +0000 (20:12 +0000)
If test case framing appears in ordinary test output,
then test2json can get confused. If the fake framing is being
saved with t.Logf/t.Errorf/etc then we can already
distinguish it from real framing, and the code did.
It just forgot to write that framing as output (1-line fix).

If the fake framing is being generated by printing directly
to stdout/stderr, then test2json will simply get confused.
There's not a lot to do at that point (maybe it's even a feature).

Fixes #23036.

Change-Id: I29449c7ace304172b89d8babe23de507c0500455
Reviewed-on: https://go-review.googlesource.com/86238
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/test2json/test2json.go
src/cmd/internal/test2json/testdata/issue23036.json [new file with mode: 0644]
src/cmd/internal/test2json/testdata/issue23036.test [new file with mode: 0644]

index 3e09c8d91517f9e6bffc58fa2523bb3350e78ba1..a113c2e0ee9a1675cb8d0c608e72546a231a1db6 100644 (file)
@@ -226,6 +226,7 @@ func (c *converter) handleInputLine(line []byte) {
                if len(c.report) < indent {
                        // Nested deeper than expected.
                        // Treat this line as plain output.
+                       c.output.write(origLine)
                        return
                }
                // Flush reports at this indentation level or deeper.
diff --git a/src/cmd/internal/test2json/testdata/issue23036.json b/src/cmd/internal/test2json/testdata/issue23036.json
new file mode 100644 (file)
index 0000000..935c0c5
--- /dev/null
@@ -0,0 +1,12 @@
+{"Action":"run","Test":"TestActualCase"}
+{"Action":"output","Test":"TestActualCase","Output":"=== RUN   TestActualCase\n"}
+{"Action":"output","Test":"TestActualCase","Output":"--- FAIL: TestActualCase (0.00s)\n"}
+{"Action":"output","Test":"TestActualCase","Output":"        foo_test.go:14: Differed.\n"}
+{"Action":"output","Test":"TestActualCase","Output":"                Expected: MyTest:\n"}
+{"Action":"output","Test":"TestActualCase","Output":"                --- FAIL: Test output from other tool\n"}
+{"Action":"output","Test":"TestActualCase","Output":"                Actual: not expected\n"}
+{"Action":"fail","Test":"TestActualCase"}
+{"Action":"output","Output":"FAIL\n"}
+{"Action":"output","Output":"exit status 1\n"}
+{"Action":"output","Output":"FAIL    github.com/org/project/badtest     0.049s\n"}
+{"Action":"fail"}
diff --git a/src/cmd/internal/test2json/testdata/issue23036.test b/src/cmd/internal/test2json/testdata/issue23036.test
new file mode 100644 (file)
index 0000000..fd4774f
--- /dev/null
@@ -0,0 +1,9 @@
+=== RUN   TestActualCase
+--- FAIL: TestActualCase (0.00s)
+        foo_test.go:14: Differed.
+                Expected: MyTest:
+                --- FAIL: Test output from other tool
+                Actual: not expected
+FAIL
+exit status 1
+FAIL    github.com/org/project/badtest     0.049s