-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test coverage generation is not working properly due to cwd being changed to the test file directory. #57
Comments
Hi @ddomurad, Thank for your feedback and kicking off that discussion! Let me start with neotest itself. In Usage section it stated that have two option:
I assume it's understandable that the adapter has to comply with plugin purpose. As you know Go runs test per package not per file:
So the less atomic structure for us to run test is a package and to execute nearest file/test we have do it within a package. Otherwise you bump into issue #38. It makes neotest-go ineffective tools in terms of big commercial projects and day to day use. With all stated above running within package directory seems as expected behaviour and shouldn't run from nvim cwd by default. Test Coverage is a nice-to-have feature but it's outside of When it comes to generating test coverage it could be easily mapped in your vim setting I assume. You don't need a separate plugin for it. The plugin is about running tests, highlighting results and navigating between it. And all it in scope of nearest test/file. Hope it helps. I am open for further discussion, please share your thoughts. |
@sergii4 Thank you for the detailed answer. I might wrongly assumed how everyone is or should use the plugin. However for my needs the directory change is a problem. If you think that an option for controlling the current working directory would be beneficial to the plugin, I could prepare a PR, that could start further discussion on how this could be achieved. On the other hand, If you don't think this should be added, then I will just fork this repo and have it changed there. Let me know :) Regarding test coverage. I really like how it integrates with neotest-go. I have mapped |
Hi @ddomurad, I am glad we have some common ground 🙂 But I still don't understand why do you need test coverage outside the test directory:
I am not sure I fully understand your problem. You want always run Is plugin in current state able to generate coverage for the package? Or it isn't what you want? |
Let me explain with an arbitrary example:
Nvim cwd is at the project root. And: // foo.go
package pkga
import (
"fmt"
"test/pkgb"
)
func Foo() {
fmt.Println("Look at me! I'm a Foo!")
pkgb.Bar()
}
// bar.go
package pkgb
import "fmt"
func Bar() {
fmt.Println("Look at me! I'm a bar!")
}
// foo_test.go
package pkga
import "testing"
func Test_Foo(t *testing.T) {
Foo()
} My problem is with generating coverage for Now, I was able to overcome the first problem, by providing an absolute path to the BTW. This works totally fine when I revert the mentioned changes in my local repo. I see now that I have wrongly used the word module. This Maybe there is an easy solution to this, that I don't see. Thanks and sorry for the confusion! |
I noticed this today too. I'm using andythigpen/nvim-coverage to load the coverage into Neovim and this plugin expects one file (in the cwd). I've resorted to pinning to the previous commit of neotest-go so to keep coverage working as expected. |
@sergii4 Do you have any plans regarding this issue ? If you don't have time to look into it, I could prepare a PR with a potential solution that would make possible to configure the behavior of the working dir. Pls. Let me know. :) |
@ddomurad sorry for a long reply. Please prepare a PR and we can have a look together. |
Hi, @ddomurad! Are you still interested in submitting the PR? |
I solved this on my end (I think), by customizing my lua setup instead of expecting this to be supported by My workflow looks like this:
By telling both {
"nvim-neotest/neotest",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-treesitter/nvim-treesitter" },
{ "antoinemadec/FixCursorHold.nvim" },
{ "folke/neodev.nvim" },
-- adapters
{ "nvim-neotest/neotest-go" }
},
opts = {
adapters = {
["neotest-go"] = {
args = { "-coverprofile=" .. vim.fn.getcwd() .. "/coverage.out" },
},
},
},
}, {
"andythigpen/nvim-coverage",
dependencies = { "nvim-lua/plenary.nvim" },
keys = {
{ "<leader>tc", "<cmd>Coverage<cr>", desc = "Coverage in gutter" },
{ "<leader>tC", "<cmd>CoverageLoad<cr><cmd>CoverageSummary<cr>", desc = "Coverage summary" },
},
opts = {
auto_reload = true,
lang = {
go = {
coverage_file = vim.fn.getcwd() .. "/coverage.out",
},
},
},
}, @sergii4 what do you make of all this? |
Hello.
Recently a PR Enable run file tests despite nvim current directory was merged, and introduced a major change in how the test are being executed. It all comes down to the fact that currently, the
go test ...
command will be executed inside the tests file directory. This behavior has been hard-coded into the test command itself:making it impossible to disable.
First of all I think it is a rather unexpected behavior, and I would assume that the
go test...
command would run from nvim cwd by default.Second of all I found out that I'm not able to properly generate code coverage when the
go test...
is not executed fromgo.mod
dir.Specifically my problem is with generating coverage for modules outside the test directory. Usually I would generate the coverage with a command like:
go test -coverprofile=./coverage.out -coverpkg ./... <TEST_PATH_AND_TAGS>
This would generate coverage for the whole project. Now when I comment out the 3 linesand run
require("neotest").run.run({ extra_args = {"-coverprofile=./coverage.out", "-coverpkg ./..."} })
I get the result I'm expecting.However with the
cd
in place I get only the coverage from the level of the test dir.I have tried to provide absolute paths:
require("neotest").run.run({ extra_args = {"-coverprofile=".. vim.fn.getcwd() .."/coverage.out", "-coverpkg " .. vim.fn.getcwd() .. "/..."} })
and while this trick works for the coverprofile output file, it does not work for coverpkg path, and i get an error:
warning: no packages being tested depend on matches for pattern PATH_TO_MY_PROJECT
.If this wouldn't be to much trouble, I would like to see at least an option to enable/disable the cwd change.
Thanks !
The text was updated successfully, but these errors were encountered: