2023-03-22 07:42:02 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2024-02-09 15:03:32 +01:00
|
|
|
helpers,
|
2023-03-22 07:42:02 +01:00
|
|
|
}:
|
|
|
|
let
|
2024-08-28 01:32:04 +01:00
|
|
|
# Import a test file into the form { name = ""; file = ""; cases = {}; }
|
2024-08-22 13:46:05 +01:00
|
|
|
handleTestFile =
|
|
|
|
file: namespace:
|
2023-03-22 07:42:02 +01:00
|
|
|
let
|
2024-08-22 13:46:05 +01:00
|
|
|
fnOrAttrs = import file;
|
2024-08-28 01:32:04 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit file;
|
|
|
|
name = lib.strings.concatStringsSep "-" namespace;
|
2024-08-22 13:46:05 +01:00
|
|
|
cases =
|
|
|
|
if builtins.isFunction fnOrAttrs then
|
|
|
|
# Call the function
|
|
|
|
fnOrAttrs { inherit pkgs lib helpers; }
|
|
|
|
else
|
|
|
|
fnOrAttrs;
|
|
|
|
};
|
2023-03-22 07:42:02 +01:00
|
|
|
|
2024-08-22 13:46:05 +01:00
|
|
|
# Recurse into all directories, extracting files as we find them.
|
2024-08-28 01:32:04 +01:00
|
|
|
# This returns a list of { name; file; cases; } attrsets.
|
2024-08-22 13:46:05 +01:00
|
|
|
fetchTests =
|
2023-03-22 07:42:02 +01:00
|
|
|
path: namespace:
|
|
|
|
let
|
2024-08-22 13:46:05 +01:00
|
|
|
# Handle an entry from readDir
|
|
|
|
# - If it is a regular nix file, import its content
|
|
|
|
# - If it is a directory, continue recursively
|
|
|
|
handleEntry =
|
|
|
|
name: type:
|
|
|
|
let
|
2025-05-10 22:07:02 +03:00
|
|
|
file = /${path}/${name};
|
2024-08-22 13:46:05 +01:00
|
|
|
in
|
|
|
|
if type == "regular" then
|
|
|
|
lib.optional (lib.hasSuffix ".nix" name) (
|
2024-12-27 18:49:02 +00:00
|
|
|
handleTestFile file (
|
|
|
|
namespace ++ lib.optional (name != "default.nix") (lib.removeSuffix ".nix" name)
|
|
|
|
)
|
2024-08-22 13:46:05 +01:00
|
|
|
)
|
|
|
|
else
|
|
|
|
fetchTests file (namespace ++ [ name ]);
|
2023-03-22 07:42:02 +01:00
|
|
|
in
|
2024-08-22 13:46:05 +01:00
|
|
|
lib.pipe path [
|
|
|
|
builtins.readDir
|
|
|
|
(lib.filterAttrs (n: v: v != "symlink"))
|
|
|
|
(lib.mapAttrsToList handleEntry)
|
|
|
|
builtins.concatLists
|
|
|
|
];
|
2023-03-22 07:42:02 +01:00
|
|
|
in
|
2024-09-07 17:36:50 +01:00
|
|
|
root: fetchTests root [ ]
|