2024-08-05 12:21:24 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.test;
|
2024-08-05 14:25:44 +01:00
|
|
|
|
|
|
|
inherit (config) warnings;
|
|
|
|
assertions = lib.nixvim.modules.getAssertionMessages config.assertions;
|
2024-08-05 12:21:24 +01:00
|
|
|
in
|
2024-08-20 00:30:16 +01:00
|
|
|
{
|
|
|
|
options.test = {
|
2024-08-05 12:21:24 +01:00
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "nixvim-check";
|
|
|
|
description = "The test derivation's name.";
|
|
|
|
};
|
|
|
|
|
2024-08-20 00:30:16 +01:00
|
|
|
runNvim = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
description = "Whether to run `nvim` in the test.";
|
|
|
|
default = true;
|
|
|
|
};
|
2024-08-05 12:21:24 +01:00
|
|
|
|
2024-08-05 14:25:44 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2024-08-05 12:21:24 +01:00
|
|
|
# Output
|
|
|
|
derivation = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
description = ''
|
|
|
|
A derivation that tests the config by running neovim.
|
|
|
|
'';
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-24 20:03:04 +01:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
showErr =
|
|
|
|
name: lines:
|
|
|
|
lib.optionalString (lines != [ ]) ''
|
|
|
|
Unexpected ${name}:
|
|
|
|
${lib.concatStringsSep "\n" (lib.map (v: "- ${v}") lines)}
|
|
|
|
'';
|
2024-08-05 12:21:24 +01:00
|
|
|
|
2024-08-24 20:03:04 +01:00
|
|
|
toCheck =
|
|
|
|
lib.optionalAttrs cfg.checkWarnings { inherit warnings; }
|
|
|
|
// lib.optionalAttrs cfg.checkAssertions { inherit assertions; };
|
2024-08-05 14:25:44 +01:00
|
|
|
|
2024-08-24 20:03:04 +01:00
|
|
|
errors = lib.foldlAttrs (
|
|
|
|
err: name: lines:
|
|
|
|
err + showErr name lines
|
|
|
|
) "" toCheck;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
test.derivation =
|
|
|
|
pkgs.runCommandNoCCLocal cfg.name { nativeBuildInputs = [ config.finalPackage ]; }
|
|
|
|
(
|
|
|
|
# First check warnings/assertions, then run nvim
|
|
|
|
lib.optionalString (errors != "") ''
|
|
|
|
echo -n ${lib.escapeShellArg errors}
|
|
|
|
exit 1
|
|
|
|
''
|
|
|
|
# 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
|
2024-08-05 14:25:44 +01:00
|
|
|
|
2024-08-24 20:03:04 +01:00
|
|
|
output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
|
|
|
|
if [[ -n $output ]]; then
|
|
|
|
echo "ERROR: $output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
''
|
|
|
|
+ ''
|
|
|
|
touch $out
|
|
|
|
''
|
|
|
|
);
|
2024-08-05 12:21:24 +01:00
|
|
|
};
|
2024-08-20 00:30:16 +01:00
|
|
|
}
|