dotfiles/symlinks/config/nvim/after/plugin/testing.lua

70 lines
2.4 KiB
Lua
Raw Normal View History

2022-05-03 16:56:58 +00:00
-------------------------------------------------------------------------------
-- - Vim-test and general testing config -
-------------------------------------------------------------------------------
-- make test commands execute using dispatch.vim
vim.g["test#strategy"] = "dispatch"
vim.g["test#csharp#runner"] = "dotnettest"
-- Map test running commands
local opts = { silent = true }
vim.keymap.set("n", "<Leader>tn", ":TestNearest<CR>", opts)
vim.keymap.set("n", "<Leader>tf", ":TestFile<CR>", opts)
vim.keymap.set("n", "<Leader>ts", ":TestSuite<CR>", opts)
vim.keymap.set("n", "<Leader>tl", ":TestLast<CR>", opts)
vim.keymap.set("n", "<Leader>tg", ":TestVisit<CR>", opts)
2022-05-05 16:07:01 +00:00
2022-05-07 18:56:11 +00:00
local last_path = nil
local function get_plenary_test_opts()
if vim.g["esensar#testing#use_minimal"] then
return {
minimal_init = vim.g["esensar#testing#minimal_init"] or "tests/minimal.vim",
}
else
return nil
end
end
2022-05-05 16:07:01 +00:00
vim.api.nvim_create_user_command("PlenaryTestFile", function()
2022-05-07 18:56:11 +00:00
last_path = vim.fn.expand("%:p")
require("plenary.test_harness").test_directory(last_path, get_plenary_test_opts())
2022-05-07 18:56:11 +00:00
end, {})
vim.api.nvim_create_user_command("PlenaryTestSuite", function()
last_path = vim.fn["projectionist#path"]()
require("plenary.test_harness").test_directory(last_path, get_plenary_test_opts())
2022-05-07 18:56:11 +00:00
end, {})
vim.api.nvim_create_user_command("PlenaryTestLast", function()
if not last_path then
vim.notify("No plenary tests run yet! Nothing to do here", vim.log.levels.WARN)
return
end
require("plenary.test_harness").test_directory(last_path, get_plenary_test_opts())
2022-05-05 16:07:01 +00:00
end, {})
2022-05-07 16:10:27 +00:00
2022-05-07 18:56:11 +00:00
vim.api.nvim_create_user_command("PlenaryVisitLastTest", function()
if not last_path then
vim.notify("No plenary tests run yet! Nothing to do here", vim.log.levels.WARN)
return
end
vim.cmd("edit " .. last_path)
2022-05-07 16:10:27 +00:00
end, {})
2022-05-07 18:56:11 +00:00
local au_id = vim.api.nvim_create_augroup("plenary_test_group", {})
vim.api.nvim_create_autocmd("FileType", {
pattern = "lua",
group = au_id,
callback = function()
local local_opts = { silent = true, buffer = true }
vim.keymap.set("n", "<Leader>tn", ":PlenaryTestFile<CR>", local_opts)
vim.keymap.set("n", "<Leader>tf", ":PlenaryTestFile<CR>", local_opts)
vim.keymap.set("n", "<Leader>ts", ":PlenaryTestSuite<CR>", local_opts)
vim.keymap.set("n", "<Leader>tl", ":PlenaryTestLast<CR>", local_opts)
vim.keymap.set("n", "<Leader>tg", ":PlenaryVisitLastTest<CR>", local_opts)
2022-05-07 18:56:11 +00:00
end,
})