test: tweak setup

This commit is contained in:
Munif Tanjim 2023-12-03 07:13:50 +06:00
parent 257dccc43b
commit 1d044afde8
5 changed files with 21 additions and 15 deletions

View file

@ -79,6 +79,7 @@ jobs:
- name: Setup luacov
run: |
luarocks install luacov
luarocks install luafilesystem
- name: Setup Neovim
uses: MunifTanjim/setup-neovim-action@v1
with:

2
.gitignore vendored
View file

@ -2,4 +2,4 @@
luacov.*.out
.testcache
.tests

View file

@ -1,3 +1,6 @@
include = {
"lua%/nui",
}
includeuntestedfiles = {
"lua/nui"
}

View file

@ -2,18 +2,21 @@
set -euo pipefail
test_scope="nui"
declare -r plugins_dir="./.tests/site/pack/deps/start"
declare -r module="nui"
declare test_scope="${module}"
while [[ $# -gt 0 ]]; do
case "${1}" in
--clean)
shift
echo "[test] cleaning up environment"
rm -rf ./.testcache
rm -rf "${plugins_dir}"
echo "[test] envionment cleaned"
;;
*)
if [[ "${test_scope}" == "nui" ]] && [[ "${1}" == "nui/"* ]]; then
if [[ "${test_scope}" == "${module}" ]] && [[ "${1}" == "${module}/"* ]]; then
test_scope="${1}"
fi
shift
@ -26,7 +29,6 @@ function setup_environment() {
echo "[test] setting up environment"
echo
local plugins_dir="./.testcache/site/pack/deps/start"
if [[ ! -d "${plugins_dir}" ]]; then
mkdir -p "${plugins_dir}"
fi
@ -60,10 +62,12 @@ function luacov_start() {
function luacov_end() {
if test -n "${luacov_dir}"; then
luacov
if test -f "luacov.stats.out"; then
luacov
echo
tail -n +$(($(grep -n "^Summary$" luacov.report.out | cut -d":" -f1) - 1)) luacov.report.out
echo
tail -n +$(($(grep -n "^Summary$" luacov.report.out | cut -d":" -f1) - 1)) luacov.report.out
fi
fi
}
@ -72,9 +76,9 @@ setup_environment
luacov_start
if [[ -d "./tests/${test_scope}/" ]]; then
nvim --headless --noplugin -u tests/minimal_init.lua -c "lua require('plenary.test_harness').test_directory('./tests/${test_scope}/', { minimal_init = 'tests/minimal_init.lua', sequential = true })"
nvim --headless --noplugin -u tests/init.lua -c "lua require('plenary.test_harness').test_directory('./tests/${test_scope}/', { minimal_init = 'tests/init.lua', sequential = true })"
elif [[ -f "./tests/${test_scope}_spec.lua" ]]; then
nvim --headless --noplugin -u tests/minimal_init.lua -c "lua require('plenary.busted').run('./tests/${test_scope}_spec.lua')"
nvim --headless --noplugin -u tests/init.lua -c "lua require('plenary.busted').run('./tests/${test_scope}_spec.lua')"
fi
luacov_end

View file

@ -13,13 +13,11 @@ end
clean_startup()
local root_dir = vim.fn.fnamemodify(vim.trim(vim.fn.system("git rev-parse --show-toplevel")), ":p")
local root_dir = vim.fn.fnamemodify(vim.trim(vim.fn.system("git rev-parse --show-toplevel")), ":p"):gsub("/$", "")
package.path = string.format("%s;%s?.lua;%s?/init.lua", package.path, root_dir, root_dir)
package.path = string.format("%s;%s/?.lua;%s/?/init.lua", package.path, root_dir, root_dir)
vim.opt.packpath:prepend(root_dir .. ".testcache/site")
vim.opt.runtimepath:prepend(root_dir)
vim.opt.packpath:prepend(root_dir .. "/.tests/site")
vim.cmd([[
packadd plenary.nvim