Skip to content

Commit

Permalink
tests: simplify fetch-tests slightly
Browse files Browse the repository at this point in the history
Simplify by reducing the number of transformations done to the
test-files' test-case modules attr.

Since `pkgs.linkFarm` can accept _either_ a list or an attrset, we don't
need to transform the attrset into a list.
  • Loading branch information
MattSturgeon committed Aug 28, 2024
1 parent 1c879ec commit 975af6a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
39 changes: 17 additions & 22 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ let
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
inherit (test-derivation) mkTestDerivationFromNixvimModule;

mkTest =
{ name, module }:
{
inherit name;
path = mkTestDerivationFromNixvimModule {
inherit name module;
pkgs = pkgsUnfree;
};
moduleToTest =
name: module:
mkTestDerivationFromNixvimModule {
inherit name module;
pkgs = pkgsUnfree;
};

# List of files containing configurations
Expand All @@ -27,29 +24,27 @@ let

exampleFiles = {
name = "examples";
modules =
file = ../example.nix;
cases =
let
config = import ../example.nix { inherit pkgs; };
in
[
{
name = "main";
module = 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"
];
}
];
{
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 (file: {
inherit (file) name;
path = pkgs.linkFarm file.name (builtins.map mkTest file.modules);
path = pkgs.linkFarm file.name (builtins.mapAttrs moduleToTest file.cases);
}))
(helpers.groupListBySize 10)
(lib.imap1 (
Expand Down
14 changes: 6 additions & 8 deletions tests/fetch-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
helpers,
}:
let
# Import a test file into the form { name = ""; file = ""; modules = []; }
# Import a test file into the form { name = ""; file = ""; cases = {}; }
handleTestFile =
file: namespace:
let
fnOrAttrs = import file;
in
{
inherit file;
name = lib.strings.concatStringsSep "-" namespace;
cases =
if builtins.isFunction fnOrAttrs then
# Call the function
fnOrAttrs { inherit pkgs lib helpers; }
else
fnOrAttrs;
in
{
inherit file;
name = lib.strings.concatStringsSep "-" namespace;
modules = lib.mapAttrsToList (name: module: { inherit name module; }) cases;
};

# Recurse into all directories, extracting files as we find them.
# This returns a list of { name; file; modules; } attrsets.
# This returns a list of { name; file; cases; } attrsets.
fetchTests =
path: namespace:
let
Expand All @@ -50,5 +49,4 @@ let
builtins.concatLists
];
in
# A list of the form [ { name = "..."; modules = [ /* test case modules */ ]; } ]
fetchTests root [ ]

0 comments on commit 975af6a

Please sign in to comment.