summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthieu Coudron <teto@users.noreply.github.com>2021-04-21 12:55:05 +0200
committerGitHub <noreply@github.com>2021-04-21 12:55:05 +0200
commitb3abdc9534a675da2aa7631d505a5f71ef30ecfa (patch)
tree89d0c303dada92b2614d1f66da96bc3c931bd0fd
parent8c87951c37e1e989c0169960879fd378774b646c (diff)
downloadnixpkgs-b3abdc9534a675da2aa7631d505a5f71ef30ecfa.tar
nixpkgs-b3abdc9534a675da2aa7631d505a5f71ef30ecfa.tar.gz
nixpkgs-b3abdc9534a675da2aa7631d505a5f71ef30ecfa.tar.bz2
nixpkgs-b3abdc9534a675da2aa7631d505a5f71ef30ecfa.tar.lz
nixpkgs-b3abdc9534a675da2aa7631d505a5f71ef30ecfa.tar.xz
nixpkgs-b3abdc9534a675da2aa7631d505a5f71ef30ecfa.tar.zst
nixpkgs-b3abdc9534a675da2aa7631d505a5f71ef30ecfa.zip
tests.vim: init (moved from vim-utils.nix) (#119467)
* tests.vim: init (moved from vim-utils.nix)

Moved tests from pkgs/misc/vim-plugins/vim-utils.nix to pkgs/test/vim.
Also reduced the amount of generated config:
- Make it possible to have an empty config when configured adequately
- removed default vim config when using native packages, it could be
  source of bugs see linked issues (syntax on overrides vim highlights)

Things to watch out for:
- if you set configure.beforePlugins yourself, you will need to add set nocompatible too not to lose it
- filetype indent plugin on | syn on is not enabled anymore by default for the vim-plug installer: I dont think we should override vim defualts, at least not here since it is shared with neovim. Also sometimes it's enabled before plugins (pathogen etc,) which is not consistent.


you can run the tests via
$ nix-build -A tests.vim
-rw-r--r--pkgs/applications/editors/neovim/wrapper.nix1
-rw-r--r--pkgs/misc/vim-plugins/vim-utils.nix159
-rw-r--r--pkgs/test/default.nix2
-rw-r--r--pkgs/test/vim/default.nix72
4 files changed, 122 insertions, 112 deletions
diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix
index 41ff62a619f..8b42191bde6 100644
--- a/pkgs/applications/editors/neovim/wrapper.nix
+++ b/pkgs/applications/editors/neovim/wrapper.nix
@@ -1,5 +1,4 @@
 { stdenv, symlinkJoin, lib, makeWrapper
-, vimUtils
 , writeText
 , bundlerEnv, ruby
 , nodejs
diff --git a/pkgs/misc/vim-plugins/vim-utils.nix b/pkgs/misc/vim-plugins/vim-utils.nix
index fd66c48ecb2..c55e8aa0a01 100644
--- a/pkgs/misc/vim-plugins/vim-utils.nix
+++ b/pkgs/misc/vim-plugins/vim-utils.nix
@@ -1,4 +1,5 @@
-{ lib, stdenv, vim, vimPlugins, vim_configurable, neovim, buildEnv, writeText, writeScriptBin
+# tests available at pkgs/test/vim
+{ lib, stdenv, vim, vimPlugins, vim_configurable, buildEnv, writeText, writeScriptBin
 , nix-prefetch-hg, nix-prefetch-git
 , fetchFromGitHub, runtimeShell
 }:
@@ -183,13 +184,49 @@ let
 
   rtpPath = "share/vim-plugins";
 
+  nativeImpl = packages: lib.optionalString (packages != null)
+  (let
+    link = (packageName: dir: pluginPath: "ln -sf ${pluginPath}/share/vim-plugins/* $out/pack/${packageName}/${dir}");
+    packageLinks = (packageName: {start ? [], opt ? []}:
+    let
+      # `nativeImpl` expects packages to be derivations, not strings (as
+      # opposed to older implementations that have to maintain backwards
+      # compatibility). Therefore we don't need to deal with "knownPlugins"
+      # and can simply pass `null`.
+      depsOfOptionalPlugins = lib.subtractLists opt (findDependenciesRecursively opt);
+      startWithDeps = findDependenciesRecursively start;
+    in
+      [ "mkdir -p $out/pack/${packageName}/start" ]
+      # To avoid confusion, even dependencies of optional plugins are added
+      # to `start` (except if they are explicitly listed as optional plugins).
+      ++ (builtins.map (link packageName "start") (lib.unique (startWithDeps ++ depsOfOptionalPlugins)))
+      ++ ["mkdir -p $out/pack/${packageName}/opt"]
+      ++ (builtins.map (link packageName "opt") opt)
+    );
+    packDir = (packages:
+      stdenv.mkDerivation {
+        name = "vim-pack-dir";
+        src = ./.;
+        installPhase = lib.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList packageLinks packages));
+        preferLocalBuild = true;
+      }
+    );
+  in
+  ''
+    set packpath^=${packDir packages}
+    set runtimepath^=${packDir packages}
+  '');
+
   vimrcContent = {
     packages ? null,
     vam ? null,
     pathogen ? null,
     plug ? null,
-    beforePlugins ? "",
-    customRC ? ""
+    beforePlugins ? ''
+      " configuration generated by NIX
+      set nocompatible
+    '',
+    customRC ? null
   }:
 
     let
@@ -301,56 +338,16 @@ let
         call vam#Scripts(l, {})
       '');
 
-      nativeImpl = lib.optionalString (packages != null)
-      (let
-        link = (packageName: dir: pluginPath: "ln -sf ${pluginPath}/share/vim-plugins/* $out/pack/${packageName}/${dir}");
-        packageLinks = (packageName: {start ? [], opt ? []}:
-        let
-          # `nativeImpl` expects packages to be derivations, not strings (as
-          # opposed to older implementations that have to maintain backwards
-          # compatibility). Therefore we don't need to deal with "knownPlugins"
-          # and can simply pass `null`.
-          depsOfOptionalPlugins = lib.subtractLists opt (findDependenciesRecursively opt);
-          startWithDeps = findDependenciesRecursively start;
-        in
-          ["mkdir -p $out/pack/${packageName}/start"]
-          # To avoid confusion, even dependencies of optional plugins are added
-          # to `start` (except if they are explicitly listed as optional plugins).
-          ++ (builtins.map (link packageName "start") (lib.unique (startWithDeps ++ depsOfOptionalPlugins)))
-          ++ ["mkdir -p $out/pack/${packageName}/opt"]
-          ++ (builtins.map (link packageName "opt") opt)
-        );
-        packDir = (packages:
-          stdenv.mkDerivation {
-            name = "vim-pack-dir";
-            src = ./.;
-            installPhase = lib.concatStringsSep
-                             "\n"
-                             (lib.flatten (lib.mapAttrsToList packageLinks packages));
-            preferLocalBuild = true;
-          }
-        );
-      in
-      ''
-        set packpath^=${packDir packages}
-        set runtimepath^=${packDir packages}
-
-        filetype indent plugin on | syn on
-      '');
-
-  in ''
-  " configuration generated by NIX
-  set nocompatible
-
-  ${beforePlugins}
+      entries = [
+        beforePlugins
+        vamImpl pathogenImpl plugImpl
+        (nativeImpl packages)
+        customRC
+      ];
 
-  ${vamImpl}
-  ${pathogenImpl}
-  ${plugImpl}
-  ${nativeImpl}
+    in
+      lib.concatStringsSep "\n" (lib.filter (x: x != null && x != "") entries);
 
-  ${customRC}
-  '';
   vimrcFile = settings: writeText "vimrc" (vimrcContent settings);
 
 in
@@ -448,8 +445,6 @@ rec {
     '';
   };
 
-  vim_with_vim2nix = vim_configurable.customize { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; };
-
   inherit (import ./build-vim-plugin.nix { inherit lib stdenv rtpPath vim; }) buildVimPlugin buildVimPluginFrom2Nix;
 
   # used to figure out which python dependencies etc. neovim needs
@@ -475,62 +470,4 @@ rec {
       nativePlugins = lib.concatMap ({start?[], opt?[], knownPlugins?vimPlugins}: start++opt) nativePluginsConfigs;
     in
       nativePlugins ++ nonNativePlugins;
-
-
-  # test cases:
-  test_vim_with_vim_nix_using_vam = vim_configurable.customize {
-   name = "vim-with-vim-addon-nix-using-vam";
-    vimrcConfig.vam.pluginDictionaries = [{name = "vim-nix"; }];
-  };
-
-  test_vim_with_vim_nix_using_pathogen = vim_configurable.customize {
-    name = "vim-with-vim-addon-nix-using-pathogen";
-    vimrcConfig.pathogen.pluginNames = [ "vim-nix" ];
-  };
-
-  test_vim_with_vim_nix_using_plug = vim_configurable.customize {
-    name = "vim-with-vim-addon-nix-using-plug";
-    vimrcConfig.plug.plugins = with vimPlugins; [ vim-nix ];
-  };
-
-  test_vim_with_vim_nix = vim_configurable.customize {
-    name = "vim-with-vim-addon-nix";
-    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`
-  # attribute.
-  test_vim_with_custom_plugin = vim_configurable.customize {
-    name = "vim_with_custom_plugin";
-    vimrcConfig.vam.knownPlugins =
-      vimPlugins // ({
-        vim-trailing-whitespace = buildVimPluginFrom2Nix {
-          name = "vim-trailing-whitespace";
-          src = fetchFromGitHub {
-            owner = "bronson";
-            repo = "vim-trailing-whitespace";
-            rev = "4c596548216b7c19971f8fc94e38ef1a2b55fee6";
-            sha256 = "0f1cpnp1nxb4i5hgymjn2yn3k1jwkqmlgw1g02sq270lavp2dzs9";
-          };
-          # make sure string dependencies are handled
-          dependencies = [ "vim-nix" ];
-        };
-      });
-    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 ];
-  };
 }
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index fa93ceb0721..b24fc539c93 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -41,6 +41,8 @@ with pkgs;
   rustCustomSysroot = callPackage ./rust-sysroot {};
   buildRustCrate = callPackage ../build-support/rust/build-rust-crate/test { };
 
+  vim = callPackage ./vim {};
+
   nixos-functions = callPackage ./nixos-functions {};
 
   patch-shebangs = callPackage ./patch-shebangs {};
diff --git a/pkgs/test/vim/default.nix b/pkgs/test/vim/default.nix
new file mode 100644
index 00000000000..4ca004a60c3
--- /dev/null
+++ b/pkgs/test/vim/default.nix
@@ -0,0 +1,72 @@
+{ vimUtils, vim_configurable, neovim, vimPlugins
+, lib, fetchFromGitHub,
+}:
+let
+  inherit (vimUtils) buildVimPluginFrom2Nix;
+
+  packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
+in
+{
+  vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
+
+  vim_with_vim2nix = vim_configurable.customize {
+    name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ];
+  };
+
+  # test cases:
+  test_vim_with_vim_nix_using_vam = vim_configurable.customize {
+   name = "vim-with-vim-addon-nix-using-vam";
+    vimrcConfig.vam.pluginDictionaries = [{name = "vim-nix"; }];
+  };
+
+  test_vim_with_vim_nix_using_pathogen = vim_configurable.customize {
+    name = "vim-with-vim-addon-nix-using-pathogen";
+    vimrcConfig.pathogen.pluginNames = [ "vim-nix" ];
+  };
+
+  test_vim_with_vim_nix_using_plug = vim_configurable.customize {
+    name = "vim-with-vim-addon-nix-using-plug";
+    vimrcConfig.plug.plugins = with vimPlugins; [ vim-nix ];
+  };
+
+  test_vim_with_vim_nix = vim_configurable.customize {
+    name = "vim-with-vim-addon-nix";
+    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`
+  # attribute.
+  test_vim_with_custom_plugin = vim_configurable.customize {
+    name = "vim_with_custom_plugin";
+    vimrcConfig.vam.knownPlugins =
+      vimPlugins // ({
+        vim-trailing-whitespace = buildVimPluginFrom2Nix {
+          name = "vim-trailing-whitespace";
+          src = fetchFromGitHub {
+            owner = "bronson";
+            repo = "vim-trailing-whitespace";
+            rev = "4c596548216b7c19971f8fc94e38ef1a2b55fee6";
+            sha256 = "0f1cpnp1nxb4i5hgymjn2yn3k1jwkqmlgw1g02sq270lavp2dzs9";
+          };
+          # make sure string dependencies are handled
+          dependencies = [ "vim-nix" ];
+        };
+      });
+    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 ];
+  };
+}