From 1136ea818720becd1b1c6e67008d1273ba251469 Mon Sep 17 00:00:00 2001 From: "Matthieu C." <886074+teto@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:11:32 +0200 Subject: [PATCH 1/3] neovim.tests.nvim_with_ftplugin: fix the test my previous "fix" broke the test, this restores it. --- .../editors/neovim/tests/default.nix | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 9152d93c1544..15a2711015d2 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -65,15 +65,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}" ({ @@ -139,10 +130,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 = [ @@ -157,10 +159,12 @@ rec { 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 ] ''; From e9e4cd93917d58a954a36fa5eb084fc34d3a88a8 Mon Sep 17 00:00:00 2001 From: "Matthieu C." <886074+teto@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:23:32 +0200 Subject: [PATCH 2/3] neovim.tests.can_require_transitive_deps: fix running it would hang without ever exiting neovim --- pkgs/applications/editors/neovim/tests/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 15a2711015d2..dfb5ed94c5f3 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -302,7 +302,7 @@ rec { 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! ''; }) From 0fc790f4ccd227e67ad2b8df9ecd53e54ce48957 Mon Sep 17 00:00:00 2001 From: "Matthieu C." <886074+teto@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:32:43 +0200 Subject: [PATCH 3/3] neovim.tests: minor improvements - factorize the export HOME in runTest - adjust suffix for nvim-with-luasnip (it was misleading) - make 'checkAliases' check for executable bit as well - expose nmt because it's more convenient to find its store path --- .../editors/neovim/tests/default.nix | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index dfb5ed94c5f3..14d682e14e43 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; @@ -72,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 @@ -129,7 +141,6 @@ rec { }; run_nvim_with_plug = runTest nvim_with_plug '' - export HOME=$TMPDIR ${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e ''; @@ -156,7 +167,6 @@ 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 -i NONE -V3log.txt main.tex -c "set ft?" -c quit @@ -195,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 ''; @@ -224,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 @@ -251,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 @@ -290,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 ''; @@ -300,7 +308,6 @@ 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 +quitall! '';