From b4cac9327b3583a217a8b26984783bf1473333ca Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 20 Aug 2024 18:54:43 +0100 Subject: [PATCH] tests: replace `helpers.enableExceptInTests` with module option --- lib/default.nix | 3 +-- lib/helpers.nix | 7 ++++--- lib/utils.nix | 8 +------- modules/misc/context.nix | 9 +++++++++ tests/enable-except-in-tests.nix | 4 ++-- tests/test-derivation.nix | 6 +++--- wrappers/standalone.nix | 3 +-- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index d247ec6e91..b618d12fdc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -3,11 +3,10 @@ makeNixvimWithModule, pkgs, lib ? pkgs.lib, - _nixvimTests ? false, ... }@args: { # Add all exported modules here check = import ../tests/test-derivation.nix { inherit makeNixvimWithModule lib pkgs; }; - helpers = import ./helpers.nix (args // { inherit _nixvimTests; }); + helpers = import ./helpers.nix { inherit pkgs lib; }; } diff --git a/lib/helpers.nix b/lib/helpers.nix index 030ca87344..7783c0caa2 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -1,7 +1,6 @@ { pkgs, lib ? pkgs.lib, - _nixvimTests ? false, ... }: let @@ -24,7 +23,7 @@ let neovim-plugin = call ./neovim-plugin.nix { }; nixvimTypes = call ./types.nix { }; options = call ./options.nix { }; - utils = call ./utils.nix { inherit _nixvimTests; }; + utils = call ./utils.nix { }; vim-plugin = call ./vim-plugin.nix { }; # Top-level helper aliases: @@ -70,7 +69,6 @@ let inherit (helpers.utils) concatNonEmptyLines emptyTable - enableExceptInTests groupListBySize hasContent ifNonNull' @@ -94,6 +92,9 @@ let toLuaObject = helpers.lua.toLua; mkLuaInline = helpers.lua.mkInline; + + # TODO: Removed 2024-08-20 + enableExceptInTests = throw "enableExceptInTests has been removed, please use the `isTest` module option instead."; }; in helpers diff --git a/lib/utils.nix b/lib/utils.nix index 7c548f6861..78b64b94fe 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -1,8 +1,4 @@ -{ - lib, - helpers, - _nixvimTests, -}: +{ lib, helpers }: with lib; rec { # Whether a string contains something other than whitespaces @@ -16,8 +12,6 @@ rec { list: builtins.listToAttrs (lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list); - enableExceptInTests = !_nixvimTests; - emptyTable = { "__empty" = null; }; diff --git a/modules/misc/context.nix b/modules/misc/context.nix index 170372acbe..fd3cfa1a32 100644 --- a/modules/misc/context.nix +++ b/modules/misc/context.nix @@ -10,5 +10,14 @@ internal = true; visible = false; }; + isTest = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Whether modules are being evaluated to build a test. + ''; + internal = true; + visible = false; + }; }; } diff --git a/tests/enable-except-in-tests.nix b/tests/enable-except-in-tests.nix index 65070198c6..99136e5a54 100644 --- a/tests/enable-except-in-tests.nix +++ b/tests/enable-except-in-tests.nix @@ -5,9 +5,9 @@ }: let module = - { helpers, ... }: + { config, ... }: { - plugins.image.enable = helpers.enableExceptInTests; + plugins.image.enable = !config.isTest; }; inTest = mkTestDerivationFromNixvimModule { diff --git a/tests/test-derivation.nix b/tests/test-derivation.nix index 7e6d2836f7..9274e8a35d 100644 --- a/tests/test-derivation.nix +++ b/tests/test-derivation.nix @@ -16,7 +16,8 @@ let ... }@args: let - cfg = nvim.config.test; + result = nvim.extend { isTest = true; }; + cfg = result.config.test; runNvim = lib.warnIf (args ? dontRun) "mkTestDerivationFromNvim: the `dontRun` argument is deprecated. You should use the `test.runNvim` module option instead." @@ -26,7 +27,7 @@ let inherit name; nativeBuildInputs = [ - nvim + result pkgs.docker-client ]; @@ -65,7 +66,6 @@ let let nvim = makeNixvimWithModule { inherit pkgs extraSpecialArgs; - _nixvimTests = true; module = if args ? dontRun then lib.warn diff --git a/wrappers/standalone.nix b/wrappers/standalone.nix index 16cc2e806b..8a070076f5 100644 --- a/wrappers/standalone.nix +++ b/wrappers/standalone.nix @@ -3,11 +3,10 @@ default_pkgs: self: pkgs ? default_pkgs, lib ? pkgs.lib, extraSpecialArgs ? { }, - _nixvimTests ? false, module, }: let - helpers = import ../lib/helpers.nix { inherit pkgs lib _nixvimTests; }; + helpers = import ../lib/helpers.nix { inherit pkgs lib; }; inherit (helpers.modules) specialArgsWith;