From 63cd226c3e16fe8c26cc32b376d7136317702fd8 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 3 Feb 2025 15:31:33 +1100 Subject: [PATCH] chore: plenary tests POC: add make entry, specify tests --- Makefile | 13 +++++++++++++ scripts/test.sh | 11 +++++++---- tests/test_init.lua | 14 ++++++++------ tests/unit/utils_spec.lua | 1 - 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index b5e829d8..e412d9a9 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,19 @@ help-update: help-check: help-update git diff --exit-code doc/nvim-tree-lua.txt +# +# test +# +test: plenary.nvim + scripts/test.sh $$TEST_NAME + +# +# Dependencies +# +# no plenary tags or releases available +plenary.nvim: + git clone git@github.com:nvim-lua/plenary.nvim.git + .PHONY: all lint style check luacheck style-check style-doc luals style-fix help-update help-check diff --git a/scripts/test.sh b/scripts/test.sh index 34e0ad7e..3ff47543 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,16 +2,19 @@ set -e -# TODO add ability for user to specify a test file or directory - -# TODO clone plenary - DIR_REPO="$(git rev-parse --show-toplevel)" export DIR_REPO DIR_PLENARY="${DIR_REPO}/plenary.nvim" export DIR_PLENARY +if [ "${#}" -eq 1 ]; then + TEST_NAME="${1}" +else + TEST_NAME="tests" +fi +export TEST_NAME + nvim --headless \ --clean \ -u "${DIR_REPO}/tests/minimal_init.lua" \ diff --git a/tests/test_init.lua b/tests/test_init.lua index b050ea18..47a8e3de 100644 --- a/tests/test_init.lua +++ b/tests/test_init.lua @@ -1,7 +1,9 @@ -local test_harness = require('plenary.test_harness') - -local DIR_TEST = vim.env.DIR_REPO .. '/tests' -local FILE_MINIMAL_INIT = DIR_TEST .. '/minimal_init.lua' - -test_harness.test_directory(DIR_TEST, { minimal_init = FILE_MINIMAL_INIT }) +local test_harness = require("plenary.test_harness") +test_harness.test_directory( + vim.env.TEST_NAME, + { + minimal_init = vim.env.DIR_REPO .. "/tests/minimal_init.lua", + sequential = true, + } +) diff --git a/tests/unit/utils_spec.lua b/tests/unit/utils_spec.lua index 924834f8..820030e2 100644 --- a/tests/unit/utils_spec.lua +++ b/tests/unit/utils_spec.lua @@ -18,7 +18,6 @@ describe("utils.path_add_trailing", function() end) describe("utils.canonical_path", function() - before_each(function() stub(vim.fn, "has") end)