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

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

80 lines
1.9 KiB
Nix
Raw Normal View History

2023-03-22 07:42:02 +01:00
{
pkgs,
makeNixvim,
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,
dontRun ? false,
...
}:
pkgs.stdenv.mkDerivation {
2023-05-22 15:45:47 +05:30
inherit name;
nativeBuildInputs = [
nvim
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 =
if !dontRun then
''
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
''
else
'''';
# If we don't do this nix is not happy
installPhase = ''
mkdir $out
'';
};
2023-03-22 07:42:02 +01:00
mkTestDerivationFromNixvimModule =
{
name ? "nixvim-check",
pkgs,
module,
extraSpecialArgs ? { },
}:
let
nvim = makeNixvimWithModule {
inherit pkgs module extraSpecialArgs;
_nixvimTests = true;
};
in
mkTestDerivationFromNvim { inherit name nvim; };
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.
mkTestDerivation =
name: config:
let
testAttributes = if builtins.hasAttr "tests" config then config.tests else { dontRun = false; };
nvim = makeNixvim (pkgs.lib.attrsets.filterAttrs (n: _: n != "tests") config);
in
mkTestDerivationFromNvim {
inherit name nvim;
inherit (testAttributes) dontRun;
};
in
{
inherit mkTestDerivation mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
}