gotestyourself / gotestsum

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.
Apache License 2.0
2.03k stars 119 forks source link

Issue with verbose output #329

Closed jmdacruz closed 1 year ago

jmdacruz commented 1 year ago

Run into a weird issue caused by verbose output, I created this repository in order to help reproduce the issue consistently: https://github.com/jmdacruz/gotestsum_issue (see README, only requires docker-compose to run)

Long story short, given this code under test:

func SomeFunction() {
    fmt.Printf("using file './path/to/file.yaml\n'")
}

Then, the following gotestsum commands fail to correctly parse the output of the tests:

gotestsum -- -v -coverpkg ./... ./...

The coverpkg option is useful to filter which packages to include coverage for. The output is

✓  . (829ms)

=== Failed
=== FAIL: . TestFunction (unknown)
using file './path/to/file.yaml
'--- PASS: TestFunction (0.00s)

DONE 1 tests, 1 failure in 1.729s

The command's exit code is 0

dnephin commented 1 year ago

Thank you for the bug report! I believe this is the same problem as described in #279. See my comment there for more details and a link to the Go issue.

The problem in your case is that the trailing ' comes after the newline, which breaks the test2json parsing, because it is output without a trailing newline.

jmdacruz commented 1 year ago

Yes, I imagined this was related to the single quote and the new line :). I'll keep an eye out for https://github.com/golang/go/issues/26325. In our particular case, this was output generated by the code under test itself, which might be impossible to control in certain situations (e.g., using some external library that has this behavior). In this particular case, we were able to change the code under test to workaround this issue.

dnephin commented 1 year ago

I'm going to close this issue since it sounds like it was a problem with either the test suite, or how go test handles missing newlines. The linked Go issue has been closed, so maybe go test handles this better now.