mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-12 02:00:18 +01:00
45 lines
1 KiB
Nix
45 lines
1 KiB
Nix
{
|
|
pkgs,
|
|
lib ? pkgs.lib,
|
|
self ? "",
|
|
...
|
|
}: {
|
|
mkTest = {
|
|
type ? "unit",
|
|
name,
|
|
description ? "",
|
|
format ? "json",
|
|
expected ? null,
|
|
actual ? null,
|
|
actualDrv ? null,
|
|
pos ? null,
|
|
}: let
|
|
fileRelative = lib.removePrefix ((toString self) + "/") pos.file;
|
|
actual' =
|
|
if format == "json"
|
|
then actual
|
|
else lib.generators.toPretty {} actual;
|
|
in {
|
|
inherit type name description expected;
|
|
actual = actual';
|
|
# discard string context, otherwise it's being built instantly which we don't want
|
|
actualDrv = builtins.unsafeDiscardStringContext (actualDrv.drvPath or "");
|
|
pos =
|
|
if pos == null
|
|
then ""
|
|
else "${fileRelative}:${toString pos.line}";
|
|
};
|
|
mkSuite = name: tests: {
|
|
inherit name tests;
|
|
};
|
|
exportSuites = suites: let
|
|
suitesList =
|
|
if builtins.isList suites
|
|
then suites
|
|
else [suites];
|
|
testsMapped = builtins.toJSON suitesList;
|
|
in
|
|
pkgs.runCommand "tests.json" {} ''
|
|
echo '${testsMapped}' > $out
|
|
'';
|
|
}
|