Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions .github/scripts/verify-nvim.lua

This file was deleted.

13 changes: 2 additions & 11 deletions .github/workflows/test-install-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
filters: |
nvim:
- 'install/nvim/**'
- '.github/scripts/verify-nvim.lua'
- '.github/workflows/test-install-scripts.yml'
kitty:
- 'install/kitty.sh'
Expand Down Expand Up @@ -82,17 +81,9 @@ jobs:
which nvim
nvim --version | head -5

- name: Test nvim startup
- name: Run nvim test suite
shell: bash
run: |
export PATH="$HOME/.nix-profile/bin:$PATH"
nvim --headless "+qa"

- name: Verify plugins and bundled tools load
shell: bash
run: |
export PATH="$HOME/.nix-profile/bin:$PATH"
nvim --headless -c "luafile .github/scripts/verify-nvim.lua" +qa
run: nix run ./install/nvim#test

test-kitty-install:
needs: changes
Expand Down
10 changes: 10 additions & 0 deletions install/nvim/config/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ local servers = {
telemetry = {
enable = false,
},
runtime = {
version = "LuaJIT",
},
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
vim.api.nvim_get_runtime_file("lua/lspconfig", false)[1],
},
},
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions install/nvim/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion install/nvim/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
lua-language-server
basedpyright
clang-tools
nodePackages.bash-language-server
bash-language-server
stylua
python3Packages.yapf
fzf
Expand Down Expand Up @@ -82,9 +82,43 @@
wrapperArgs = neovimConfig.wrapperArgs
++ [ "--prefix" "PATH" ":" (pkgs.lib.makeBinPath extraBinaries) ];
});

nvimTest = pkgs.writeShellApplication {
name = "nvim-test";
runtimeInputs = [ nvim pkgs.coreutils ];
text = ''
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
export XDG_DATA_HOME="$tmp/data"
export XDG_STATE_HOME="$tmp/state"
export XDG_CACHE_HOME="$tmp/cache"
mkdir -p "$XDG_DATA_HOME" "$XDG_STATE_HOME" "$XDG_CACHE_HOME"

# Mirror the live-or-baked pattern the config itself uses, so local
# edits are testable without committing them for nix to see.
tests="$HOME/dotfiles/install/nvim/tests"
if [ ! -d "$tests" ]; then
tests="${./tests}"
fi

status=0
nvim --headless \
--cmd "lua vim.g.nvim_tests_dir = '$tests'" \
-c "luafile $tests/run.lua" || status=$?

rm -rf "$tmp"
trap - EXIT
exit "$status"
'';
};
in {
packages.nvim = nvim;
packages.test = nvimTest;
packages.default = nvim;
apps.test = {
type = "app";
program = "${nvimTest}/bin/nvim-test";
};
}
);
}
61 changes: 61 additions & 0 deletions install/nvim/tests/helpers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- Shared bootstrap for the nvim config test suite.
--
-- The nix wrapper starts Neovim with the config split across two mechanisms:
-- VIMINIT="lua dofile('/nix/store/<hash>-init.lua')" (environment)
-- --cmd "set packpath^=/nix/store/<hash>-vim-pack-dir" (argv)
-- --cmd "set rtp^=<same>" (argv)
--
-- mini.test spawns child processes with a hardcoded `--clean`, which discards
-- both. So we recover them from the running parent and pass them to the child
-- explicitly. Without this a child has no mapleader and no plugins.

local M = {}

--- Reconstruct the argv a child needs in order to load the real config.
---@return string[]
function M.config_args()
local viminit = vim.env.VIMINIT
assert(viminit, "VIMINIT unset - tests must run under the nix-wrapped nvim")

local init = viminit:match("dofile%(.([^'\"]+).%)")
assert(init, "could not extract init path from VIMINIT: " .. viminit)

local pack
for _, p in ipairs(vim.opt.packpath:get()) do
if p:match("vim%-pack%-dir") then
pack = p
break
end
end
assert(pack, "no vim-pack-dir on packpath")

return {
"--cmd",
"set packpath^=" .. pack,
"--cmd",
"set rtp^=" .. pack,
"-u",
init,
}
end

--- A child Neovim preloaded with the args needed to reach the real config.
function M.new_child()
local child = MiniTest.new_child_neovim()
child.args = M.config_args()
return child
end

--- A test set that gives every case a freshly restarted child.
function M.new_set(child)
return MiniTest.new_set {
hooks = {
pre_case = function()
child.restart(child.args)
end,
post_once = child.stop,
},
}
end

return M
39 changes: 39 additions & 0 deletions install/nvim/tests/run.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Entry point. `vim.g.nvim_tests_dir` is set by the flake app.
local dir = vim.g.nvim_tests_dir
assert(dir, "vim.g.nvim_tests_dir not set - run via `nix run ./install/nvim#test`")

package.path = dir .. "/?.lua;" .. package.path

require("mini.test").setup {
collect = {
find_files = function()
return vim.fn.globpath(dir, "test_*.lua", true, true)
end,
},
}

-- MiniTest.collect() re-raises (via `error`) any failure while sourcing a
-- test file (e.g. a broken top-level `assert` in a shared helper), and
-- MiniTest.run() does not guard that call. Left unguarded, nvim prints the
-- error (E5113) and then just sits there in headless mode instead of exiting
-- nonzero, turning a bootstrap bug into a CI hang. Guard it ourselves.
local ok, err = pcall(MiniTest.run)

if not ok then
vim.api.nvim_err_writeln("nvim-test: bootstrap error: " .. tostring(err))
vim.cmd "cquit 1"
end

-- MiniTest.run() calls `cquit 0`/`cquit 1` itself (via the stdout reporter's
-- `finish` hook) as soon as at least one case was collected, for both the
-- passing and failing case, and that never returns control here. So reaching
-- this point means zero cases were collected - e.g. the glob or tests dir
-- resolved wrong - which mini.test would otherwise treat as a vacuous pass.
-- Refuse that instead of exiting 0 having tested nothing.
local all_cases = MiniTest.current.all_cases
if all_cases == nil or #all_cases == 0 then
vim.api.nvim_err_writeln "nvim-test: collected 0 test cases - refusing to report success"
vim.cmd "cquit 1"
end

vim.cmd "qall!"
Loading
Loading