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 148 , vimAlias ? false 149 149 , viAlias ? false 150 150 , configure ? {} 151 + , extraName ? "" 151 152 }: 152 153 let 153 154 /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */ ··· 160 161 extraPython3Packages = compatFun extraPython3Packages; 161 162 inherit withNodeJs withRuby viAlias vimAlias; 162 163 inherit configure; 164 + inherit extraName; 163 165 }; 164 166 in 165 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 27 # set to false if you want to control where to save the generated config 28 28 # (e.g., in ~/.config/init.vim or project/.nvimrc) 29 29 , wrapRc ? true 30 + , neovimRcContent ? "" 30 31 , ... 31 32 }@args: 32 33 let 33 34 34 35 wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs; 35 36 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 - ; 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 + ; 47 48 in 48 49 assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env."; 49 50 ··· 116 117 preferLocalBuild = true; 117 118 118 119 nativeBuildInputs = [ makeWrapper ]; 119 - passthru = { unwrapped = neovim; }; 120 + passthru = { 121 + unwrapped = neovim; 122 + initRc = neovimRcContent; 123 + }; 120 124 121 125 meta = neovim.meta // { 122 126 # To prevent builds on hydra
+60 -6
pkgs/test/vim/default.nix
··· 1 1 { vimUtils, vim_configurable, writeText, neovim, vimPlugins 2 2 , lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable 3 3 , neovim-unwrapped 4 + , fetchFromGitLab 5 + , pkgs 4 6 }: 5 7 let 6 8 inherit (vimUtils) buildVimPluginFrom2Nix; 9 + inherit (neovimUtils) makeNeovimConfig; 7 10 8 11 packages.myVimPackage.start = with vimPlugins; [ vim-nix ]; 9 12 ··· 16 19 } 17 20 ]; 18 21 19 - nvimConfNix = neovimUtils.makeNeovimConfig { 22 + nvimConfNix = makeNeovimConfig { 23 + inherit plugins; 24 + customRC = '' 25 + " just a comment 26 + ''; 27 + }; 28 + 29 + nvimConfDontWrap = makeNeovimConfig { 20 30 inherit plugins; 21 31 customRC = '' 22 32 " just a comment 23 33 ''; 24 34 }; 25 35 26 - wrapNeovim = suffix: config: 36 + wrapNeovim2 = suffix: config: 27 37 wrapNeovimUnstable neovim-unwrapped (config // { 28 38 extraName = suffix; 29 - wrapRc = true; 30 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 + 31 60 in 32 - { 61 + pkgs.recurseIntoAttrs ( 62 + rec { 33 63 vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; }; 34 64 35 65 ### neovim tests 36 66 ################## 37 - nvim_with_plugins = wrapNeovim "-with-plugins" nvimConfNix; 67 + nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix; 38 68 39 69 nvim_via_override = neovim.override { 70 + extraName = "-via-override"; 40 71 configure = { 41 72 packages.foo.start = [ vimPlugins.ale ]; 42 73 customRC = '' ··· 44 75 ''; 45 76 }; 46 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 + ''; 47 101 48 102 ### vim tests 49 103 ################## ··· 107 161 test_nvim_with_remote_plugin = neovim.override { 108 162 configure.pathogen.pluginNames = with vimPlugins; [ deoplete-nvim ]; 109 163 }; 110 - } 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