From c2db3f7758de817ded000890a4a8af55e497bd25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 5 May 2022 18:07:01 +0200 Subject: [PATCH] Add plenary tests to neovim check --- Makefile | 2 ++ symlinks/config/nvim/after/plugin/testing.lua | 4 ++++ .../nvim/lua/esensar/fugitive_extensions.lua | 7 ++++++- .../lua/tests/fugitive_extensions_spec.lua | 21 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 symlinks/config/nvim/lua/tests/fugitive_extensions_spec.lua diff --git a/Makefile b/Makefile index db04295..8b7a294 100644 --- a/Makefile +++ b/Makefile @@ -314,6 +314,8 @@ check_neovim: check_os @nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerInstall' @echo "Doing a basic neovim startup and quit" @nvim --headless -c 'set display-=msgsep' -c 'quitall' + @echo "Running plenary tests" + @nvim --headless -c 'PlenaryBustedDirectory symlinks/config/nvim/lua/tests' .PHONY: run_tests run_tests: check_os diff --git a/symlinks/config/nvim/after/plugin/testing.lua b/symlinks/config/nvim/after/plugin/testing.lua index a8e9b62..808c939 100644 --- a/symlinks/config/nvim/after/plugin/testing.lua +++ b/symlinks/config/nvim/after/plugin/testing.lua @@ -13,3 +13,7 @@ vim.keymap.set("n", "tf", ":TestFile", opts) vim.keymap.set("n", "ts", ":TestSuite", opts) vim.keymap.set("n", "tl", ":TestLast", opts) vim.keymap.set("n", "tg", ":TestVisit", opts) + +vim.api.nvim_create_user_command("PlenaryTestFile", function() + require("plenary.test_harness").test_directory(vim.fn.expand("%:p")) +end, {}) diff --git a/symlinks/config/nvim/lua/esensar/fugitive_extensions.lua b/symlinks/config/nvim/lua/esensar/fugitive_extensions.lua index 70cd54c..d0bb0ed 100644 --- a/symlinks/config/nvim/lua/esensar/fugitive_extensions.lua +++ b/symlinks/config/nvim/lua/esensar/fugitive_extensions.lua @@ -57,7 +57,7 @@ end -- Copies current branches PR url to system clipboard function M.copy_pr_url(...) - vim.cmd('let @+ = "' .. get_pr_url(...) .. '"') + vim.fn.setreg("+", get_pr_url(...)) end -- Opens current banches PR url in default browser @@ -77,4 +77,9 @@ function M.checkout_branch(branch) vim.cmd("Git checkout " .. branch) end +-- Deletes a branch +function M.delete_branch(branch) + vim.cmd("Git branch -d " .. branch) +end + return M diff --git a/symlinks/config/nvim/lua/tests/fugitive_extensions_spec.lua b/symlinks/config/nvim/lua/tests/fugitive_extensions_spec.lua new file mode 100644 index 0000000..ad6c603 --- /dev/null +++ b/symlinks/config/nvim/lua/tests/fugitive_extensions_spec.lua @@ -0,0 +1,21 @@ +local fugitive_extensions = require("esensar.fugitive_extensions") + +describe("fugitive extensions:", function() + describe("copy_pr_url", function() + before_each(function() + fugitive_extensions.create_branch("test") + end) + after_each(function() + fugitive_extensions.checkout_branch("main") + fugitive_extensions.delete_branch("test") + end) + it("copies PR url to main branch by default", function() + fugitive_extensions.copy_pr_url() + assert.are.same("https://github.com/esensar/dotfiles/compare/test?expand=1", vim.fn.getreg("+")) + end) + it("copies PR url to passed branch", function() + fugitive_extensions.copy_pr_url("dev") + assert.are.same("https://github.com/esensar/dotfiles/compare/dev...test?expand=1", vim.fn.getreg("+")) + end) + end) +end)