From f9dc2948292adfb288c7dda8104f73d1a99d98c3 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 3 Feb 2025 14:45:26 +1100 Subject: [PATCH] chore: plenary tests POC: harden directories --- scripts/test.sh | 15 ++++++++------- tests/minimal_init.lua | 16 ++++++++-------- tests/test_init.lua | 7 +++++++ 3 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 tests/test_init.lua diff --git a/scripts/test.sh b/scripts/test.sh index 4666e2ae..34e0ad7e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,16 +4,17 @@ set -e # TODO add ability for user to specify a test file or directory -REPO_DIR="$(git rev-parse --show-toplevel)" -export REPO_DIR +# TODO clone plenary -PLENARY_DIR="${REPO_DIR}/plenary.nvim" -export PLENARY_DIR +DIR_REPO="$(git rev-parse --show-toplevel)" +export DIR_REPO + +DIR_PLENARY="${DIR_REPO}/plenary.nvim" +export DIR_PLENARY nvim --headless \ --clean \ - --noplugin \ - -u "tests/minimal_init.lua" \ - -c "lua require('plenary.test_harness').test_directory('tests/', { minimal_init = './tests/minimal_init.lua' })" \ + -u "${DIR_REPO}/tests/minimal_init.lua" \ + -l "${DIR_REPO}/tests/test_init.lua" \ -c "qa!" diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index 2d9fce69..ac5785f0 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -1,8 +1,8 @@ --- this file is necessary for the minimal_init option which directs the spawned nvim test instances be run with --noplugin - --- ensure that this nvim-tree is not overridden by installed versions in .local/share/nvim/site etc. -vim.o.runtimepath = vim.env.REPO_DIR .. "," .. vim.o.runtimepath - --- plenary will append ,.,$HOME/src/nvim-tree/master/plenary.nvim in the spawned test instances, however we want this here to prevent overrides -vim.o.runtimepath = vim.env.PLENARY_DIR .. "," .. vim.o.runtimepath - +-- Prepend these as plenary appends a "." and plenary directory +-- The spawned processes don't specify --clean so contain the full ~/.local runtime path +vim.o.runtimepath = string.format( + "%s,%s,%s", + vim.env.DIR_REPO, + vim.env.DIR_PLENARY, + vim.o.runtimepath +) diff --git a/tests/test_init.lua b/tests/test_init.lua new file mode 100644 index 00000000..b050ea18 --- /dev/null +++ b/tests/test_init.lua @@ -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 }) +