Closed a-h closed 1 year ago
I can do this for Go alone with this command:
vim.api.nvim_create_user_command('TestAll', '!go test -cover --coverprofile=coverage.out ./...', { nargs = 0 })
But it would be great if I could do that in other languages.
I've realised I can create what I want with a few lines of Lua, also that my configuration was messed up because of a clash between vim-test
being installed (but not initialized), and nvim-test
.
local function testAll()
local testCommands = {
go = "go test -cover --coverprofile=coverage.out ./...",
-- add other langs
}
local cmd = testCommands[vim.bo.filetype]
if cmd ~= nil then
vim.cmd("!" .. cmd)
else
print("no test command for filetype: " .. vim.bo.filetype)
end
end
vim.api.nvim_create_user_command('TestAll', testAll, {})
I don't really mind if I'm in a test file or not, I often want to run all the tests.
At the moment, in a Go file like
api.go
, when I use theTestSuite
command, it complains "not a test file".I'd love to be able to run
go test ./...
from any file.