diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 9152d93c15444..14d682e14e431 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -1,4 +1,13 @@ -# run tests by building `neovim.tests` +/* +run tests with `nix-build -A neovim.tests` + +The attrset exposes both the wrapped neovim and the associated test for easier debugging + +Here are some common neovim flags used in the tests: +-e runs neovim in `:h Ex-mode` which returns an exit code != 0 when hitting an error +-i NONE gets rid of shada warnings + +*/ { vimUtils, writeText, neovim, vimPlugins , neovimUtils, wrapNeovimUnstable , neovim-unwrapped @@ -43,7 +52,7 @@ let ''; }; - nvim-with-luasnip = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig { + nvim-with-luasnip = wrapNeovim2 "-with-luasnip" (makeNeovimConfig { plugins = [ { plugin = vimPlugins.luasnip; @@ -65,15 +74,6 @@ let sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc"; }; - # this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex - # $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin - # we save b:did_ftplugin's value in a `plugin_was_loaded_too_late` file - texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" {} '' - mkdir -p $out/ftplugin - echo 'call system("echo ". exists("b:did_ftplugin") . " > plugin_was_loaded_too_late")' >> $out/ftplugin/tex.vim - echo ':q!' >> $out/ftplugin/tex.vim - '') // { pname = "test-ftplugin"; }; - # neovim-drv must be a wrapped neovim runTest = neovim-drv: buildCommand: runCommandLocal "test-${neovim-drv.name}" ({ @@ -81,18 +81,21 @@ let meta.platforms = neovim-drv.meta.platforms; }) ('' source ${nmt}/bash-lib/assertions.sh - vimrc="${writeText "init.vim" neovim-drv.initRc}" - luarc="${writeText "init.lua" neovim-drv.luaRcContent}" + vimrc="${writeText "test-${neovim-drv.name}-init.vim" neovim-drv.initRc}" + luarc="${writeText "test-${neovim-drv.name}-init.lua" neovim-drv.luaRcContent}" luarcGeneric="$out/patched.lua" vimrcGeneric="$out/patched.vim" mkdir $out + export HOME=$TMPDIR ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric" ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$luarc" > "$luarcGeneric" '' + buildCommand); in - pkgs.recurseIntoAttrs ( -rec { + pkgs.recurseIntoAttrs (rec { + + inherit nmt; + vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; }; ### neovim tests @@ -138,11 +141,21 @@ rec { }; run_nvim_with_plug = runTest nvim_with_plug '' - export HOME=$TMPDIR - ${nvim_with_plug}/bin/nvim -i NONE -c 'color base16-tomorrow-night' +quit! -e + ${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e ''; - nvim_with_ftplugin = neovim.override { + nvim_with_ftplugin = let + # this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex + # $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin + # we save b:did_ftplugin's value in a `plugin_was_loaded_too_late` file + texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" {} '' + mkdir -p $out/ftplugin + echo 'call system("echo ". exists("b:did_ftplugin") . " > plugin_was_loaded_too_late")' >> $out/ftplugin/tex.vim + echo ':q!' >> $out/ftplugin/tex.vim + '') // { pname = "test-ftplugin"; }; + in + + neovim.override { extraName = "-with-ftplugin"; configure.packages.plugins = { start = [ @@ -154,13 +167,14 @@ rec { # regression test that ftplugin files from plugins are loaded before the ftplugin # files from $VIMRUNTIME run_nvim_with_ftplugin = runTest nvim_with_ftplugin '' - export HOME=$TMPDIR echo '\documentclass{article}' > main.tex - ${nvim_with_ftplugin}/bin/nvim main.tex -c "set ft?" -c quit + ${nvim_with_ftplugin}/bin/nvim -i NONE -V3log.txt main.tex -c "set ft?" -c quit ls -l $TMPDIR - # if the file exists, then our plugin has been loaded instead of neovim's - [ ! -f plugin_was_loaded_too_late ] + # check the saved value b:did_ftplugin then our plugin has been loaded instead of neovim's + result="$(cat plugin_was_loaded_too_late)" + echo $result + [ "$result" = 0 ] ''; @@ -191,8 +205,8 @@ rec { ]; }; }; + checkHelpLuaPackages = runTest nvim_with_gitsigns_plugin '' - export HOME=$TMPDIR ${nvim_with_gitsigns_plugin}/bin/nvim -i NONE -c 'help gitsigns' +quitall! -e ''; @@ -220,8 +234,8 @@ rec { checkAliases = runTest nvim_with_aliases '' folder=${nvim_with_aliases}/bin - assertFileExists "$folder/vi" - assertFileExists "$folder/vim" + assertFileIsExecutable "$folder/vi" + assertFileIsExecutable "$folder/vim" ''; # having no RC generated should autodisable init.vim wrapping @@ -247,8 +261,7 @@ rec { }); nvim_with_lua_packages = runTest nvimWithLuaPackages '' - export HOME=$TMPDIR - ${nvimWithLuaPackages}/bin/nvim -i NONE --noplugin -es + ${nvimWithLuaPackages}/bin/nvim -V3log.txt -i NONE --noplugin +quitall! -e ''; # nixpkgs should install optional packages in the opt folder @@ -286,7 +299,6 @@ rec { }; run_nvim_with_opt_plugin = runTest nvim_with_opt_plugin '' - export HOME=$TMPDIR ${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e ''; @@ -296,9 +308,8 @@ rec { # for instance luasnip has a dependency on jsregexp can_require_transitive_deps = runTest nvim-with-luasnip '' - export HOME=$TMPDIR cat ${nvim-with-luasnip}/bin/nvim - ${nvim-with-luasnip}/bin/nvim -i NONE --cmd "lua require'jsregexp'" -e + ${nvim-with-luasnip}/bin/nvim -i NONE --cmd "lua require'jsregexp'" -e +quitall! ''; })