]> Cypherpunks.ru repositories - gostls13.git/commit
testing: fix many test2json inaccuracies
authorRuss Cox <rsc@golang.org>
Thu, 13 Oct 2022 20:13:46 +0000 (16:13 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 26 Oct 2022 19:50:36 +0000 (19:50 +0000)
commit1c72ee7f13831b215b8744f6b35bc4fd53aba5e2
tree6f60ccc1bdb1abb77d9fe657f33134a88c30022d
parent4e6f90fecd377777b08a151e1712b6d9180630de
testing: fix many test2json inaccuracies

Test2json is parsing the output stream from the test, which includes
package testing's own framing lines intermingled with other output,
in particular any output printed via fmt.Printf, println, and so on.
We have had recurring problems with unexpected partial output lines
causing a framing line to be missed.

A recent talk at GopherCon gave an example of an integration test
involving Docker that happened to print \r-terminated lines instead
of \n-terminated lines in some configurations, which in turn broke
test2json badly. (https://www.gophercon.com/agenda/session/944259)

There are also a variety of open reported issues with similar problems,
which this CL also addresses. The general approach is to add a new
testing flag -test.v=json that means to print additional output to help
test2json. And then test2json takes advantage of that output.

Among the fixes:

 - Identify testing framing more reliably, using ^V
   (#23036, #26325, #43683, GopherCon talk)
 - Test that output with \r\n endings is handled correctly
   (#43683, #34286)
 - Use === RUN in fuzz tests (#52636, #48132)
 - Add === RUN lines to note benchmark starts (#27764, #49505)
 - Print subtest --- PASS/FAIL lines as they happen (#29811)
 - Add === NAME lines to emit more test change events,
   such as when a subtest stops and the parent continues running.
 - Fix event shown in overall test failure (#27568)
 - Avoid interleaving of writes to os.Stdout and os.Stderr (#33419)

Fixes #23036.
Fixes #26325.
Fixes #27568.
Fixes #27764.
Fixes #29811.
Fixes #33419.
Fixes #34286.
Fixes #43683.
Fixes #49505.
Fixes #52636.

Change-Id: Id4207b746a20693f92e52d68c6e4a7f8c41cc7c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/443596
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
26 files changed:
src/cmd/go/internal/test/test.go
src/cmd/go/internal/test/testflag.go
src/cmd/go/testdata/script/test_chatty_parallel_fail.txt
src/cmd/go/testdata/script/test_chatty_parallel_success.txt
src/cmd/go/testdata/script/test_chatty_parallel_success_run.txt
src/cmd/go/testdata/script/test_json_panic_exit.txt
src/cmd/go/testdata/script/test_json_prints.txt [new file with mode: 0644]
src/cmd/go/testdata/script/test_json_timeout.txt [new file with mode: 0644]
src/cmd/internal/test2json/test2json.go
src/cmd/internal/test2json/test2json_test.go
src/cmd/internal/test2json/testdata/frame.json [new file with mode: 0644]
src/cmd/internal/test2json/testdata/frame.test [new file with mode: 0644]
src/cmd/internal/test2json/testdata/framebig.json [new file with mode: 0644]
src/cmd/internal/test2json/testdata/framebig.test [new file with mode: 0644]
src/cmd/internal/test2json/testdata/framefuzz.json [new file with mode: 0644]
src/cmd/internal/test2json/testdata/framefuzz.test [new file with mode: 0644]
src/cmd/internal/test2json/testdata/timeout.json [new file with mode: 0644]
src/cmd/internal/test2json/testdata/timeout.test [new file with mode: 0644]
src/cmd/test2json/main.go
src/testing/benchmark.go
src/testing/example.go
src/testing/fuzz.go
src/testing/run_example.go
src/testing/run_example_js.go
src/testing/sub_test.go
src/testing/testing.go