mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
modules/test: check warnings/assertions
Warnings and assertions defined as `config.warnings` and `config.assertions` respectively will be checked as part of the test derivation, instead of when evaluating the modules. Adds new `checkWarnings` and `checkAssertions` test options (default true).
This commit is contained in:
parent
83c2844bec
commit
088e584e54
2 changed files with 52 additions and 11 deletions
|
@ -62,6 +62,9 @@ let
|
||||||
extraSpecialArgs = {
|
extraSpecialArgs = {
|
||||||
defaultPkgs = pkgs;
|
defaultPkgs = pkgs;
|
||||||
} // extraSpecialArgs;
|
} // extraSpecialArgs;
|
||||||
|
# Don't check assertions/warnings while evaluating nixvim config
|
||||||
|
# We'll let the test derivation handle that
|
||||||
|
check = false;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
result.config.test.derivation;
|
result.config.test.derivation;
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.test;
|
cfg = config.test;
|
||||||
|
|
||||||
|
inherit (config) warnings;
|
||||||
|
assertions = lib.nixvim.modules.getAssertionMessages config.assertions;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.test = {
|
options.test = {
|
||||||
|
@ -21,6 +24,18 @@ in
|
||||||
default = true;
|
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
|
# Output
|
||||||
derivation = lib.mkOption {
|
derivation = lib.mkOption {
|
||||||
type = lib.types.package;
|
type = lib.types.package;
|
||||||
|
@ -38,19 +53,42 @@ in
|
||||||
|
|
||||||
nativeBuildInputs = [ config.finalPackage ];
|
nativeBuildInputs = [ config.finalPackage ];
|
||||||
|
|
||||||
# We need to set HOME because neovim will try to create some files
|
# First check warnings/assertions, then run nvim
|
||||||
#
|
buildPhase =
|
||||||
# Because neovim does not return an exitcode when quitting we need to check if there are
|
let
|
||||||
# errors on stderr
|
showErr =
|
||||||
buildPhase = lib.optionalString cfg.runNvim ''
|
name: lines:
|
||||||
mkdir -p .cache/nvim
|
lib.optionalString (lines != [ ]) ''
|
||||||
|
Unexpected ${name}:
|
||||||
|
${lib.concatStringsSep "\n" (lib.map (v: "- ${v}") lines)}
|
||||||
|
'';
|
||||||
|
|
||||||
output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
|
toCheck =
|
||||||
if [[ -n $output ]]; then
|
lib.optionalAttrs cfg.checkWarnings { inherit warnings; }
|
||||||
echo "ERROR: $output"
|
// 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
|
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
|
# If we don't do this nix is not happy
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue