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; };
|
test-derivation = import ../lib/tests.nix { inherit pkgs lib; };
|
||||||
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
inherit (test-derivation) mkTestDerivationFromNixvimModule;
|
||||||
|
|
||||||
|
mkTest =
|
||||||
|
{ name, module }:
|
||||||
|
{
|
||||||
|
inherit name;
|
||||||
|
path = mkTestDerivationFromNixvimModule {
|
||||||
|
inherit name module;
|
||||||
|
pkgs = pkgsUnfree;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# List of files containing configurations
|
# List of files containing configurations
|
||||||
testFiles = fetchTests {
|
testFiles = fetchTests {
|
||||||
inherit lib pkgs helpers;
|
inherit lib pkgs helpers;
|
||||||
|
@ -17,7 +27,7 @@ let
|
||||||
|
|
||||||
exampleFiles = {
|
exampleFiles = {
|
||||||
name = "examples";
|
name = "examples";
|
||||||
cases =
|
modules =
|
||||||
let
|
let
|
||||||
config = import ../example.nix { inherit pkgs; };
|
config = import ../example.nix { inherit pkgs; };
|
||||||
in
|
in
|
||||||
|
@ -37,24 +47,10 @@ let
|
||||||
in
|
in
|
||||||
# We attempt to build & execute all configurations
|
# We attempt to build & execute all configurations
|
||||||
lib.pipe (testFiles ++ [ exampleFiles ]) [
|
lib.pipe (testFiles ++ [ exampleFiles ]) [
|
||||||
(builtins.map (
|
(builtins.map (file: {
|
||||||
file:
|
|
||||||
let
|
|
||||||
mkTest =
|
|
||||||
{ name, module }:
|
|
||||||
{
|
|
||||||
inherit name;
|
|
||||||
path = mkTestDerivationFromNixvimModule {
|
|
||||||
inherit name module;
|
|
||||||
pkgs = pkgsUnfree;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit (file) name;
|
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)
|
(helpers.groupListBySize 10)
|
||||||
(lib.imap1 (
|
(lib.imap1 (
|
||||||
i: group: rec {
|
i: group: rec {
|
||||||
|
|
|
@ -5,54 +5,50 @@
|
||||||
helpers,
|
helpers,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
# Handle an entry from readDir and either extract the configuration if its a regular file,
|
# Import a test file into the form { name = ""; file = ""; modules = []; }
|
||||||
# or continue to recurse if it's a directory. While recursing maintain a list of the traversed
|
handleTestFile =
|
||||||
# directories
|
file: namespace:
|
||||||
handleEntry =
|
|
||||||
relativePath: namespace: name: type:
|
|
||||||
let
|
let
|
||||||
file = "${root}/${relativePath}/${name}";
|
fnOrAttrs = import file;
|
||||||
in
|
cases =
|
||||||
if type == "regular" then
|
if builtins.isFunction fnOrAttrs then
|
||||||
lib.optional (lib.hasSuffix ".nix" name) [
|
# Call the function
|
||||||
{
|
fnOrAttrs { inherit pkgs lib helpers; }
|
||||||
namespace = namespace ++ [ (lib.strings.removeSuffix ".nix" name) ];
|
|
||||||
cases = import file;
|
|
||||||
}
|
|
||||||
]
|
|
||||||
else
|
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
|
# Recurse into all directories, extracting files as we find them.
|
||||||
# list, where each non list element is a set of test cases.
|
# This returns a list of { name; file; modules; } attrsets.
|
||||||
parseDirectories =
|
fetchTests =
|
||||||
path: namespace:
|
path: namespace:
|
||||||
let
|
let
|
||||||
relativePath = lib.removePrefix "${root}" "${path}";
|
# Handle an entry from readDir
|
||||||
|
# - If it is a regular nix file, import its content
|
||||||
children = builtins.readDir path;
|
# - If it is a directory, continue recursively
|
||||||
childrenFiltered = lib.attrsets.filterAttrs (n: v: v != "symlink") children;
|
handleEntry =
|
||||||
|
name: type:
|
||||||
childrenRecursed = lib.attrsets.mapAttrsToList (handleEntry relativePath namespace) childrenFiltered;
|
let
|
||||||
|
file = "${path}/${name}";
|
||||||
in
|
in
|
||||||
childrenRecursed;
|
if type == "regular" then
|
||||||
|
lib.optional (lib.hasSuffix ".nix" name) (
|
||||||
# Remove the nesting
|
handleTestFile file (namespace ++ [ (lib.removeSuffix ".nix" name) ])
|
||||||
testsList = lib.lists.flatten (parseDirectories root [ ]);
|
)
|
||||||
|
else
|
||||||
testsListEvaluated = builtins.map (
|
fetchTests file (namespace ++ [ name ]);
|
||||||
{ cases, ... }@args:
|
in
|
||||||
if builtins.isFunction cases then args // { cases = cases { inherit pkgs lib helpers; }; } else args
|
lib.pipe path [
|
||||||
) testsList;
|
builtins.readDir
|
||||||
|
(lib.filterAttrs (n: v: v != "symlink"))
|
||||||
# Take a list of test cases (i.e the content of a file) and prepare a test case that can be
|
(lib.mapAttrsToList handleEntry)
|
||||||
# handled by mkTestDerivation
|
builtins.concatLists
|
||||||
handleTestFile =
|
];
|
||||||
{ namespace, cases }:
|
|
||||||
{
|
|
||||||
name = lib.strings.concatStringsSep "-" namespace;
|
|
||||||
cases = lib.mapAttrsToList (name: module: { inherit module name; }) cases;
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
# A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ]
|
# A list of the form [ { name = "..."; modules = [ /* test case modules */ ]; } ]
|
||||||
builtins.map handleTestFile testsListEvaluated
|
fetchTests root [ ]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue