From 7add68e918172ca58fc5b507377c5abc08c5fa78 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 19 Nov 2025 12:13:44 +0000 Subject: [PATCH] tests/enable-except-in-tests: refactor More explicitly assert that `enableExceptInTests` is the expected value. --- tests/enable-except-in-tests.nix | 58 +++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/tests/enable-except-in-tests.nix b/tests/enable-except-in-tests.nix index 721a161a..67eb74bb 100644 --- a/tests/enable-except-in-tests.nix +++ b/tests/enable-except-in-tests.nix @@ -1,4 +1,5 @@ { + lib, pkgs, linkFarm, runCommandLocal, @@ -6,30 +7,61 @@ makeNixvimWithModule, }: let - module = - { helpers, ... }: - { - plugins.image.enable = helpers.enableExceptInTests; - }; - inTest = mkTestDerivationFromNixvimModule { name = "enable-except-in-tests-test"; - inherit pkgs module; + inherit pkgs; + module = + { lib, helpers, ... }: + { + assertions = [ + { + # FIXME: should be false + assertion = lib.nixvim.enableExceptInTests; + message = "Expected lib.nixvim.enableExceptInTests to be true"; + } + { + assertion = !helpers.enableExceptInTests; + message = "Expected helpers.enableExceptInTests to be false"; + } + ]; + }; }; notInTest = let - nvim = makeNixvimWithModule { inherit pkgs module; }; + nvim = makeNixvimWithModule { + inherit pkgs; + module = + { lib, helpers, ... }: + { + assertions = [ + { + assertion = lib.nixvim.enableExceptInTests; + message = "Expected lib.nixvim.enableExceptInTests to be true"; + } + { + assertion = helpers.enableExceptInTests; + message = "Expected helpers.enableExceptInTests to be true"; + } + ]; + }; + }; in runCommandLocal "enable-except-in-tests-not-in-test" - { printConfig = "${nvim}/bin/nixvim-print-init"; } + { + __structuredAttrs = true; + assertions = lib.pipe nvim.config.assertions [ + (lib.filter (x: !x.assertion)) + (lib.map (x: x.message)) + ]; + } '' - if ! "$printConfig" | grep 'require("image").setup'; then - echo "image.nvim is not present in the configuration" - echo -e "configuration:\n$($printConfig)" + if (( ''${#assertions[@]} )); then + for assertion in "''${assertions[@]}"; do + echo "- $assertion" + done exit 1 fi - touch $out ''; in