Skip to content

Commit 6940e56

Browse files
authored
test: allow running locally in isolated environment (#413)
1 parent 61ba9a6 commit 6940e56

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

.github/workflows/ci.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ jobs:
4040
chmod +x nvim.appimage
4141
mv nvim.appimage ./build/nvim
4242
}
43-
git clone https://github.com/MunifTanjim/nui.nvim ~/.local/share/nvim/site/pack/vendor/start/nui.nvim
44-
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
45-
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
4643
4744
- name: Run tests
4845
run: |
4946
export PATH="${PWD}/build/:${PATH}"
50-
make test
47+
./scripts/test.sh

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ luac.out
4141

4242
# Vim tag files
4343
tags
44+
45+
# Others
46+
.testcache

scripts/test.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
while [[ $# -gt 0 ]]; do
6+
case "${1}" in
7+
--clean)
8+
shift
9+
echo "[test] cleaning up environment"
10+
rm -rf ./.testcache
11+
echo "[test] envionment cleaned"
12+
;;
13+
*)
14+
shift
15+
;;
16+
esac
17+
done
18+
19+
function setup_environment() {
20+
echo
21+
echo "[test] setting up environment"
22+
echo
23+
24+
local plugins_dir="./.testcache/site/pack/vendor/start"
25+
if [[ ! -d "${plugins_dir}" ]]; then
26+
mkdir -p "${plugins_dir}"
27+
fi
28+
29+
if [[ ! -d "${plugins_dir}/nui.nvim" ]]; then
30+
echo "[plugins] nui.nvim: installing..."
31+
git clone https://github.com/MunifTanjim/nui.nvim "${plugins_dir}/nui.nvim"
32+
echo "[plugins] nui.nvim: installed"
33+
echo
34+
fi
35+
36+
if [[ ! -d "${plugins_dir}/plenary.nvim" ]]; then
37+
echo "[plugins] plenary.nvim: installing..."
38+
git clone https://github.com/nvim-lua/plenary.nvim "${plugins_dir}/plenary.nvim"
39+
echo "[plugins] plenary.nvim: installed"
40+
echo
41+
fi
42+
43+
echo "[test] environment ready"
44+
echo
45+
}
46+
47+
setup_environment
48+
49+
make test

tests/init_follow_current_file.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
-- Need the absolute path as when doing the testing we will issue things like `tcd` to change directory
22
-- to where our temporary filesystem lives
3+
local root_dir = vim.fn.fnamemodify(vim.trim(vim.fn.system("git rev-parse --show-toplevel")), ":p")
4+
5+
vim.opt.packpath:prepend(string.format("%s", root_dir .. ".testcache/site"))
6+
37
vim.opt.rtp = {
4-
vim.fn.fnamemodify(vim.trim(vim.fn.system("git rev-parse --show-toplevel")), ":p"),
8+
root_dir,
59
vim.env.VIMRUNTIME,
610
}
711

tests/mininit.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
-- Need the absolute path as when doing the testing we will issue things like `tcd` to change directory
22
-- to where our temporary filesystem lives
3+
local root_dir = vim.fn.fnamemodify(vim.trim(vim.fn.system("git rev-parse --show-toplevel")), ":p")
4+
5+
vim.opt.packpath:prepend(string.format("%s", root_dir .. ".testcache/site"))
6+
37
vim.opt.rtp = {
4-
vim.fn.fnamemodify(vim.trim(vim.fn.system("git rev-parse --show-toplevel")), ":p"),
8+
root_dir,
59
vim.env.VIMRUNTIME,
610
}
711

0 commit comments

Comments
 (0)