nix-community.nixvim/tests/default.nix
Matt Sturgeon 10f64e6c96
tests/test-derivation: allow tests to be modules
Use `mkTestDerivationFromNixvimModule` instead of `mkTestDerivation`,
allowing "proper" modules to be used instead of plain attr configs.

This is useful for more complex tests that wish to use `config` or
`options` arguments, e.g:

```nix
{config, options, ...}: {
  /* some cool test */
}
```

To allow `tests.dontRun` to be defined on such a test, the module is
allowed to be nested as `module`, e.g:

```nix
{
  tests.dontRun = true;
  module = {config, options, ...}: {
    /* a disabled test */
  };
}
```

Also ended up doing some general cleanup, removing an unused function,
etc.
2024-06-29 22:02:44 +01:00

46 lines
1.3 KiB
Nix

{
makeNixvimWithModule,
lib ? pkgs.lib,
helpers,
pkgs,
pkgsUnfree,
}:
let
fetchTests = import ./fetch-tests.nix;
test-derivation = import ./test-derivation.nix { inherit pkgs makeNixvimWithModule; };
inherit (test-derivation) mkTestDerivationFromNixvimModule;
# List of files containing configurations
testFiles = fetchTests {
inherit lib pkgs helpers;
root = ./test-sources;
};
exampleFiles = {
example =
let
config = import ../example.nix { inherit pkgs; };
in
builtins.removeAttrs config.programs.nixvim [
# This is not available to standalone modules, only HM & NixOS Modules
"enable"
# This is purely an example, it does not reflect a real usage
"extraConfigLua"
"extraConfigVim"
];
};
# We attempt to build & execute all configurations
derivationList = pkgs.lib.mapAttrsToList (name: def: {
inherit name;
path = mkTestDerivationFromNixvimModule {
inherit name;
# The module can either be the actual definition,
# or a child attr named `module`.
module = def.module or lib.removeAttrs def [ "tests" ];
dontRun = def.tests.dontRun or false;
pkgs = pkgsUnfree;
};
}) (testFiles // exampleFiles);
in
pkgs.linkFarm "nixvim-tests" derivationList