Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Dec 27, 2024
1 parent 44cd9c2 commit 6f6d419
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 70 deletions.
19 changes: 19 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
return {
_all = {
helper = 'spec/spec_helper.lua',
lpath = 'lua/?.lua;lua/?/init.lua',
lua = './spec/nvim-shim',
},
default = {
coverage = false,
verbose = false
},
verbose = {
coverage = false,
verbose = true
},
coverage = {
coverage = true,
verbose = true
},
}
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ jobs:
- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-openresty"
- uses: leafo/gh-actions-luarocks@v4

- name: Install Neovim
uses: rhysd/action-setup-vim@v1
with:
Expand All @@ -37,8 +43,6 @@ jobs:
- uses: extractions/setup-just@v2
- name: Run tests
run: just test
env:
TEST_SEQUENTIAL: 1

release:
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ demo.mp4

/luapath
/packpath
/pack
/.isolated_config*

/.tests
/lua/tests/fixtures/example-project/build
Expand Down
37 changes: 15 additions & 22 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
packpath := justfile_directory() / "packpath"
scripts := justfile_directory() / "scripts"
doc := justfile_directory() / "doc"
devcontainer := justfile_directory() / ".devcontainer/lazyvim/Dockerfile"
Expand All @@ -8,23 +7,23 @@ spec := justfile_directory() / "spec"
fixtures := spec / "fixtures"
demos := justfile_directory() / "demos"

init_lua := scripts / "minimal_init.lua"
clean_config := justfile_directory() / ".test-config"
export LEAN_NVIM_ISOLATED_CONFIG_ROOT := justfile_directory() / ".isolated_config_for_tests"
packpath := LEAN_NVIM_ISOLATED_CONFIG_ROOT / "local/share/nvim/site/pack/testing/start"

# Run the lean.nvim test suite.
[group('testing')]
test: _rebuild-test-fixtures _clone-test-dependencies
@just retest
test *ARGS='': _rebuild-test-fixtures _clone-dependencies
@just retest {{ ARGS }}

# Run the test suite without rebuilding or recloning any dependencies.
[group('testing')]
retest *test_files=spec:
XDG_CONFIG_HOME="{{ clean_config }}" nvim --headless --clean -u {{ init_lua }} -c 'lua require("inanis").run{ specs = vim.split("{{ test_files }}", " "), minimal_init = "{{ init_lua }}", sequential = vim.env.TEST_SEQUENTIAL ~= nil }'
retest *ARGS='':
eval $(luarocks path --no-bin --lua-version 5.1); luarocks --lua-version 5.1 test -- {{ ARGS }}

# Run an instance of neovim with the same minimal init used to run tests.
# Run an instance of neovim with the same setup used to run tests.
[group('dev')]
nvim *ARGS='':
XDG_CONFIG_HOME="{{ clean_config }}" nvim --clean -u {{ init_lua }} -c "lua require('lean').setup { mappings = true }" {{ ARGS }}
XDG_CONFIG_HOME="{{ LEAN_NVIM_ISOLATED_CONFIG_ROOT }}"/config nvim --clean -u NONE -c "lua require('lean').setup { mappings = true }" {{ ARGS }}

# Run an instance of the `devcontainer` which uses LazyVim.
[group('dev')]
Expand All @@ -40,7 +39,7 @@ scratch *ARGS='':

# Coarsely profile how long the whole test suite takes to run.
[group('testing')]
profile-test *ARGS: _rebuild-test-fixtures _clone-test-dependencies
profile-test *ARGS: _rebuild-test-fixtures _clone-dependencies
hyperfine --warmup 2 {{ ARGS }} "just retest"

# Lint lean.nvim for style and typing issues.
Expand All @@ -50,7 +49,7 @@ lint:
{{ if `lua-language-server --version 2>&1 >/dev/null; echo $?` != "0" { error('lua-language-server not found') } else { "" } }}
lua-language-server --check {{ lean }} --checklevel=Warning --configpath "{{ justfile_directory() }}/.luarc.json"
{{ if `selene --version 2>&1 >/dev/null; echo $?` != "0" { error('selene not found') } else { "" } }}
selene {{ src }}
selene {{ src }} {{ spec }}

# Rebuild a demo from our VHS script.
demo:
Expand All @@ -73,7 +72,7 @@ docs:
{{ lean }}/stderr.lua \
{{ lean }}/sorry.lua \
>{{ doc }}/lean.txt
nvim --headless --clean -u {{ init_lua }} -c 'helptags {{ doc }}' -c 'quit'
nvim --headless --clean -u NONE -c 'helptags {{ doc }}' -c 'quit'

# Update the versions of test fixtures used in CI.
[group('testing')]
Expand All @@ -86,19 +85,13 @@ bump-test-fixtures:

# Delete any previously cloned dependencies.
_clean-dependencies:
rm -rf '{{ packpath }}'
mkdir '{{ packpath }}'
rm -rf '{{ LEAN_NVIM_ISOLATED_CONFIG_ROOT }}'

# Clone any neovim dependencies required for the plugin.
_clone-dependencies: _clean-dependencies
for dependency in AndrewRadev/switch.vim andymass/vim-matchup neovim/nvim-lspconfig nvim-lua/plenary.nvim tomtom/tcomment_vim lewis6991/satellite.nvim; do \
git clone --quiet --filter=blob:none "https://github.com/$dependency" "{{ packpath }}/$(basename $dependency)"; \
done

# Clone any neovim dependencies required for the test suite.
_clone-test-dependencies: _clone-dependencies
for dependency in Julian/inanis.nvim; do \
git clone --quiet --filter=blob:none "https://github.com/$dependency" "{{ packpath }}/$(basename $dependency)"; \
mkdir -p '{{ packpath }}' && ln -s "{{ justfile_directory() }}" "{{ packpath }}"
for dependency in AndrewRadev/switch.vim andymass/vim-matchup tomtom/tcomment_vim lewis6991/satellite.nvim; do \
git clone --quiet --filter=blob:none "https://github.com/$dependency" "{{ packpath }}/$(basename $dependency)"; \
done

# Rebuild some test fixtures used in the test suite.
Expand Down
2 changes: 2 additions & 0 deletions lean.nvim-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies = {
'nvim-lspconfig',
'plenary.nvim',
}
test_dependencies = {
}

source = {
url = 'https://github.com/Julian/lean.nvim',
Expand Down
45 changes: 0 additions & 45 deletions scripts/minimal_init.lua

This file was deleted.

2 changes: 2 additions & 0 deletions spec/fixtures.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local assert = require 'luassert.assert'

local this_file = debug.getinfo(1).source:match '@(.*)$'

local root = vim.fs.joinpath(vim.fs.dirname(this_file), 'fixtures')
Expand Down
8 changes: 8 additions & 0 deletions spec/nvim-shim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -euf

export XDG_CONFIG_HOME="$LEAN_NVIM_ISOLATED_CONFIG_ROOT/config"
export XDG_STATE_HOME="$LEAN_NVIM_ISOLATED_CONFIG_ROOT/local/state/"
export XDG_DATA_HOME="$LEAN_NVIM_ISOLATED_CONFIG_ROOT/local/share/"

nvim --cmd 'set loadplugins' -l $@
25 changes: 25 additions & 0 deletions spec/spec_helper.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
local assert = require 'luassert.assert'
local say = require 'say'

--- Assert a Lua object is empty.
--- In particular, the empty string, empty table and nil are all empty.
local function is_empty(_, arguments)
local got = arguments[1]
if not got then
return true
elseif type(got) == 'string' then
return got == ''
else
return vim.tbl_isempty(got)
end
end

say:set('assertion.empty.positive', '%q is non-empty')
say:set('assertion.empty.negative', '%q is empty')
assert:register(
'assertion',
'empty',
is_empty,
'assertion.empty.positive',
'assertion.empty.negative'
)

0 comments on commit 6f6d419

Please sign in to comment.