nvim-neotest / neotest-go

MIT License
133 stars 43 forks source link

Broken output when non-json lines occur #25

Closed Davincible closed 8 months ago

Davincible commented 1 year ago

The go test -json package has a tendency to include non-json output in some cases. For example when one (distant) sub-package doesn't compile. As a result of this, if I have one not-compiling file in my whole project, non of my tests will report as passing, even though they pass, and the log output will not be parsed.

The problematic code is here; https://github.com/nvim-neotest/neotest-go/blob/afb87c63f7358c51fecfe98aee8762f917558666/lua/neotest-go/init.lua#L220-L226

It happens because it now returns prematurely when one line has no valid json. We can either ignore the line here, or try to include it as is.

How do you want to handle this scenario? I can implement a fix

Davincible commented 1 year ago

Any general build message is not logged out as json, but should still be included in the output. E.g. import cycle

akinsho commented 1 year ago

@Davincible do you have a solution in mind. FWIW AFAIK most go testing explodes if there is any error in the package so I view it not working with invalid code as normal. I wouldn't expect it to partially run since I don't think go supports that, happy to be corrected if there is a non overly complex way to do that.

Essentially, if there is no valid json then you can't really call any of the parsing functions since they expect json. I guess you'd need some other mechanism to pass the output string to neotest's output. Happy to review a PR 🤷🏿

Bacbia3696 commented 1 year ago

I have the same issue, that when I run test, it show some warning so that neotest-go can not parse because it's invalid json, should we add option '2>/dev/null' to the command execute unit test ? This will show the warning: go test ./x/distributionx/... -run TestKeeperTestSuite/TestAllocateTokens -v -json

cgo-gcc-prolog:217:2: warning: 'FSEventStreamScheduleWithRunLoop' is deprecated: first deprecated in macOS 13.0 - Use FSEventStreamSetDispatchQueue instead. [-Wdeprecated-declarations] /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/FSEvents.framework/Headers/FSEvents.h:1138:1: note: 'FSEventStreamScheduleWithRunLoop' has been explicitly marked deprecated here

But this will work fine: go test ./x/distributionx/... -run TestKeeperTestSuite/TestAllocateTokens -v -json 2>/dev/null I am on Mac, and I don't know how to make it work on Window.

fredrikaverpil commented 8 months ago

I believe this can be closed as this got merged: https://github.com/nvim-neotest/neotest-go/pull/54