klen / nvim-test

A Neovim wrapper for running tests
MIT License
183 stars 26 forks source link

feature request - add TestAll command #33

Closed a-h closed 1 year ago

a-h commented 1 year ago

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 the TestSuite command, it complains "not a test file".

image

I'd love to be able to run go test ./... from any file.

a-h commented 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.

a-h commented 1 year ago

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, {})