From 62a9f425612324d531358ba81c4f4ffe95a7469a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Sat, 7 May 2022 20:56:11 +0200 Subject: [PATCH] Improve nvim lua testing experience --- symlinks/config/nvim/after/plugin/testing.lua | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/symlinks/config/nvim/after/plugin/testing.lua b/symlinks/config/nvim/after/plugin/testing.lua index 35a82bd..79619e1 100644 --- a/symlinks/config/nvim/after/plugin/testing.lua +++ b/symlinks/config/nvim/after/plugin/testing.lua @@ -14,10 +14,45 @@ vim.keymap.set("n", "ts", ":TestSuite", opts) vim.keymap.set("n", "tl", ":TestLast", opts) vim.keymap.set("n", "tg", ":TestVisit", opts) +local last_path = nil + vim.api.nvim_create_user_command("PlenaryTestFile", function() - require("plenary.test_harness").test_directory(vim.fn.expand("%:p")) + last_path = vim.fn.expand("%:p") + + require("plenary.test_harness").test_directory(last_path) end, {}) -vim.api.nvim_create_user_command("PlenaryTestFileWithLocalMinInit", function() - require("plenary.test_harness").test_directory(vim.fn.expand("%:p"), { minimal_init = "tests/minimal.vim" }) +vim.api.nvim_create_user_command("PlenaryTestSuite", function() + last_path = vim.fn["projectionist#path"]() + + require("plenary.test_harness").test_directory(last_path) 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) +end, {}) + +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) +end, {}) + +local au_id = vim.api.nvim_create_augroup("plenary_test_group", {}) +vim.api.nvim_create_autocmd("FileType", { + pattern = "lua", + group = au_id, + callback = function() + vim.keymap.set("n", "tn", ":PlenaryTestFile", opts) + vim.keymap.set("n", "tf", ":PlenaryTestFile", opts) + vim.keymap.set("n", "ts", ":PlenaryTestSuite", opts) + vim.keymap.set("n", "tl", ":PlenaryTestLast", opts) + vim.keymap.set("n", "tg", ":PlenaryVisitLastTest", opts) + end, +})