summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorMatthieu Coudron <mcoudron@hotmail.com>2021-06-08 00:52:17 +0200
committerMatthieu Coudron <teto@users.noreply.github.com>2021-06-09 21:45:25 +0200
commit83f6711464e03a856fb554693fe2e0f3af2ab0d5 (patch)
treed49259077e82562a5bacbe9aa88d0bc5b3b14ebc /pkgs
parentcc90d13883f1bd126c649ce73d448e96829b7cb6 (diff)
downloadnixpkgs-83f6711464e03a856fb554693fe2e0f3af2ab0d5.tar
nixpkgs-83f6711464e03a856fb554693fe2e0f3af2ab0d5.tar.gz
nixpkgs-83f6711464e03a856fb554693fe2e0f3af2ab0d5.tar.bz2
nixpkgs-83f6711464e03a856fb554693fe2e0f3af2ab0d5.tar.lz
nixpkgs-83f6711464e03a856fb554693fe2e0f3af2ab0d5.tar.xz
nixpkgs-83f6711464e03a856fb554693fe2e0f3af2ab0d5.tar.zst
nixpkgs-83f6711464e03a856fb554693fe2e0f3af2ab0d5.zip
neovim.tests: added more tests
to check for creation of vi/vim aliases.
These tests also now follow the coding conventions of having tests in
passthru.test .
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/applications/editors/neovim/neovim-override.vim (renamed from pkgs/test/vim/neovim-override.vim)0
-rw-r--r--pkgs/applications/editors/neovim/tests.nix135
-rw-r--r--pkgs/applications/editors/neovim/wrapper.nix4
-rw-r--r--pkgs/test/vim/default.nix107
4 files changed, 142 insertions, 104 deletions
diff --git a/pkgs/test/vim/neovim-override.vim b/pkgs/applications/editors/neovim/neovim-override.vim
index 34a1a8f1f43..34a1a8f1f43 100644
--- a/pkgs/test/vim/neovim-override.vim
+++ b/pkgs/applications/editors/neovim/neovim-override.vim
diff --git a/pkgs/applications/editors/neovim/tests.nix b/pkgs/applications/editors/neovim/tests.nix
new file mode 100644
index 00000000000..f9d0d659b73
--- /dev/null
+++ b/pkgs/applications/editors/neovim/tests.nix
@@ -0,0 +1,135 @@
+{ vimUtils, vim_configurable, writeText, neovim, vimPlugins
+, lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable
+, neovim-unwrapped
+, fetchFromGitLab
+, pkgs
+}:
+let
+  inherit (vimUtils) buildVimPluginFrom2Nix;
+  inherit (neovimUtils) makeNeovimConfig;
+
+  packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
+
+  plugins = with vimPlugins; [
+    {
+      plugin = vim-obsession;
+      config = ''
+        map <Leader>$ <Cmd>Obsession<CR>
+      '';
+    }
+  ];
+
+  nvimConfNix = makeNeovimConfig {
+    inherit plugins;
+    customRC = ''
+      " just a comment
+    '';
+  };
+
+  nvimAutoDisableWrap = makeNeovimConfig { };
+
+  nvimConfDontWrap = makeNeovimConfig {
+    inherit plugins;
+    customRC = ''
+      " just a comment
+    '';
+  };
+
+  wrapNeovim2 = suffix: config:
+    wrapNeovimUnstable neovim-unwrapped (config // {
+      extraName = suffix;
+    });
+
+  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
+  pkgs.recurseIntoAttrs (
+rec {
+  vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
+
+  ### neovim tests
+  ##################
+  nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix;
+
+  nvim_via_override = neovim.override {
+    extraName = "-via-override";
+    configure = {
+      packages.foo.start = [ vimPlugins.ale ];
+      customRC = ''
+        :help ale
+      '';
+    };
+  };
+
+  nvim_with_aliases = neovim.override {
+    extraName = "-with-aliases";
+    vimAlias = true;
+    viAlias = true;
+  };
+
+  # nixpkgs should detect that no wrapping is necessary
+  nvimShouldntWrap = wrapNeovim2 "-should-not-wrap" nvimAutoDisableWrap;
+
+  # this will generate a neovimRc content but we disable wrapping
+  nvimDontWrap = wrapNeovim2 "-forced-nowrap" (makeNeovimConfig {
+    wrapRc = false;
+    customRC = ''
+      " this shouldn't trigger the creation of an init.vim
+    '';
+  });
+
+  force-nowrap = runTest nvimDontWrap ''
+      ! grep "-u" ${nvimDontWrap}/bin/nvim
+  '';
+
+  nvim_via_override-test = runTest nvim_via_override ''
+      assertFileContent \
+        "$vimrcGeneric" \
+        "${./neovim-override.vim}"
+  '';
+
+
+  checkAliases = runTest nvim_with_aliases ''
+      folder=${nvim_with_aliases}/bin
+      assertFileExists "$folder/vi"
+      assertFileExists "$folder/vim"
+  '';
+
+  # having no RC generated should autodisable init.vim wrapping
+  nvim_autowrap = runTest nvim_via_override ''
+      ! grep "-u" ${nvimShouldntWrap}/bin/nvim
+  '';
+
+
+  # system remote plugin manifest should be generated, deoplete should be usable
+  # without the user having to do `UpdateRemotePlugins`. To test, launch neovim
+  # and do `:call deoplete#enable()`. It will print an error if the remote
+  # plugin is not registered.
+  test_nvim_with_remote_plugin = neovim.override {
+    extraName = "-pathogen-remote";
+    configure.pathogen.pluginNames = with vimPlugins; [ deoplete-nvim ];
+  };
+
+  # only neovim makes use of `requiredPlugins`, test this here
+  test_nvim_with_vim_nix_using_pathogen = neovim.override {
+    extraName = "-pathogen";
+    configure.pathogen.pluginNames = [ "vim-nix" ];
+  };
+})
diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix
index 07a1dad7c09..96b61a43cca 100644
--- a/pkgs/applications/editors/neovim/wrapper.nix
+++ b/pkgs/applications/editors/neovim/wrapper.nix
@@ -4,6 +4,7 @@
 , nodejs
 , nodePackages
 , python3Packages
+, callPackage
 }:
 with lib;
 
@@ -120,6 +121,9 @@ let
     passthru = {
       unwrapped = neovim;
       initRc = neovimRcContent;
+
+      tests = callPackage ./tests.nix {
+      };
     };
 
     meta = neovim.meta // {
diff --git a/pkgs/test/vim/default.nix b/pkgs/test/vim/default.nix
index 3bdc3234134..cb3953a63f5 100644
--- a/pkgs/test/vim/default.nix
+++ b/pkgs/test/vim/default.nix
@@ -1,104 +1,16 @@
-{ vimUtils, vim_configurable, writeText, neovim, vimPlugins
-, lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable
-, neovim-unwrapped
-, fetchFromGitLab
+{ vimUtils, vim_configurable, writeText, vimPlugins
+, lib, fetchFromGitHub
 , pkgs
 }:
 let
   inherit (vimUtils) buildVimPluginFrom2Nix;
-  inherit (neovimUtils) makeNeovimConfig;
 
   packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
 
-  plugins = with vimPlugins; [
-    {
-      plugin = vim-obsession;
-      config = ''
-        map <Leader>$ <Cmd>Obsession<CR>
-      '';
-    }
-  ];
-
-  nvimConfNix = makeNeovimConfig {
-    inherit plugins;
-    customRC = ''
-      " just a comment
-    '';
-  };
-
-  nvimConfDontWrap = makeNeovimConfig {
-    inherit plugins;
-    customRC = ''
-      " just a comment
-    '';
-  };
-
-  wrapNeovim2 = suffix: config:
-    wrapNeovimUnstable neovim-unwrapped (config // {
-      extraName = suffix;
-    });
-
-  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
-  pkgs.recurseIntoAttrs (
-rec {
+  pkgs.recurseIntoAttrs (rec {
   vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
 
-  ### neovim tests
-  ##################
-  nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix;
-
-  nvim_via_override = neovim.override {
-    extraName = "-via-override";
-    configure = {
-      packages.foo.start = [ vimPlugins.ale ];
-      customRC = ''
-        :help ale
-      '';
-    };
-  };
-
-
-  # 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_with_vim2nix = vim_configurable.customize {
@@ -126,11 +38,6 @@ rec {
     vimrcConfig.packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
   };
 
-  # only neovim makes use of `requiredPlugins`, test this here
-  test_nvim_with_vim_nix_using_pathogen = neovim.override {
-    configure.pathogen.pluginNames = [ "vim-nix" ];
-  };
-
   # regression test for https://github.com/NixOS/nixpkgs/issues/53112
   # The user may have specified their own plugins which may not be formatted
   # exactly as the generated ones. In particular, they may not have the `pname`
@@ -153,12 +60,4 @@ rec {
       });
     vimrcConfig.vam.pluginDictionaries = [ { names = [ "vim-trailing-whitespace" ]; } ];
   };
-
-  # system remote plugin manifest should be generated, deoplete should be usable
-  # without the user having to do `UpdateRemotePlugins`. To test, launch neovim
-  # and do `:call deoplete#enable()`. It will print an error if the remote
-  # plugin is not registered.
-  test_nvim_with_remote_plugin = neovim.override {
-    configure.pathogen.pluginNames = with vimPlugins; [ deoplete-nvim ];
-  };
 })