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 - exposes lua config in $luarcGeneric
85 - exposes vim config in $vimrcGeneric
89 runTest = neovim-drv: buildCommand:
90 runCommandLocal "test-${neovim-drv.name}" ({
91 nativeBuildInputs = [ ];
92 meta.platforms = neovim-drv.meta.platforms;
94 source ${nmt}/bash-lib/assertions.sh
95 vimrc="${writeText "test-${neovim-drv.name}-init.vim" neovim-drv.initRc}"
96 luarc="${writeText "test-${neovim-drv.name}-init.lua" neovim-drv.luaRcContent}"
97 luarcGeneric="$out/patched.lua"
98 vimrcGeneric="$out/patched.vim"
101 ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric"
102 ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$luarc" > "$luarcGeneric"
106 pkgs.recurseIntoAttrs (rec {
110 # Disabled because of https://github.com/NixOS/nixpkgs/pull/352727
111 # failed_check = pkgs.testers.testBuildFailure nvim-run-failing-check;
113 vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
117 nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix;
118 nvim_singlelines = wrapNeovim2 "-single-lines" nvimConfSingleLines;
120 # test that passthru.initRc hasn't changed
121 passthruInitRc = runTest nvim_singlelines ''
122 INITRC=${pkgs.writeTextFile { name = "initrc"; text = nvim_singlelines.passthru.initRc; }}
125 "${./init-single-lines.vim}"
128 # test single line concatenation
129 singlelinesconfig = runTest nvim_singlelines ''
132 "vim.cmd.source \"/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-init.vim"
135 "${./init-single-lines.vim}"
138 nvim_via_override = neovim.override {
139 extraName = "-via-override";
141 packages.foo.start = [ vimPlugins.ale ];
148 nvim_with_aliases = neovim.override {
149 extraName = "-with-aliases";
154 # test it still works with vim-plug
155 nvim_with_plug = neovim.override {
156 extraName = "-with-plug";
157 configure.packages.plugins = with pkgs.vimPlugins; {
159 (base16-vim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use"; }))
162 configure.customRC = ''
163 color base16-tomorrow-night
168 run_nvim_with_plug = runTest nvim_with_plug ''
169 ${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e
172 nvim_with_autoconfigure = pkgs.neovim.overrideAttrs(oa: {
173 plugins = [ vimPlugins.unicode-vim ];
174 autoconfigure = true;
175 # legacy wrapper sets it to false
179 nvim_with_ftplugin = let
180 # this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex
181 # $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin
182 # we save b:did_ftplugin's value in a `plugin_was_loaded_too_late` file
183 texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" {} ''
184 mkdir -p $out/ftplugin
185 echo 'call system("echo ". exists("b:did_ftplugin") . " > plugin_was_loaded_too_late")' >> $out/ftplugin/tex.vim
186 echo ':q!' >> $out/ftplugin/tex.vim
187 '') // { pname = "test-ftplugin"; };
191 extraName = "-with-ftplugin";
192 configure.packages.plugins = {
199 # regression test that ftplugin files from plugins are loaded before the ftplugin
200 # files from $VIMRUNTIME
201 run_nvim_with_ftplugin = runTest nvim_with_ftplugin ''
202 echo '\documentclass{article}' > main.tex
204 ${nvim_with_ftplugin}/bin/nvim -i NONE -V3log.txt main.tex -c "set ft?" -c quit
206 # check the saved value b:did_ftplugin then our plugin has been loaded instead of neovim's
207 result="$(cat plugin_was_loaded_too_late)"
213 # check that the vim-doc hook correctly generates the tag
214 # we know for a fact packer has a doc folder
215 checkForTags = vimPlugins.packer-nvim.overrideAttrs(oldAttrs: {
216 doInstallCheck = true;
217 installCheckPhase = ''
222 # check that the vim-doc hook correctly generates the tag
223 # for neovim packages from luaPackages
224 # we know for a fact gitsigns-nvim has a doc folder and comes from luaPackages
225 checkForTagsLuaPackages = vimPlugins.gitsigns-nvim.overrideAttrs(oldAttrs: {
226 doInstallCheck = true;
227 installCheckPhase = ''
232 nvim_with_gitsigns_plugin = neovim.override {
233 extraName = "-with-gitsigns-plugin";
234 configure.packages.plugins = {
236 vimPlugins.gitsigns-nvim
241 checkHelpLuaPackages = runTest nvim_with_gitsigns_plugin ''
242 ${nvim_with_gitsigns_plugin}/bin/nvim -i NONE -c 'help gitsigns' +quitall! -e
245 # nixpkgs should detect that no wrapping is necessary
246 nvimShouldntWrap = wrapNeovim2 "-should-not-wrap" nvimAutoDisableWrap;
248 # this will generate a neovimRc content but we disable wrapping
249 nvimDontWrap = wrapNeovim2 "-forced-nowrap" (makeNeovimConfig {
252 " this shouldn't trigger the creation of an init.vim
256 force-nowrap = runTest nvimDontWrap ''
257 ! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim
260 nvim_via_override-test = runTest nvim_via_override ''
263 "${./init-override.vim}"
267 checkAliases = runTest nvim_with_aliases ''
268 folder=${nvim_with_aliases}/bin
269 assertFileIsExecutable "$folder/vi"
270 assertFileIsExecutable "$folder/vim"
273 # having no RC generated should autodisable init.vim wrapping
274 nvim_autowrap = runTest nvim_via_override ''
275 ! grep ${nvimShouldntWrap}/bin/nvim
279 # system remote plugin manifest should be generated, deoplete should be usable
280 # without the user having to do `UpdateRemotePlugins`. To test, launch neovim
281 # and do `:call deoplete#enable()`. It will print an error if the remote
282 # plugin is not registered.
283 test_nvim_with_remote_plugin = neovim.override {
284 extraName = "-remote";
285 configure.packages.foo.start = with vimPlugins; [ deoplete-nvim ];
288 nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig {
289 extraLuaPackages = ps: [ps.mpack];
295 nvim_with_lua_packages = runTest nvimWithLuaPackages ''
296 ${nvimWithLuaPackages}/bin/nvim -V3log.txt -i NONE --noplugin +quitall! -e
299 # nixpkgs should install optional packages in the opt folder
300 nvim_with_opt_plugin = neovim.override {
301 extraName = "-with-opt-plugin";
302 configure.packages.opt-plugins = with pkgs.vimPlugins; {
304 (dashboard-nvim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use-opt"; }))
307 configure.customRC = ''
308 " Load all autoloaded plugins
311 " Try to run Dashboard, and throw if it succeeds
314 echo "Dashboard found, throwing error"
316 catch /^Vim\%((\a\+)\)\=:E492/
317 echo "Dashboard not found"
320 " Load Dashboard as an optional
321 packadd dashboard-nvim-unique-for-tests-please-dont-use-opt
323 " Try to run Dashboard again, and throw if it fails
324 let res = exists(':Dashboard')
326 echo "Dashboard not found, throwing error"
333 run_nvim_with_opt_plugin = runTest nvim_with_opt_plugin ''
334 ${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e
337 inherit nvim-with-luasnip;
339 autoconfigure = runTest nvim_with_autoconfigure ''
342 '${vimPlugins.unicode-vim.passthru.initLua}'
345 # check that bringing in one plugin with lua deps makes those deps visible from wrapper
346 # for instance luasnip has a dependency on jsregexp
347 can_require_transitive_deps =
348 runTest nvim-with-luasnip ''
349 cat ${nvim-with-luasnip}/bin/nvim
350 ${nvim-with-luasnip}/bin/nvim -i NONE --cmd "lua require'jsregexp'" -e +quitall!