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
master
Matthieu Coudron 2021-05-28 23:44:43 +02:00 committed by Matthieu Coudron
parent 602163952d
commit 4a2cbcfbb4
4 changed files with 85 additions and 18 deletions

View File

@ -148,6 +148,7 @@ let
, vimAlias ? false , vimAlias ? false
, viAlias ? false , viAlias ? false
, configure ? {} , configure ? {}
, extraName ? ""
}: }:
let let
/* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */ /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */
@ -160,6 +161,7 @@ let
extraPython3Packages = compatFun extraPython3Packages; extraPython3Packages = compatFun extraPython3Packages;
inherit withNodeJs withRuby viAlias vimAlias; inherit withNodeJs withRuby viAlias vimAlias;
inherit configure; inherit configure;
inherit extraName;
}; };
in in
assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages."; assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages.";

View File

@ -27,23 +27,24 @@ let
# set to false if you want to control where to save the generated config # set to false if you want to control where to save the generated config
# (e.g., in ~/.config/init.vim or project/.nvimrc) # (e.g., in ~/.config/init.vim or project/.nvimrc)
, wrapRc ? true , wrapRc ? true
, neovimRcContent ? ""
, ... , ...
}@args: }@args:
let let
wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs; wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
# If configure != {}, we can't generate the rplugin.vim file with e.g # If configure != {}, we can't generate the rplugin.vim file with e.g
# NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
# the wrapper. That's why only when configure != {} (tested both here and # the wrapper. That's why only when configure != {} (tested both here and
# when postBuild is evaluated), we call makeWrapper once to generate a # when postBuild is evaluated), we call makeWrapper once to generate a
# wrapper with most arguments we need, excluding those that cause problems to # wrapper with most arguments we need, excluding those that cause problems to
# generate rplugin.vim, but still required for the final wrapper. # generate rplugin.vim, but still required for the final wrapper.
finalMakeWrapperArgs = finalMakeWrapperArgs =
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ] [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ] ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" args.neovimRcContent}" ] ++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ]
; ;
in in
assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env."; assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
@ -116,7 +117,10 @@ let
preferLocalBuild = true; preferLocalBuild = true;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
passthru = { unwrapped = neovim; }; passthru = {
unwrapped = neovim;
initRc = neovimRcContent;
};
meta = neovim.meta // { meta = neovim.meta // {
# To prevent builds on hydra # To prevent builds on hydra

View File

@ -1,9 +1,12 @@
{ vimUtils, vim_configurable, writeText, neovim, vimPlugins { vimUtils, vim_configurable, writeText, neovim, vimPlugins
, lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable , lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable
, neovim-unwrapped , neovim-unwrapped
, fetchFromGitLab
, pkgs
}: }:
let let
inherit (vimUtils) buildVimPluginFrom2Nix; inherit (vimUtils) buildVimPluginFrom2Nix;
inherit (neovimUtils) makeNeovimConfig;
packages.myVimPackage.start = with vimPlugins; [ vim-nix ]; packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
@ -16,27 +19,55 @@ let
} }
]; ];
nvimConfNix = neovimUtils.makeNeovimConfig { nvimConfNix = makeNeovimConfig {
inherit plugins; inherit plugins;
customRC = '' customRC = ''
" just a comment " just a comment
''; '';
}; };
wrapNeovim = suffix: config: nvimConfDontWrap = makeNeovimConfig {
inherit plugins;
customRC = ''
" just a comment
'';
};
wrapNeovim2 = suffix: config:
wrapNeovimUnstable neovim-unwrapped (config // { wrapNeovimUnstable neovim-unwrapped (config // {
extraName = suffix; extraName = suffix;
wrapRc = true;
}); });
nmt = fetchFromGitLab {
owner = "rycee";
repo = "nmt";
rev = "d2cc8c1042b1c2511f68f40e2790a8c0e29eeb42";
sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc";
};
runTest = neovim-drv: buildCommand:
pkgs.runCommandLocal "test-${neovim-drv.name}" ({
nativeBuildInputs = [ ];
meta.platforms = neovim-drv.meta.platforms;
}) (''
source ${nmt}/bash-lib/assertions.sh
vimrc="${writeText "init.vim" neovim-drv.initRc}"
vimrcGeneric="$out/patched.vim"
mkdir $out
${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric"
'' + buildCommand);
in in
{ pkgs.recurseIntoAttrs (
rec {
vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; }; vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
### neovim tests ### neovim tests
################## ##################
nvim_with_plugins = wrapNeovim "-with-plugins" nvimConfNix; nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix;
nvim_via_override = neovim.override { nvim_via_override = neovim.override {
extraName = "-via-override";
configure = { configure = {
packages.foo.start = [ vimPlugins.ale ]; packages.foo.start = [ vimPlugins.ale ];
customRC = '' customRC = ''
@ -45,6 +76,29 @@ in
}; };
}; };
# nixpkgs should detect that no wrapping is necessary
nvimShouldntWrap = wrapNeovim2 "-should-not-wrap" nvimConfNix;
# this will generate a neovimRc content but we disable wrapping
nvimDontWrap = wrapNeovim2 "-dont-wrap" (makeNeovimConfig {
wrapRc = false;
customRC = ''
" this shouldn't trigger the creation of an init.vim
'';
});
nvim_dontwrap-test = runTest nvimDontWrap ''
! grep "-u" ${nvimDontWrap}/bin/nvim
'';
nvim_via_override-test = runTest nvim_via_override ''
assertFileContent \
"$vimrcGeneric" \
"${./neovim-override.vim}"
'';
### vim tests ### vim tests
################## ##################
vim_with_vim2nix = vim_configurable.customize { vim_with_vim2nix = vim_configurable.customize {
@ -107,4 +161,4 @@ in
test_nvim_with_remote_plugin = neovim.override { test_nvim_with_remote_plugin = neovim.override {
configure.pathogen.pluginNames = with vimPlugins; [ deoplete-nvim ]; configure.pathogen.pluginNames = with vimPlugins; [ deoplete-nvim ];
}; };
} })

View File

@ -0,0 +1,7 @@
" configuration generated by NIX
set nocompatible
set packpath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir
set runtimepath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir
:help ale