mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
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.
This commit is contained in:
parent
049bbc168f
commit
10f64e6c96
4 changed files with 28 additions and 47 deletions
|
@ -3,25 +3,21 @@
|
||||||
perSystem =
|
perSystem =
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
config,
|
pkgsUnfree,
|
||||||
system,
|
system,
|
||||||
helpers,
|
helpers,
|
||||||
makeNixvimWithModuleUnfree,
|
|
||||||
makeNixvimWithModule,
|
makeNixvimWithModule,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
checks = {
|
checks = {
|
||||||
tests = import ../tests {
|
tests = import ../tests {
|
||||||
inherit pkgs helpers makeNixvimWithModule;
|
inherit
|
||||||
inherit (pkgs) lib;
|
pkgs
|
||||||
makeNixvim =
|
pkgsUnfree
|
||||||
configuration:
|
helpers
|
||||||
makeNixvimWithModuleUnfree {
|
makeNixvimWithModule
|
||||||
module = {
|
;
|
||||||
config = configuration;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extra-args-tests = import ../tests/extra-args.nix {
|
extra-args-tests = import ../tests/extra-args.nix {
|
||||||
|
|
|
@ -14,18 +14,10 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{
|
{ system, pkgs, ... }:
|
||||||
system,
|
|
||||||
pkgs,
|
|
||||||
pkgsUnfree,
|
|
||||||
config,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
{
|
||||||
_module.args = {
|
_module.args = {
|
||||||
makeNixvimWithModule = import ../wrappers/standalone.nix pkgs wrapperArgs;
|
makeNixvimWithModule = import ../wrappers/standalone.nix pkgs wrapperArgs;
|
||||||
|
|
||||||
makeNixvimWithModuleUnfree = import ../wrappers/standalone.nix pkgsUnfree wrapperArgs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
checks =
|
checks =
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
{
|
{
|
||||||
makeNixvim,
|
|
||||||
makeNixvimWithModule,
|
makeNixvimWithModule,
|
||||||
lib,
|
lib ? pkgs.lib,
|
||||||
helpers,
|
helpers,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
pkgsUnfree,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
fetchTests = import ./fetch-tests.nix;
|
fetchTests = import ./fetch-tests.nix;
|
||||||
test-derivation = import ./test-derivation.nix { inherit pkgs makeNixvim makeNixvimWithModule; };
|
test-derivation = import ./test-derivation.nix { inherit pkgs makeNixvimWithModule; };
|
||||||
inherit (test-derivation) mkTestDerivation;
|
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
||||||
|
|
||||||
# List of files containing configurations
|
# List of files containing configurations
|
||||||
testFiles = fetchTests {
|
testFiles = fetchTests {
|
||||||
|
@ -31,9 +31,16 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
# We attempt to build & execute all configurations
|
# We attempt to build & execute all configurations
|
||||||
derivationList = pkgs.lib.mapAttrsToList (name: path: {
|
derivationList = pkgs.lib.mapAttrsToList (name: def: {
|
||||||
inherit name;
|
inherit name;
|
||||||
path = mkTestDerivation name path;
|
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);
|
}) (testFiles // exampleFiles);
|
||||||
in
|
in
|
||||||
pkgs.linkFarm "nixvim-tests" derivationList
|
pkgs.linkFarm "nixvim-tests" derivationList
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
{
|
{ pkgs, makeNixvimWithModule, ... }:
|
||||||
pkgs,
|
|
||||||
makeNixvim,
|
|
||||||
makeNixvimWithModule,
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
# Create a nix derivation from a nixvim executable.
|
# Create a nix derivation from a nixvim executable.
|
||||||
# The build phase simply consists in running the provided nvim binary.
|
# The build phase simply consists in running the provided nvim binary.
|
||||||
|
@ -46,12 +42,15 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Create a nix derivation from a nixvim configuration.
|
||||||
|
# The build phase simply consists in running neovim with the given configuration.
|
||||||
mkTestDerivationFromNixvimModule =
|
mkTestDerivationFromNixvimModule =
|
||||||
{
|
{
|
||||||
name ? "nixvim-check",
|
name ? "nixvim-check",
|
||||||
pkgs,
|
pkgs ? pkgs,
|
||||||
module,
|
module,
|
||||||
extraSpecialArgs ? { },
|
extraSpecialArgs ? { },
|
||||||
|
dontRun ? false,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
nvim = makeNixvimWithModule {
|
nvim = makeNixvimWithModule {
|
||||||
|
@ -59,21 +58,8 @@ let
|
||||||
_nixvimTests = true;
|
_nixvimTests = true;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
mkTestDerivationFromNvim { inherit name nvim; };
|
mkTestDerivationFromNvim { inherit name nvim dontRun; };
|
||||||
|
|
||||||
# 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
|
in
|
||||||
{
|
{
|
||||||
inherit mkTestDerivation mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
|
inherit mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue