Skip to content

Commit 6325906

Browse files
committed
feat(tests): based on plenary / busted shim
* ci(github): setup tests
1 parent 5190e7a commit 6325906

8 files changed

Lines changed: 267 additions & 26 deletions

File tree

.github/workflows/tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: dev
2+
on:
3+
# Trigger worfklow when branch or tags are pushed
4+
push:
5+
branches:
6+
- dev
7+
pull_request:
8+
branches: [ "dev", "main" ]
9+
paths:
10+
- "lua/**"
11+
- "plugin/**"
12+
- "tests/**"
13+
jobs:
14+
tests:
15+
name: Run ALL lua tests
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout git repository
19+
uses: actions/checkout@v4
20+
- name: Run tests
21+
shell: bash
22+
# CONTINUE: [November 01, 2023] Provide basic testing workflow
23+
run: |
24+
make -sR -C tests/

Makefile

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
NVIM=nvim
2-
PROJECT_NAME=lsp-timeout
1+
export SHELL=/usr/bin/bash
32

4-
all: doc/tags
3+
export PROJECT_NAME ?=lsp-timeout
4+
export NVIM ?=nvim
55

6-
.PHONY:
7-
doc/tags: doc/$(PROJECT_NAME).txt
8-
@$(NVIM) --headless -c "helptags doc/" -c "exit"
6+
# Only directories
7+
SUBDIRS=$(wildcard */)
98

10-
# ts-vimdoc generate vimhelp from markdown
11-
.SILENT:
9+
.PHONY: $(SUBDIRS)
1210
.ONESHELL:
13-
doc/$(PROJECT_NAME).txt: doc/index.md
14-
$(NVIM) --headless -E -c "
15-
lua require('ts-vimdoc').docgen({
16-
input_file='doc/index.md',
17-
output_file = '$@',
18-
project_name='$(PROJECT_NAME)',
19-
})
20-
os.exit()
21-
"
22-
command -v unicode-emoji-remove.sh &> /dev/null || {
23-
# Use 2> error.log to read the output of the command
24-
echo -e "$0: $(tput setaf 1)error:$(tput op) unicode-emoji-remove.sh is nout found; install it from" \
25-
"https://github.com/hinell/dotfiles/blob/main/bash-scripts/unicode-emoji-remove.sh" \
26-
> /dev/stderr;
27-
}
28-
test -f $< && unicode-emoji-remove.sh -i $@
29-
# strip <br> tags
30-
sed -i -E -e 's/<\/?br\/?>\s*/\n/g' $@
11+
$(SUBDIRS):
12+
$(MAKE) -$(MAKEFLAGS) -C $@ all
13+
14+
all: $(SUBDIRS)

doc/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is intended to be called by meta Make file
2+
export NVIM ?=nvim
3+
export PROJECT_NAME ?=lsp-timeout
4+
5+
include ../make/ts-vimdoc.mk
6+
7+
# Add more files here,
8+
# e.g. $(PROJECT_NAME)-subpage.txt - will be made out of $(PROJECT_NAME)-subpage.md
9+
.ONESHELL:
10+
tags: $(PROJECT_NAME).txt
11+
@$(NVIM) --headless -c "helptags ./" -c "q!"
12+
13+
.PHONY: clean
14+
.ONESHELL:
15+
clean:
16+
rm -v $(PROJECT_NAME).txt ./tags
17+
18+
all: tags

make/neovim-install.mk

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (C) 2023- Alex A. Davronov <al.neodim@gmail.com>
2+
# See LICENSE file or comment at the top of the main file
3+
# provided along with the source code for additional info
4+
#
5+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
11+
# SOFTWARE.
12+
13+
14+
# Install neovim binaries by version
15+
# usage:
16+
# include make/neovim-install.mk
17+
# test-%: $(HOME)/.neovim/%/bin/nvim | $(HOME)/.neovim/ $(HOME)/.local/share/nvim/lazy/plenary.nvim
18+
# VIM="$${HOME}/.neovim/$(*)/share/nvim/runtime" $(HOME)/.neovim/$(*)/bin/nvim --headless --noplugin \
19+
# -c "lua print('neovim version: $(*)')"
20+
#
21+
22+
ifeq ($(NEOVIM_VERSIONS),)
23+
$(error "neovim versions are required")
24+
endif
25+
26+
# Use globally available folder for neovim
27+
$(HOME)/.neovim/:
28+
mkdir -vp $@
29+
30+
# (GNU Make static patter is used)
31+
# ref: https://www.gnu.org/software/make/manual/html_node/Static-Usage.html
32+
# $HOME/.neovim/NVIM_VERSION/bin/nvim
33+
# $HOME/.neovim/nightly/bin/nvim
34+
# $HOME/.neovim/v0.9.2/bin/nvim
35+
.ONESHELL:
36+
$(patsubst %,$(HOME)/.neovim/%/bin/nvim,$(NEOVIM_VERSIONS)): $(HOME)/.neovim/%/bin/nvim: | $(HOME)/.neovim/
37+
echo "Downloading Nvim $(*) to \$$HOME/.neovim/$(*)/"
38+
mkdir -vp "$${HOME}/.neovim/$(*)"
39+
_ASSET_NAME="$(*)/nvim-linux64.tar.gz"
40+
curl -sL "https://github.com/neovim/neovim/releases/download/$${_ASSET_NAME}" | tar --strip-components=1 -C "$${HOME}/.neovim/$(*)/" -xzf -

make/ts-vimdoc.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ts-vimdoc generate vimhelp from markdown
2+
.ONESHELL:
3+
%.txt: %.md
4+
PROJECT_NAME="$(@)"
5+
$(NVIM) --headless -E -c "
6+
lua require('ts-vimdoc').docgen({
7+
input_file='$<',
8+
output_file = '$@',
9+
project_name=\"$${PROJECT_NAME%%.txt}\",
10+
})
11+
os.exit(0)
12+
"
13+
command -v unicode-emoji-remove.sh &> /dev/null || {
14+
# Use 2> error.log to read the output of the command
15+
echo -e "$0: $(tput setaf 1)error:$(tput op) unicode-emoji-remove.sh is nout found; install it from" \
16+
"https://github.com/hinell/dotfiles/blob/main/bash-scripts/unicode-emoji-remove.sh" \
17+
> /dev/stderr;
18+
}
19+
test -f "$<" && unicode-emoji-remove.sh -i $@
20+
# strip <br> tags
21+
sed -i -E -e 's/<\/?br\/?>\s*/\n/g' $@

tests/Makefile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This file is intended to be called by meta Make file
2+
export SHELL ?=bash
3+
export NVIM ?=nvim
4+
5+
# tests: setup plenary.nvim
6+
#-------------------------------------
7+
# Find path to a plenary.nvim in differet package manager paths
8+
# this is used for local testing; in CI it's going to downloaded to a shortest path
9+
DEP_PLENARY_PATH = $(or $(shell _path=$(HOME)/.local/share/nvim/site/pack/opt/pack/plenary/start/plenary.nvim; test -d $${_path} && echo "$${_path}"))
10+
DEP_PLENARY_PATH = $(or $(shell _path=$(HOME)/.local/share/nvim/site/pack/packer/start/plenary.nvim; test -d $${_path} && echo "$${_path}"))
11+
DEP_PLENARY_PATH = $(or $(shell _path=$(HOME)/.local/share/nvim/lazy/plenary.nvim; test -d $${_path} && echo "$${_path}"))
12+
DEP_PLENARY_PATH := $(or $(DEP_PLENARY_PATH), $(HOME)/.local/share/nvim/lazy/plenary.nvim)
13+
14+
.ONESHELL:
15+
.PHONY: $(DEP_PLENARY_PATH)
16+
$(DEP_PLENARY_PATH):
17+
# ping google public DNS to check if connected to WAN
18+
nc -4 -w 1 8.8.8.8 53 || {
19+
echo -e "$(tput setaf 5)info:$(tput op): github.com is unreachable, checkout your connection"
20+
exit 0
21+
}
22+
if test -d "$(@)" ;
23+
then
24+
git -C "$(@)" pull origin master
25+
else
26+
mkdir -vp $@
27+
git clone --no-tags --depth=1 --single-branch 'https://github.com/nvim-lua/plenary.nvim.git' "$(@)"
28+
fi
29+
30+
# test: setup neovim versions for testing
31+
#-------------------------------------
32+
# Neovim versions to test
33+
NEOVIM_VERSIONS=v0.7.2 v0.8.3 v0.9.2 nightly
34+
35+
include ../make/neovim-install.mk
36+
37+
# tests for specific neovim versions
38+
# test-ubuntu-NVIM_VERSION
39+
# test-ubuntu-nightly etc.
40+
.PHONY: $(patsubst %,test-ubuntu-%,$(NEOVIM_VERSIONS))
41+
.ONESHELL:
42+
$(patsubst %,test-ubuntu-%,$(NEOVIM_VERSIONS)): test-ubuntu-%: $(HOME)/.neovim/%/bin/nvim | $(DEP_PLENARY_PATH)
43+
cd ..
44+
if test -s tests/minimal_init.lua ;
45+
then
46+
PLENARY_PATH=$(DEP_PLENARY_PATH) \
47+
VIM="$${HOME}/.neovim/$(*)/share/nvim/runtime" \
48+
$(HOME)/.neovim/$(*)/bin/nvim \
49+
--headless --noplugin -u tests/minimal_init.lua \
50+
-c "PlenaryBustedDirectory tests/ { sequential = false }"
51+
else
52+
echo -e "$(@): $$(tput setaf 1)error:$$(tput op) tests/minimal_init.lua is not found. Aborting!" > /dev/stderr
53+
exit 1
54+
fi
55+
56+
# tests by using system-installed nvim
57+
.PHONY: test-current
58+
.ONESHELL:
59+
test-current: | $(DEP_PLENARY_PATH)
60+
cd ..
61+
command -v nvim && {
62+
PLENARY_PATH=$(DEP_PLENARY_PATH) \
63+
$(NVIM) --clean --headless --noplugin -u tests/minimal_init.lua \
64+
-c "PlenaryBustedDirectory tests/ { sequential = true }"
65+
}
66+
67+
# all tests
68+
.PHONY: test
69+
.ONESHELL:
70+
test: $(patsubst %,test-ubuntu-%,$(NEOVIM_VERSIONS))
71+
72+
.PHONY: clean
73+
.ONESHELL:
74+
clean:
75+
# nightly is often updated
76+
rm -vrd $(HOME)/.neovim/nightly
77+
78+
all: test

tests/minimal_init.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
local path = {}
2+
path.sep = "/"
3+
if vim.fn.has("win32") == 1 then path.sep = "\\" end
4+
5+
-- We do not search for plenary path over here
6+
-- and rely entirely on upstream use of this module
7+
local plenary_path=vim.env.PLENARY_PATH
8+
if plenary_path == "" then
9+
vim.notify(
10+
"minimal_init.lua: plenary.nvim is not found,"
11+
.. "please make sure you have provided nvim with PLENARY_PATH= environment variable ",
12+
vim.log.levels.ERROR)
13+
vim.cmd("q!")
14+
end
15+
16+
vim.o.runtimepath = vim.o.runtimepath .. ',' .. plenary_path
17+
vim.cmd("runtime " .. "plugin" .. path.sep .. "plenary.vim")
18+
19+
if vim.fn.exists(":PlenaryBustedDirectory") == 0 then
20+
vim.notify(
21+
"minimal_init.lua: Failed to find PlenaryBustedDirectory command. Aborting!",
22+
vim.log.levels.ERROR)
23+
vim.cmd("q!")
24+
end
25+
26+
vim.notify("-------------------------------------------------------------------------------")
27+
vim.notify("minimal_init.lua: testing in ", vim.log.levels.INFO)
28+
vim.cmd("version")
29+
vim.notify("\n")

tests/tests_spec.lua

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
describe("lsp-timeout", function()
2+
describe("Config class", function()
3+
local Config = require("lsp-timeout.config").Config
4+
5+
local ignorelist = { "java", "vim", "make" }
6+
local config = {}
7+
config.stopTimeout = 1
8+
config.startTimeout = 2
9+
config.silent = true
10+
config.filetypes = {}
11+
config.filetypes.ignore = ignorelist
12+
13+
it("instantiate by merging provided argument", function()
14+
local config_default = {
15+
filetypes = {
16+
ignore = ignorelist
17+
}
18+
}
19+
20+
local config = Config:new(config_default)
21+
assert.are.same(config.filetypes.ignore, ignorelist)
22+
end)
23+
24+
describe("should validate config", function()
25+
it("without errors", function()
26+
Config:new(config):validate()
27+
end)
28+
it("with errors", function()
29+
assert.has_error(function ()
30+
Config:new({
31+
startTimeout = "string", -- wrong
32+
stopTimeout = {}
33+
}):validate()
34+
end)
35+
end)
36+
end)
37+
38+
39+
-- it("have static tableOfStrings method to check for ", function()
40+
-- local Config = require("lsp-timeout.config").Config
41+
-- assert.is_function(Config.tableOfStrings)
42+
-- end)
43+
44+
end)
45+
end)
46+
47+

0 commit comments

Comments
 (0)