-
Notifications
You must be signed in to change notification settings - Fork 44
Description
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:
local command = vim.tbl_flatten({
"cd",
dir,
"&&",
"go",
"test",
"-v",
"-json",
utils.get_build_tags(),
vim.list_extend(get_args(), args.extra_args or {}),
unpack(cmd_args),
})
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 from go.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 lines
"cd",
dir,
"&&",
and 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 !