2 run tests with `nix-build -A neovim.tests`
4 The attrset exposes both the wrapped neovim and the associated test for easier debugging
6 Here are some common neovim flags used in the tests:
7 -e runs neovim in `:h Ex-mode` which returns an exit code != 0 when hitting an error
8 -i NONE gets rid of shada warnings
11 { vimUtils, writeText, neovim, vimPlugins
12 , neovimUtils, wrapNeovimUnstable
19 inherit (neovimUtils) makeNeovimConfig;
21 plugins = with vimPlugins; [
23 plugin = vim-obsession;
25 map <Leader>$ <Cmd>Obsession<CR>
30 packagesWithSingleLineConfigs = with vimPlugins; [
32 plugin = vim-obsession;
33 config = ''map <Leader>$ <Cmd>Obsession<CR>'';
36 plugin = trouble-nvim;
37 config = ''" placeholder config'';
41 nvimConfSingleLines = makeNeovimConfig {
42 plugins = packagesWithSingleLineConfigs;
48 nvimConfNix = makeNeovimConfig {
55 nvim-with-luasnip = wrapNeovim2 "-with-luasnip" (makeNeovimConfig {
57 plugin = vimPlugins.luasnip;
62 # build should fail with a wrong
63 nvim-run-failing-check = (wrapNeovimUnstable neovim-unwrapped {
64 luaRcContent = "this is an invalid lua statement to break the build";
69 nvimAutoDisableWrap = makeNeovimConfig { };
71 wrapNeovim2 = suffix: config:
72 wrapNeovimUnstable neovim-unwrapped (config // {
76 nmt = fetchFromGitLab {
79 rev = "d2cc8c1042b1c2511f68f40e2790a8c0e29eeb42";
80 sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc";
83 # neovim-drv must be a wrapped neovim
84 runTest = neovim-drv: buildCommand:
85 runCommandLocal "test-${neovim-drv.name}" ({
86 nativeBuildInputs = [ ];
87 meta.platforms = neovim-drv.meta.platforms;
89 source ${nmt}/bash-lib/assertions.sh
90 vimrc="${writeText "test-${neovim-drv.name}-init.vim" neovim-drv.initRc}"
91 luarc="${writeText "test-${neovim-drv.name}-init.lua" neovim-drv.luaRcContent}"
92 luarcGeneric="$out/patched.lua"
93 vimrcGeneric="$out/patched.vim"
96 ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric"
97 ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$luarc" > "$luarcGeneric"
101 pkgs.recurseIntoAttrs (rec {
105 # Disabled because of https://github.com/NixOS/nixpkgs/pull/352727
106 # failed_check = pkgs.testers.testBuildFailure nvim-run-failing-check;
108 vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
112 nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix;
113 nvim_singlelines = wrapNeovim2 "-single-lines" nvimConfSingleLines;
115 # test that passthru.initRc hasn't changed
116 passthruInitRc = runTest nvim_singlelines ''
117 INITRC=${pkgs.writeTextFile { name = "initrc"; text = nvim_singlelines.passthru.initRc; }}
120 "${./init-single-lines.vim}"
123 # test single line concatenation
124 singlelinesconfig = runTest nvim_singlelines ''
127 "vim.cmd.source \"/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-init.vim"
130 "${./init-single-lines.vim}"
133 nvim_via_override = neovim.override {
134 extraName = "-via-override";
136 packages.foo.start = [ vimPlugins.ale ];
143 nvim_with_aliases = neovim.override {
144 extraName = "-with-aliases";
149 # test it still works with vim-plug
150 nvim_with_plug = neovim.override {
151 extraName = "-with-plug";
152 configure.packages.plugins = with pkgs.vimPlugins; {
154 (base16-vim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use"; }))
157 configure.customRC = ''
158 color base16-tomorrow-night
163 run_nvim_with_plug = runTest nvim_with_plug ''
164 ${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e
167 nvim_with_ftplugin = let
168 # this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex
169 # $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin
170 # we save b:did_ftplugin's value in a `plugin_was_loaded_too_late` file
171 texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" {} ''
172 mkdir -p $out/ftplugin
173 echo 'call system("echo ". exists("b:did_ftplugin") . " > plugin_was_loaded_too_late")' >> $out/ftplugin/tex.vim
174 echo ':q!' >> $out/ftplugin/tex.vim
175 '') // { pname = "test-ftplugin"; };
179 extraName = "-with-ftplugin";
180 configure.packages.plugins = {
187 # regression test that ftplugin files from plugins are loaded before the ftplugin
188 # files from $VIMRUNTIME
189 run_nvim_with_ftplugin = runTest nvim_with_ftplugin ''
190 echo '\documentclass{article}' > main.tex
192 ${nvim_with_ftplugin}/bin/nvim -i NONE -V3log.txt main.tex -c "set ft?" -c quit
194 # check the saved value b:did_ftplugin then our plugin has been loaded instead of neovim's
195 result="$(cat plugin_was_loaded_too_late)"
201 # check that the vim-doc hook correctly generates the tag
202 # we know for a fact packer has a doc folder
203 checkForTags = vimPlugins.packer-nvim.overrideAttrs(oldAttrs: {
204 doInstallCheck = true;
205 installCheckPhase = ''
210 # check that the vim-doc hook correctly generates the tag
211 # for neovim packages from luaPackages
212 # we know for a fact gitsigns-nvim has a doc folder and comes from luaPackages
213 checkForTagsLuaPackages = vimPlugins.gitsigns-nvim.overrideAttrs(oldAttrs: {
214 doInstallCheck = true;
215 installCheckPhase = ''
220 nvim_with_gitsigns_plugin = neovim.override {
221 extraName = "-with-gitsigns-plugin";
222 configure.packages.plugins = {
224 vimPlugins.gitsigns-nvim
229 checkHelpLuaPackages = runTest nvim_with_gitsigns_plugin ''
230 ${nvim_with_gitsigns_plugin}/bin/nvim -i NONE -c 'help gitsigns' +quitall! -e
233 # nixpkgs should detect that no wrapping is necessary
234 nvimShouldntWrap = wrapNeovim2 "-should-not-wrap" nvimAutoDisableWrap;
236 # this will generate a neovimRc content but we disable wrapping
237 nvimDontWrap = wrapNeovim2 "-forced-nowrap" (makeNeovimConfig {
240 " this shouldn't trigger the creation of an init.vim
244 force-nowrap = runTest nvimDontWrap ''
245 ! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim
248 nvim_via_override-test = runTest nvim_via_override ''
251 "${./init-override.vim}"
255 checkAliases = runTest nvim_with_aliases ''
256 folder=${nvim_with_aliases}/bin
257 assertFileIsExecutable "$folder/vi"
258 assertFileIsExecutable "$folder/vim"
261 # having no RC generated should autodisable init.vim wrapping
262 nvim_autowrap = runTest nvim_via_override ''
263 ! grep ${nvimShouldntWrap}/bin/nvim
267 # system remote plugin manifest should be generated, deoplete should be usable
268 # without the user having to do `UpdateRemotePlugins`. To test, launch neovim
269 # and do `:call deoplete#enable()`. It will print an error if the remote
270 # plugin is not registered.
271 test_nvim_with_remote_plugin = neovim.override {
272 extraName = "-remote";
273 configure.packages.foo.start = with vimPlugins; [ deoplete-nvim ];
276 nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig {
277 extraLuaPackages = ps: [ps.mpack];
283 nvim_with_lua_packages = runTest nvimWithLuaPackages ''
284 ${nvimWithLuaPackages}/bin/nvim -V3log.txt -i NONE --noplugin +quitall! -e
287 # nixpkgs should install optional packages in the opt folder
288 nvim_with_opt_plugin = neovim.override {
289 extraName = "-with-opt-plugin";
290 configure.packages.opt-plugins = with pkgs.vimPlugins; {
292 (dashboard-nvim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use-opt"; }))
295 configure.customRC = ''
296 " Load all autoloaded plugins
299 " Try to run Dashboard, and throw if it succeeds
302 echo "Dashboard found, throwing error"
304 catch /^Vim\%((\a\+)\)\=:E492/
305 echo "Dashboard not found"
308 " Load Dashboard as an optional
309 packadd dashboard-nvim-unique-for-tests-please-dont-use-opt
311 " Try to run Dashboard again, and throw if it fails
312 let res = exists(':Dashboard')
314 echo "Dashboard not found, throwing error"
321 run_nvim_with_opt_plugin = runTest nvim_with_opt_plugin ''
322 ${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e
325 inherit nvim-with-luasnip;
327 # check that bringing in one plugin with lua deps makes those deps visible from wrapper
328 # for instance luasnip has a dependency on jsregexp
329 can_require_transitive_deps =
330 runTest nvim-with-luasnip ''
331 cat ${nvim-with-luasnip}/bin/nvim
332 ${nvim-with-luasnip}/bin/nvim -i NONE --cmd "lua require'jsregexp'" -e +quitall!