neovim: add some tests

To test the generated RC is included in the file and that we have the
option not to wrap the RC.

run:
nix-build -A tests.vim

authored by

Matthieu Coudron and committed by
Matthieu Coudron
4a2cbcfb 60216395

+85 -18
+2
pkgs/applications/editors/neovim/utils.nix
··· 148 , vimAlias ? false 149 , viAlias ? false 150 , configure ? {} 151 }: 152 let 153 /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */ ··· 160 extraPython3Packages = compatFun extraPython3Packages; 161 inherit withNodeJs withRuby viAlias vimAlias; 162 inherit configure; 163 }; 164 in 165 assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages.";
··· 148 , vimAlias ? false 149 , viAlias ? false 150 , configure ? {} 151 + , extraName ? "" 152 }: 153 let 154 /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */ ··· 161 extraPython3Packages = compatFun extraPython3Packages; 162 inherit withNodeJs withRuby viAlias vimAlias; 163 inherit configure; 164 + inherit extraName; 165 }; 166 in 167 assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages.";
+16 -12
pkgs/applications/editors/neovim/wrapper.nix
··· 27 # set to false if you want to control where to save the generated config 28 # (e.g., in ~/.config/init.vim or project/.nvimrc) 29 , wrapRc ? true 30 , ... 31 }@args: 32 let 33 34 wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs; 35 36 - # If configure != {}, we can't generate the rplugin.vim file with e.g 37 - # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in 38 - # the wrapper. That's why only when configure != {} (tested both here and 39 - # when postBuild is evaluated), we call makeWrapper once to generate a 40 - # wrapper with most arguments we need, excluding those that cause problems to 41 - # generate rplugin.vim, but still required for the final wrapper. 42 - finalMakeWrapperArgs = 43 - [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ] 44 - ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ] 45 - ++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" args.neovimRcContent}" ] 46 - ; 47 in 48 assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env."; 49 ··· 116 preferLocalBuild = true; 117 118 nativeBuildInputs = [ makeWrapper ]; 119 - passthru = { unwrapped = neovim; }; 120 121 meta = neovim.meta // { 122 # To prevent builds on hydra
··· 27 # set to false if you want to control where to save the generated config 28 # (e.g., in ~/.config/init.vim or project/.nvimrc) 29 , wrapRc ? true 30 + , neovimRcContent ? "" 31 , ... 32 }@args: 33 let 34 35 wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs; 36 37 + # If configure != {}, we can't generate the rplugin.vim file with e.g 38 + # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in 39 + # the wrapper. That's why only when configure != {} (tested both here and 40 + # when postBuild is evaluated), we call makeWrapper once to generate a 41 + # wrapper with most arguments we need, excluding those that cause problems to 42 + # generate rplugin.vim, but still required for the final wrapper. 43 + finalMakeWrapperArgs = 44 + [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ] 45 + ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ] 46 + ++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ] 47 + ; 48 in 49 assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env."; 50 ··· 117 preferLocalBuild = true; 118 119 nativeBuildInputs = [ makeWrapper ]; 120 + passthru = { 121 + unwrapped = neovim; 122 + initRc = neovimRcContent; 123 + }; 124 125 meta = neovim.meta // { 126 # To prevent builds on hydra
+60 -6
pkgs/test/vim/default.nix
··· 1 { vimUtils, vim_configurable, writeText, neovim, vimPlugins 2 , lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable 3 , neovim-unwrapped 4 }: 5 let 6 inherit (vimUtils) buildVimPluginFrom2Nix; 7 8 packages.myVimPackage.start = with vimPlugins; [ vim-nix ]; 9 ··· 16 } 17 ]; 18 19 - nvimConfNix = neovimUtils.makeNeovimConfig { 20 inherit plugins; 21 customRC = '' 22 " just a comment 23 ''; 24 }; 25 26 - wrapNeovim = suffix: config: 27 wrapNeovimUnstable neovim-unwrapped (config // { 28 extraName = suffix; 29 - wrapRc = true; 30 }); 31 in 32 - { 33 vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; }; 34 35 ### neovim tests 36 ################## 37 - nvim_with_plugins = wrapNeovim "-with-plugins" nvimConfNix; 38 39 nvim_via_override = neovim.override { 40 configure = { 41 packages.foo.start = [ vimPlugins.ale ]; 42 customRC = '' ··· 44 ''; 45 }; 46 }; 47 48 ### vim tests 49 ################## ··· 107 test_nvim_with_remote_plugin = neovim.override { 108 configure.pathogen.pluginNames = with vimPlugins; [ deoplete-nvim ]; 109 }; 110 - }
··· 1 { vimUtils, vim_configurable, writeText, neovim, vimPlugins 2 , lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable 3 , neovim-unwrapped 4 + , fetchFromGitLab 5 + , pkgs 6 }: 7 let 8 inherit (vimUtils) buildVimPluginFrom2Nix; 9 + inherit (neovimUtils) makeNeovimConfig; 10 11 packages.myVimPackage.start = with vimPlugins; [ vim-nix ]; 12 ··· 19 } 20 ]; 21 22 + nvimConfNix = makeNeovimConfig { 23 + inherit plugins; 24 + customRC = '' 25 + " just a comment 26 + ''; 27 + }; 28 + 29 + nvimConfDontWrap = makeNeovimConfig { 30 inherit plugins; 31 customRC = '' 32 " just a comment 33 ''; 34 }; 35 36 + wrapNeovim2 = suffix: config: 37 wrapNeovimUnstable neovim-unwrapped (config // { 38 extraName = suffix; 39 }); 40 + 41 + nmt = fetchFromGitLab { 42 + owner = "rycee"; 43 + repo = "nmt"; 44 + rev = "d2cc8c1042b1c2511f68f40e2790a8c0e29eeb42"; 45 + sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc"; 46 + }; 47 + 48 + runTest = neovim-drv: buildCommand: 49 + pkgs.runCommandLocal "test-${neovim-drv.name}" ({ 50 + nativeBuildInputs = [ ]; 51 + meta.platforms = neovim-drv.meta.platforms; 52 + }) ('' 53 + source ${nmt}/bash-lib/assertions.sh 54 + vimrc="${writeText "init.vim" neovim-drv.initRc}" 55 + vimrcGeneric="$out/patched.vim" 56 + mkdir $out 57 + ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric" 58 + '' + buildCommand); 59 + 60 in 61 + pkgs.recurseIntoAttrs ( 62 + rec { 63 vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; }; 64 65 ### neovim tests 66 ################## 67 + nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix; 68 69 nvim_via_override = neovim.override { 70 + extraName = "-via-override"; 71 configure = { 72 packages.foo.start = [ vimPlugins.ale ]; 73 customRC = '' ··· 75 ''; 76 }; 77 }; 78 + 79 + 80 + # nixpkgs should detect that no wrapping is necessary 81 + nvimShouldntWrap = wrapNeovim2 "-should-not-wrap" nvimConfNix; 82 + 83 + 84 + # this will generate a neovimRc content but we disable wrapping 85 + nvimDontWrap = wrapNeovim2 "-dont-wrap" (makeNeovimConfig { 86 + wrapRc = false; 87 + customRC = '' 88 + " this shouldn't trigger the creation of an init.vim 89 + ''; 90 + }); 91 + 92 + nvim_dontwrap-test = runTest nvimDontWrap '' 93 + ! grep "-u" ${nvimDontWrap}/bin/nvim 94 + ''; 95 + 96 + nvim_via_override-test = runTest nvim_via_override '' 97 + assertFileContent \ 98 + "$vimrcGeneric" \ 99 + "${./neovim-override.vim}" 100 + ''; 101 102 ### vim tests 103 ################## ··· 161 test_nvim_with_remote_plugin = neovim.override { 162 configure.pathogen.pluginNames = with vimPlugins; [ deoplete-nvim ]; 163 }; 164 + })
+7
pkgs/test/vim/neovim-override.vim
···
··· 1 + " configuration generated by NIX 2 + set nocompatible 3 + 4 + set packpath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir 5 + set runtimepath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir 6 + 7 + :help ale