nix-community.nixvim/tests/fetch-tests.nix
Stanislav Asunkin 44849233e0 modules/performance: add ability to byte compile lua configuration files
This commit adds support for byte compiling lua configuration files.
It's enabled by default (if byte compiling is enabled at all) and can be
disabled with `performance.byteCompileLua.configs` toggle.

To implement this feature `extraFiles.<name>.finalSource` internal
read-only option is introduced. `source` option cannot be used because
it's user configurable. In order to access the values of the
`performance.byteCompileLua` options, parent config is added to
specialArgs of extraFiles submodule. Then the usages of `source` option
changed to `finalSource` in all relevant places (filesPlugin and
wrappers).

Added more helpers for various cases of byte compiling:

* `byteCompileLuaFile` byte compiles lua file
* `byteCompileLuaHook` is a setup hook that byte compiles all lua files
* `byteCompileLuaDrv` overrides derivation by adding byteCompileLuaHook
  to it

Added tests to validate that extraFiles specified by various methods are
handled correctly. Added a separate home-manager test, that is intended
to validate that extraFiles propagated to wrapper modules are correctly
byte compiled.
2024-07-31 11:31:40 +00:00

71 lines
2.1 KiB
Nix

{
root,
lib,
pkgs,
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:
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;
}
]
else
parseDirectories file (namespace ++ [ name ]);
# 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 =
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
{
# cases is a function
cases = cases {
inherit pkgs helpers;
efmls-options = import ../plugins/lsp/language-servers/efmls-configs.nix {
inherit pkgs lib helpers;
config = { };
};
};
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 }:
{
name = lib.strings.concatStringsSep "-" namespace;
cases = lib.mapAttrsToList (name: case: { inherit case name; }) cases;
};
in
# A list of the form [ { name = "..."; modules = [ /* test cases */ ]; } ]
builtins.map handleTestFile testsListEvaluated