chore: plenary tests POC: harden directories

This commit is contained in:
Alexander Courtis 2025-02-03 14:45:26 +11:00
parent 2dcf249d49
commit f9dc294829
3 changed files with 23 additions and 15 deletions

View File

@ -4,16 +4,17 @@ set -e
# TODO add ability for user to specify a test file or directory # TODO add ability for user to specify a test file or directory
REPO_DIR="$(git rev-parse --show-toplevel)" # TODO clone plenary
export REPO_DIR
PLENARY_DIR="${REPO_DIR}/plenary.nvim" DIR_REPO="$(git rev-parse --show-toplevel)"
export PLENARY_DIR export DIR_REPO
DIR_PLENARY="${DIR_REPO}/plenary.nvim"
export DIR_PLENARY
nvim --headless \ nvim --headless \
--clean \ --clean \
--noplugin \ -u "${DIR_REPO}/tests/minimal_init.lua" \
-u "tests/minimal_init.lua" \ -l "${DIR_REPO}/tests/test_init.lua" \
-c "lua require('plenary.test_harness').test_directory('tests/', { minimal_init = './tests/minimal_init.lua' })" \
-c "qa!" -c "qa!"

View File

@ -1,8 +1,8 @@
-- this file is necessary for the minimal_init option which directs the spawned nvim test instances be run with --noplugin -- Prepend these as plenary appends a "." and plenary directory
-- The spawned processes don't specify --clean so contain the full ~/.local runtime path
-- ensure that this nvim-tree is not overridden by installed versions in .local/share/nvim/site etc. vim.o.runtimepath = string.format(
vim.o.runtimepath = vim.env.REPO_DIR .. "," .. vim.o.runtimepath "%s,%s,%s",
vim.env.DIR_REPO,
-- plenary will append ,.,$HOME/src/nvim-tree/master/plenary.nvim in the spawned test instances, however we want this here to prevent overrides vim.env.DIR_PLENARY,
vim.o.runtimepath = vim.env.PLENARY_DIR .. "," .. vim.o.runtimepath vim.o.runtimepath
)

7
tests/test_init.lua Normal file
View File

@ -0,0 +1,7 @@
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 })