golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.84k stars 17.52k forks source link

cmd/go: go test -json has inconsistent Time precision #44588

Open rittneje opened 3 years ago

rittneje commented 3 years ago

What version of Go are you using (go version)?

$ go version
go version go1.14.13 darwin/amd64

Does this issue reproduce with the latest release?

Yes (go1.16)

What did you do?

Ran go test -json on a package, and attempted to sort the resulting JSON via jq using the Package and Time fields.

What did you expect to see?

I expected jq to sort the results correctly.

What did you see instead?

I noticed that the decimal precision of the Time field is inconsistent. My guess is that it is chopping off trailing zeros. However, this means that the resulting timestamps cannot be sorted properly. For example, we might get the following two entries:

{"Time":"2021-02-24T14:14:25.8589Z","Action":"output","Package":"my-package","Test":"TestFoo","Output":"=== RUN TestFoo\n"} {"Time":"2021-02-24T14:14:25.8589131Z","Action":"output","Package":"my-package","Test":"TestFoo","Output":" --- PASS: TestFoo (0.00s)\n"}

Since 'Z' > '1', this causes the "PASS" line to get sorted before the "RUN" line. This is especially a problem when dealing with older (< 1.6) versions of jq that do not perform a stable sort.

ChandanChainani commented 1 year ago

@rittneje please can you check with go version 1.19 and 1.20, if still fails please share steps and cmd.