nix-community.nixvim/tests/test-derivation.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
2.8 KiB
Nix
Raw Normal View History

{
pkgs,
lib ? pkgs.lib,
makeNixvimWithModule,
...
}:
2023-03-22 07:42:02 +01:00
let
# Create a nix derivation from a nixvim executable.
# The build phase simply consists in running the provided nvim binary.
mkTestDerivationFromNvim =
{
name,
nvim ? null,
tests ? [ ],
dontRun ? false,
...
}:
# At least one of these should be undefined
assert lib.assertMsg (tests == [ ] || nvim == null) "Both nvim & tests can't be supplied";
let
nvimAsList = lib.optional (nvim != null) {
derivation = nvim;
inherit name dontRun;
};
testList = tests ++ nvimAsList;
in
pkgs.stdenv.mkDerivation {
2023-05-22 15:45:47 +05:30
inherit name;
nativeBuildInputs = [ pkgs.docker-client ];
dontUnpack = true;
# 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 (!dontRun) (
''
mkdir -p .cache/nvim
''
+ lib.concatStringsSep "\n" (
builtins.map (
{
derivation,
name,
dontRun ? false,
}:
lib.optionalString (!dontRun) ''
echo "Running test for ${name}"
output=$(HOME=$(realpath .) ${lib.getExe derivation} -mn --headless "+q" 2>&1 >/dev/null)
if [[ -n $output ]]; then
echo "ERROR: $output"
exit 1
fi
''
) testList
)
);
# If we don't do this nix is not happy
installPhase = ''
mkdir $out
'';
};
2023-03-22 07:42:02 +01:00
# Create a nix derivation from a nixvim configuration.
# The build phase simply consists in running neovim with the given configuration.
mkTestDerivationFromNixvimModule =
{
name ? "nixvim-check",
pkgs ? pkgs,
module ? null,
tests ? [ ],
extraSpecialArgs ? { },
dontRun ? false,
}:
# At least one of these should be undefined
assert lib.assertMsg (tests == [ ] || module == null) "Both module & tests can't be supplied";
let
moduleAsList = lib.optional (module != null) { inherit module name; };
moduleList = tests ++ moduleAsList;
testDerivations = builtins.map (
{
module,
name,
dontRun ? false,
}:
{
derivation = makeNixvimWithModule {
inherit pkgs module extraSpecialArgs;
_nixvimTests = true;
};
inherit name dontRun;
}
) moduleList;
in
mkTestDerivationFromNvim {
inherit name dontRun;
tests = testDerivations;
};
in
{
inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
}