diff --git a/tests/default.nix b/tests/default.nix index 015f9572..2fafe55f 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -7,7 +7,7 @@ }: let fetchTests = import ./fetch-tests.nix; - test-derivation = import ./test-derivation.nix { inherit pkgs makeNixvimWithModule lib; }; + test-derivation = import ./test-derivation.nix { inherit pkgs makeNixvimWithModule; }; inherit (test-derivation) mkTestDerivationFromNixvimModule; # List of files containing configurations diff --git a/tests/test-derivation.nix b/tests/test-derivation.nix index cd95b576..9c5355ee 100644 --- a/tests/test-derivation.nix +++ b/tests/test-derivation.nix @@ -1,63 +1,40 @@ -{ - pkgs, - lib ? pkgs.lib, - makeNixvimWithModule, - ... -}: +{ pkgs, makeNixvimWithModule, ... }: 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 ? [ ], + nvim, 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 { inherit name; - nativeBuildInputs = [ pkgs.docker-client ]; + 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 = lib.optionalString (!dontRun) ( - '' - mkdir -p .cache/nvim - '' - + lib.concatStringsSep "\n" ( - builtins.map ( - { - derivation, - name, - dontRun ? false, - }: - lib.optionalString (!dontRun) '' - echo "Running test for ${name}" + buildPhase = + if !dontRun then + '' + mkdir -p .cache/nvim - output=$(HOME=$(realpath .) ${lib.getExe derivation} -mn --headless "+q" 2>&1 >/dev/null) - if [[ -n $output ]]; then - echo "ERROR: $output" - exit 1 - fi - '' - ) testList - ) - ); + 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 = '' @@ -71,35 +48,17 @@ let { name ? "nixvim-check", pkgs ? pkgs, - module ? null, - tests ? [ ], + module, 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; + nvim = makeNixvimWithModule { + inherit pkgs module extraSpecialArgs; + _nixvimTests = true; + }; in - mkTestDerivationFromNvim { - inherit name dontRun; - tests = testDerivations; - }; + mkTestDerivationFromNvim { inherit name nvim dontRun; }; in { inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;