mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
tests: general cleanup
- Refactor much of `tests/fetch-tests.nix` - Move `mkTest` up to let-block in `tests/default.nix`
This commit is contained in:
parent
087f70cb0a
commit
fe12a092f6
2 changed files with 55 additions and 63 deletions
|
@ -9,6 +9,16 @@ 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;
|
||||
};
|
||||
};
|
||||
|
||||
# List of files containing configurations
|
||||
testFiles = fetchTests {
|
||||
inherit lib pkgs helpers;
|
||||
|
@ -17,7 +27,7 @@ let
|
|||
|
||||
exampleFiles = {
|
||||
name = "examples";
|
||||
cases =
|
||||
modules =
|
||||
let
|
||||
config = import ../example.nix { inherit pkgs; };
|
||||
in
|
||||
|
@ -37,24 +47,10 @@ let
|
|||
in
|
||||
# We attempt to build & execute all configurations
|
||||
lib.pipe (testFiles ++ [ exampleFiles ]) [
|
||||
(builtins.map (
|
||||
file:
|
||||
let
|
||||
mkTest =
|
||||
{ name, module }:
|
||||
{
|
||||
inherit name;
|
||||
path = mkTestDerivationFromNixvimModule {
|
||||
inherit name module;
|
||||
pkgs = pkgsUnfree;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
(builtins.map (file: {
|
||||
inherit (file) name;
|
||||
path = pkgs.linkFarm file.name (builtins.map mkTest file.cases);
|
||||
}
|
||||
))
|
||||
path = pkgs.linkFarm file.name (builtins.map mkTest file.modules);
|
||||
}))
|
||||
(helpers.groupListBySize 10)
|
||||
(lib.imap1 (
|
||||
i: group: rec {
|
||||
|
|
|
@ -5,54 +5,50 @@
|
|||
helpers,
|
||||
}:
|
||||
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:
|
||||
# Import a test file into the form { name = ""; file = ""; modules = []; }
|
||||
handleTestFile =
|
||||
file: namespace:
|
||||
let
|
||||
file = "${root}/${relativePath}/${name}";
|
||||
in
|
||||
if type == "regular" then
|
||||
lib.optional (lib.hasSuffix ".nix" name) [
|
||||
{
|
||||
namespace = namespace ++ [ (lib.strings.removeSuffix ".nix" name) ];
|
||||
cases = import file;
|
||||
}
|
||||
]
|
||||
fnOrAttrs = import file;
|
||||
cases =
|
||||
if builtins.isFunction fnOrAttrs then
|
||||
# Call the function
|
||||
fnOrAttrs { inherit pkgs lib helpers; }
|
||||
else
|
||||
parseDirectories file (namespace ++ [ name ]);
|
||||
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 deeply nested
|
||||
# list, where each non list element is a set of test cases.
|
||||
parseDirectories =
|
||||
# Recurse into all directories, extracting files as we find them.
|
||||
# This returns a list of { name; file; modules; } attrsets.
|
||||
fetchTests =
|
||||
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;
|
||||
# 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
|
||||
file = "${path}/${name}";
|
||||
in
|
||||
childrenRecursed;
|
||||
|
||||
# Remove the nesting
|
||||
testsList = lib.lists.flatten (parseDirectories root [ ]);
|
||||
|
||||
testsListEvaluated = builtins.map (
|
||||
{ cases, ... }@args:
|
||||
if builtins.isFunction cases then args // { cases = cases { inherit pkgs lib helpers; }; } else args
|
||||
) 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 }:
|
||||
{
|
||||
name = lib.strings.concatStringsSep "-" namespace;
|
||||
cases = lib.mapAttrsToList (name: module: { inherit module name; }) cases;
|
||||
};
|
||||
if type == "regular" then
|
||||
lib.optional (lib.hasSuffix ".nix" name) (
|
||||
handleTestFile file (namespace ++ [ (lib.removeSuffix ".nix" name) ])
|
||||
)
|
||||
else
|
||||
fetchTests file (namespace ++ [ name ]);
|
||||
in
|
||||
# A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ]
|
||||
builtins.map handleTestFile testsListEvaluated
|
||||
lib.pipe path [
|
||||
builtins.readDir
|
||||
(lib.filterAttrs (n: v: v != "symlink"))
|
||||
(lib.mapAttrsToList handleEntry)
|
||||
builtins.concatLists
|
||||
];
|
||||
in
|
||||
# A list of the form [ { name = "..."; modules = [ /* test case modules */ ]; } ]
|
||||
fetchTests root [ ]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue