diff --git a/lib/tests.nix b/lib/tests.nix index 8face09091..182c79d724 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -62,6 +62,9 @@ let extraSpecialArgs = { defaultPkgs = pkgs; } // extraSpecialArgs; + # Don't check assertions/warnings while evaluating nixvim config + # We'll let the test derivation handle that + check = false; }; in result.config.test.derivation; diff --git a/modules/top-level/test.nix b/modules/top-level/test.nix index 2e430dc3e6..547dc0754b 100644 --- a/modules/top-level/test.nix +++ b/modules/top-level/test.nix @@ -6,6 +6,9 @@ }: let cfg = config.test; + + inherit (config) warnings; + assertions = lib.nixvim.modules.getAssertionMessages config.assertions; in { options.test = { @@ -21,6 +24,18 @@ in default = true; }; + checkWarnings = lib.mkOption { + type = lib.types.bool; + description = "Whether to check `config.warnings` in the test."; + default = true; + }; + + checkAssertions = lib.mkOption { + type = lib.types.bool; + description = "Whether to check `config.assertions` in the test."; + default = true; + }; + # Output derivation = lib.mkOption { type = lib.types.package; @@ -38,19 +53,42 @@ in nativeBuildInputs = [ config.finalPackage ]; - # We need to set HOME because neovim will try to create some files - # - # Because neovim does not return an exitcode when quitting we need to check if there are - # errors on stderr - buildPhase = lib.optionalString cfg.runNvim '' - mkdir -p .cache/nvim + # First check warnings/assertions, then run nvim + buildPhase = + let + showErr = + name: lines: + lib.optionalString (lines != [ ]) '' + Unexpected ${name}: + ${lib.concatStringsSep "\n" (lib.map (v: "- ${v}") lines)} + ''; - output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null) - if [[ -n $output ]]; then - echo "ERROR: $output" + toCheck = + lib.optionalAttrs cfg.checkWarnings { inherit warnings; } + // lib.optionalAttrs cfg.checkAssertions { inherit assertions; }; + + errors = lib.foldlAttrs ( + err: name: lines: + err + showErr name lines + ) "" toCheck; + in + lib.optionalString (errors != "") '' + echo -n ${lib.escapeShellArg errors} exit 1 - fi - ''; + '' + # We need to set HOME because neovim will try to create some files + # + # Because neovim does not return an exitcode when quitting we need to check if there are + # errors on stderr + + lib.optionalString cfg.runNvim '' + mkdir -p .cache/nvim + + output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null) + if [[ -n $output ]]; then + echo "ERROR: $output" + exit 1 + fi + ''; # If we don't do this nix is not happy installPhase = ''