tests: move test derivations to tests/default.nix

Move the previous `default.nix` to `main.nix` so that `default.nix` can
be used for defining the set of all test derivations.

`main.nix` is imported by `default.nix`, but is only responsible for the
tests built from `tests/test-sources/`.
This commit is contained in:
Matt Sturgeon 2024-10-18 09:44:59 +01:00
parent 3c7b6ae5d1
commit 990ef039f7
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 129 additions and 105 deletions

66
tests/main.nix Normal file
View file

@ -0,0 +1,66 @@
# Collects the various test modules in tests/test-sources/ and groups them into a number of test derivations
{
lib ? pkgs.lib,
helpers,
pkgs,
pkgsUnfree,
}:
let
fetchTests = import ./fetch-tests.nix { inherit lib pkgs helpers; };
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
inherit (test-derivation) mkTestDerivationFromNixvimModule;
moduleToTest =
file: name: module:
mkTestDerivationFromNixvimModule {
inherit name;
module = {
_file = file;
imports = [ module ];
};
pkgs = pkgsUnfree;
};
# List of files containing configurations
testFiles = fetchTests ./test-sources;
exampleFiles = {
name = "examples";
file = ../example.nix;
cases =
let
config = import ../example.nix { inherit pkgs; };
in
{
main = 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"
];
};
};
in
# We attempt to build & execute all configurations
lib.pipe (testFiles ++ [ exampleFiles ]) [
(builtins.map (
{
name,
file,
cases,
}:
{
inherit name;
path = pkgs.linkFarm name (builtins.mapAttrs (moduleToTest file) cases);
}
))
(helpers.groupListBySize 10)
(lib.imap1 (
i: group: rec {
name = "test-${toString i}";
value = pkgs.linkFarm name group;
}
))
builtins.listToAttrs
]