fredrikaverpil / neotest-golang

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

bug: error running tests from a lower working directory #103

Closed jstensland closed 4 months ago

jstensland commented 4 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0

Operating system/version

MacOS 14.5

Describe the bug

The adapter is limiting its search for the go.mod file to the current working directory and this is causing test commands to fail.

Steps To Reproduce

  1. Create a go project with a valid go.mod file at its root, but with packages in subdirectories.
  2. Change directory into one of the packages
  3. Run the tests, for example lua require("neotest").run.run( vim.fn.expand("%:h")). This produces a notification with the error

    Error 10:46:51 notify.error The selected folder must contain a go.mod file or be a subdirectory of a Go package.

Expected Behavior

Tests for the package should run

Your Lua setup

No response

jstensland commented 4 months ago

It looks like the adapter is limiting its search to the the cwd.

Perhaps it could search up to find go.mod, go.work or .git to establish the root

fredrikaverpil commented 4 months ago

Perhaps it could search up to find go.mod, go.work or .git to establish the root

This is actually exactly what it does today, except for making that into a root. The adapter searches for the upmost go.mod relative to the dir/file/test you are trying to run.

I'm not sure what you are experiencing, but if you launch Neovim in the root of this very repo, you will see tests in the tests/go folder. You can also see how there is no go.mod in the root of this repo, but instead you will find one in the tests/go folder.

Can you please provide a reproducible example so I can more easily see what you are seeing?

fredrikaverpil commented 4 months ago

Aha, I think I got it.

The upwards search stops at the cwd today. This behavior comes from me always opening Neovim in the root of a git repo.

https://github.com/fredrikaverpil/neotest-golang/blob/main/lua/neotest-golang/path.lua#L13

I'm not sure if it's a great idea to search further than that... 🤔

How far would you expect it to search? To the ~/?

fredrikaverpil commented 4 months ago

I'm not 100% sure about this fix yet, but please go ahead and try it out and see if it solves the problem on your end: https://github.com/fredrikaverpil/neotest-golang/pull/104

jstensland commented 4 months ago

I usually do too, so not a blocker for me, but not always.

Neotest's helper stops at HOME if I am reading this right. It looks like lspconfig just keeps searching though, so either is probably reasonable.

Matching neotest makes sense to me.

jstensland commented 4 months ago

Using the changes in https://github.com/fredrikaverpil/neotest-golang/pull/104, this symptom goes away. Only tested using go.mod fwiw

fredrikaverpil commented 4 months ago

Aha, nice that you looked into those details. Many thanks. Let's go for this then. 👍