2023-03-22 07:42:02 +01:00
|
|
|
{
|
|
|
|
root,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2024-02-09 15:03:32 +01:00
|
|
|
helpers,
|
2023-03-22 07:42:02 +01:00
|
|
|
}: let
|
|
|
|
# Handle an entry from readDir and either extract the configuration if its a regular file,
|
|
|
|
# or continue to recurse if it's a directory. While recursing maintain a list of the traversed
|
|
|
|
# directories
|
|
|
|
handleEntry = relativePath: namespace: name: type: let
|
|
|
|
file = "${root}/${relativePath}/${name}";
|
|
|
|
in
|
|
|
|
if type == "regular"
|
|
|
|
then [
|
|
|
|
{
|
|
|
|
namespace = namespace ++ [(lib.strings.removeSuffix ".nix" name)];
|
|
|
|
cases = import file;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
else parseDirectories file (namespace ++ [name]);
|
|
|
|
|
2024-03-07 19:44:13 +01:00
|
|
|
# Recurse into all directories, extracting files as we find them. This returns a deeply nested
|
2023-03-22 07:42:02 +01:00
|
|
|
# list, where each non list element is a set of test cases.
|
|
|
|
parseDirectories = path: namespace: let
|
|
|
|
relativePath = lib.removePrefix "${root}" "${path}";
|
|
|
|
|
|
|
|
children = builtins.readDir path;
|
|
|
|
childrenFiltered =
|
|
|
|
lib.attrsets.filterAttrs (n: v: v != "symlink") children;
|
|
|
|
|
|
|
|
childrenRecursed =
|
|
|
|
lib.attrsets.mapAttrsToList (handleEntry relativePath namespace) childrenFiltered;
|
|
|
|
in
|
|
|
|
childrenRecursed;
|
|
|
|
|
|
|
|
# Remove the nesting
|
|
|
|
testsList = lib.lists.flatten (parseDirectories root []);
|
|
|
|
|
|
|
|
testsListEvaluated = builtins.map ({
|
|
|
|
cases,
|
|
|
|
namespace,
|
|
|
|
} @ args:
|
|
|
|
if builtins.isAttrs cases
|
|
|
|
then args
|
|
|
|
else {
|
2023-09-27 10:43:23 +02:00
|
|
|
# cases is a function
|
2023-11-17 12:17:13 +01:00
|
|
|
cases = cases {
|
|
|
|
inherit pkgs helpers;
|
|
|
|
efmls-options = import ../plugins/lsp/language-servers/efmls-configs.nix {
|
|
|
|
inherit pkgs lib helpers;
|
|
|
|
config = {};
|
|
|
|
};
|
2024-03-01 13:24:14 +01:00
|
|
|
nonels-sources-options = import ../plugins/none-ls/servers.nix {
|
|
|
|
inherit pkgs lib helpers;
|
|
|
|
config = {};
|
|
|
|
};
|
2023-11-17 12:17:13 +01:00
|
|
|
};
|
2023-03-22 07:42:02 +01:00
|
|
|
inherit namespace;
|
|
|
|
})
|
|
|
|
testsList;
|
|
|
|
|
|
|
|
# Take a list of test cases (i.e the content of a file) and prepare a test case that can be
|
|
|
|
# handled by mkTestDerivation
|
|
|
|
handleTestFile = {
|
|
|
|
namespace,
|
|
|
|
cases,
|
|
|
|
}:
|
|
|
|
lib.attrsets.mapAttrs' (case: config: {
|
|
|
|
name = lib.strings.concatStringsSep "-" (namespace ++ [case]);
|
|
|
|
value = config;
|
|
|
|
})
|
|
|
|
cases;
|
|
|
|
|
|
|
|
# Helper function that calls `//` for each attrset of a list
|
2023-05-22 15:45:47 +05:30
|
|
|
concatMany = lib.lists.foldr lib.mergeAttrs {};
|
2023-03-22 07:42:02 +01:00
|
|
|
# An attrset of 'test-name' -> 'test-config'
|
|
|
|
in
|
|
|
|
concatMany (builtins.map handleTestFile testsListEvaluated)
|