64 lines
1.5 KiB
Nix
64 lines
1.5 KiB
Nix
{
|
|
lib,
|
|
modularFlake,
|
|
nixpkgs,
|
|
...
|
|
}:
|
|
let
|
|
# system used to develop this flake and check its code for validity
|
|
checkSystem = "x86_64-linux";
|
|
checkPkgs = import nixpkgs { system = checkSystem; };
|
|
|
|
testsDir = ./.;
|
|
entries = builtins.readDir testsDir;
|
|
testFileNames = builtins.filter (
|
|
name: entries.${name} == "regular" && name != "default.nix" && lib.hasSuffix ".nix" name
|
|
) (builtins.attrNames entries);
|
|
tests = builtins.listToAttrs (
|
|
map (fileName: {
|
|
name = lib.removeSuffix ".nix" fileName;
|
|
value = testsDir + "/${fileName}";
|
|
}) testFileNames
|
|
);
|
|
|
|
mkCase =
|
|
name: path:
|
|
let
|
|
test = (import path) {
|
|
inherit
|
|
modularFlake
|
|
checkSystem
|
|
checkPkgs
|
|
lib
|
|
;
|
|
};
|
|
produced = modularFlake.mkFlake {
|
|
modules = test.modules;
|
|
outputs = test.outputs or (builtins.attrValues modularFlake.defaultOutputs);
|
|
systems = [ checkSystem ];
|
|
};
|
|
in
|
|
lib.nameValuePair "test-${name}" (
|
|
if test ? check then
|
|
{
|
|
expr = test.check produced;
|
|
expected = true;
|
|
}
|
|
else if test.fails then
|
|
{
|
|
expr = (builtins.tryEval (modularFlake.safeSeq produced null)).success;
|
|
expected = false;
|
|
}
|
|
else
|
|
{
|
|
expr = produced;
|
|
expected = test.expectedOutput;
|
|
}
|
|
);
|
|
cases = lib.mapAttrs' mkCase tests;
|
|
in
|
|
{
|
|
${checkSystem} = builtins.seq (lib.debug.throwTestFailures {
|
|
failures = lib.runTests cases;
|
|
}) { };
|
|
}
|