design/2981: address akavel's comment
Address https://github.com/golang/go/issues/2981#issuecomment-150318685
Change-Id: I897ccbfa88bd7fb068df9431ce3d01a9371a5843
Reviewed-on: https://go-review.googlesource.com/16285
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/design/2981-go-test-json.md b/design/2981-go-test-json.md
index 3c3b4b5..7393bda 100644
--- a/design/2981-go-test-json.md
+++ b/design/2981-go-test-json.md
@@ -42,13 +42,14 @@
* supports streaming
* `go test` JSON output contains unrecognized test binary output.
* minimal changes in `testing` package.
+* output is not indented
## Proposal
I propose the following user-visible changes:
* add `-json` flag to `go test`
- * `-json`: all `go test` stdout is indented JSON objects containing
+ * `-json`: all `go test` stdout is JSON objects containing
test binary artifacts, separated by newline.
Format below.
* `-json -v`: verbose messages are printed to stderr,
@@ -56,7 +57,7 @@
* `-json -n`: not supported
* `-json -x`: not supported
* In `testing` package
- * Add `type State` which is enum (`PASS`, `FAIL`, `SKIP`).
+ * Add `type State` which is enum
* Add `Name`, `Log`, `State` and `Procs` fields to `BenchmarkResult`.
* Add `type CoverageResult`.
* In type `Cover`, change `CoveredPackages` field type from `string` to
@@ -74,7 +75,8 @@
type State int
const (
- PASS State = iota
+ RUN State = iota
+ PASS
FAIL
SKIP
)
@@ -102,7 +104,7 @@
// JSONResult is used for test binary JSON output format.
//
// Each time a test/benchmark completes, the test binary emits one result
-// in unindented JSON format to stdout, surrounded by '\n'.
+// in JSON format to stdout, surrounded by '\n'.
type JSONResult struct {
// BenchmarkResult contains fields used by both benchmarks and tests,
// such as Name and State.
@@ -116,23 +118,46 @@
convenience of the reader. It will be unindented in fact):
```json
+
+{
+ "Name": "TestFoo",
+ "State": "RUN",
+}
+Random string written directly to os.Stdout.
{
"Name": "TestFoo",
"State": "PASS",
"T": 1000000
}
-Random string written directly to os.Stdout.
+
+{
+ "Name": "TestBar",
+ "State": "RUN",
+}
+
{
"Name": "TestBar",
"State": "PASS",
"T": 1000000,
"Log": "some test output\n"
}
+
+{
+ "Name": "Example1",
+ "State": "RUN",
+}
+
{
"Name": "Example1",
"State": "PASS",
"T": 1000000,
}
+
+{
+ "Name": "BenchmarkBar",
+ "State": "RUN",
+}
+
{
"Name": "BenchmarkBar",
"State": "PASS",
@@ -142,6 +167,7 @@
"MemAllocs": 10,
"MemBytes": 10
}
+
{
"Coverage": {
"Mode": "set",
@@ -169,21 +195,34 @@
}
```
-Example `go test -json` output
-
+Example `go test -json` output:
```json
{
"Package": "example.com/foobar",
"Result": {
"Name": "TestFoo",
+ "State": "Run",
+ }
+}
+{
+ "Package": "example.com/foobar",
+ "Stdout": "Random string written directly to os.Stdout."
+}
+{
+ "Package": "example.com/foobar",
+ "Result": {
+ "Name": "TestFoo",
"State": "PASS",
"T": 1000000
}
}
{
"Package": "example.com/foobar",
- "Stdout": "Random string written directly to os.Stdout.\n"
+ "Result": {
+ "Name": "TestBar",
+ "State": "Run",
+ }
}
{
"Package": "example.com/foobar",
@@ -198,6 +237,13 @@
"Package": "example.com/foobar",
"Result": {
"Name": "Example1",
+ "State": "Run",
+ }
+}
+{
+ "Package": "example.com/foobar",
+ "Result": {
+ "Name": "Example1",
"State": "PASS",
"T": 1000000
}
@@ -206,13 +252,17 @@
"Package": "example.com/foobar",
"Result": {
"Name": "BenchmarkBar",
+ "State": "Run",
+ }
+}
+{
+ "Package": "example.com/foobar",
+ "Result": {
+ "Name": "BenchmarkBar",
"State": "PASS",
"Procs": 8,
"T": 1000000,
"N": 1000,
- "Bytes": 0,
- "MemAllocs": 0,
- "MemBytes": 0
}
}
{
@@ -256,7 +306,7 @@
* add `type TestResult`, which together with
`BenchmarkResult` would have duplicated fields, such as `Name`,
- `Status`, `Procs`, `T`, `Log`.
+ `State`, `Procs`, `T`, `Log`.
We cannot add `type CommonResult` with common fields and embed it in
`TestResult` and `BenchmarkResult` because it would break backwards
compatibility of `BenchmarkResult`.
@@ -299,7 +349,7 @@
Implementation steps:
-1. Add `type Status` and add new fields to `testing.BenchmarkResult`.
+1. Add `type State` and add new fields to `testing.BenchmarkResult`.
Modify `testing.(*B).launch` to fill the new fields.
1. Add `-test.json` flag, `type CoverageResult` and `type JSONResult` to the
`testing` package.