fredrikaverpil / neotest-golang

Reliable Neotest adapter for running Go tests in Neovim.
MIT License
125 stars 17 forks source link

feature: report an error if -race is not working #169

Closed augbed closed 1 month ago

augbed commented 2 months ago

Did you check docs and existing issues?

Is your feature request related to a problem? Please describe.

Hey,

creating this feature request in case somebody will face the same in the future.

If cgo is not enabled/available then with default configuration tests will be skipped silently with not much help in the logs to narrow down the issue.

In my particular case I am using NixOS and did not had gcc package installed that's required for cgo to work. More about it: Using cgo on NixOS

To easily reproduce you can:

anyways, thanks for your work on the plugin!

Describe the solution you'd like to see.

Race flag should probably not be enabled by default or at least return an error if it fails, currently the only issue that can be seen is exit code 2 in the debug logs.

Describe alternatives you've considered.

If race kept as default might be nice to have information about it in the readme that it might be the reason tests are failing silently.

Additional context

No response

fredrikaverpil commented 2 months ago

I'll look into this, thank you!

I think just in general that if there's any error when attempting to run a test, there should be a more clear notification/log with the error.

About using -race, do you mean that cgo is required when running go test -race ./...?

augbed commented 2 months ago

Yes to use -race you must have cgo enabled and on non-Darwin systems have C compiler as per go docs

You can see an error message that cgo must be enabled if you do CGO_ENABLED=0 go test -race ./...

Also this is not strictly related to this issue, but error reporting in general can be improved. For example when trying to run a test that does not compile (syntax issue for example) it defaults to returning a generic tests were skipped message: Test(s) not associated (not found/executed): { "list_of_skipped_tests" } other neotest adapters usually mark those tests as failed and you can see the reason why it failed in the neotest output. In this case it would be nice to see the build error.

fredrikaverpil commented 2 months ago

Yes, 100% agreed. I've thought about this many times myself while using the plugin (I use it on a daily basis). But just to confirm then, this really isn't limited to -race and instead we can rename the issue into being more generic on simply becoming better at reporting when the test command itself returns a non-zero code?

augbed commented 2 months ago

Sure, I just noticed the -race thing first. I think if you were to output the text from go test to neotest ouptut on non-zero code and mark the test as failed it would solve all of the above.

fredrikaverpil commented 2 months ago

Ok, this was actually a little tricky... but if you have the time, please give #176 a try by defining the branch in the plugin options:

{
  "fredrikaverpil/neotest-golang",
  branch = "output-on-failure",
},
image