2025-05-03 22:23:05 +02:00
|
|
|
{
|
|
|
|
|
pkgs,
|
|
|
|
|
lib ? pkgs.lib,
|
|
|
|
|
self ? "",
|
|
|
|
|
...
|
|
|
|
|
}: {
|
2025-05-03 22:05:29 +02:00
|
|
|
mkTest = {
|
|
|
|
|
type ? "unit",
|
|
|
|
|
name,
|
|
|
|
|
description ? "",
|
2025-05-10 21:55:08 +02:00
|
|
|
format ? "json",
|
2025-05-03 22:05:29 +02:00
|
|
|
expected ? null,
|
|
|
|
|
actual ? null,
|
|
|
|
|
actualDrv ? null,
|
2025-05-31 17:20:19 +02:00
|
|
|
script ? null,
|
2025-05-03 22:05:29 +02:00
|
|
|
pos ? null,
|
2025-05-03 22:23:05 +02:00
|
|
|
}: let
|
|
|
|
|
fileRelative = lib.removePrefix ((toString self) + "/") pos.file;
|
2025-05-10 21:55:08 +02:00
|
|
|
actual' =
|
|
|
|
|
if format == "json"
|
|
|
|
|
then actual
|
|
|
|
|
else lib.generators.toPretty {} actual;
|
2025-05-11 02:05:01 +02:00
|
|
|
expected' =
|
|
|
|
|
if format == "json"
|
|
|
|
|
then expected
|
|
|
|
|
else lib.generators.toPretty {} expected;
|
2025-05-03 22:23:05 +02:00
|
|
|
in {
|
2025-05-11 02:05:01 +02:00
|
|
|
inherit type name description;
|
2025-05-10 21:55:08 +02:00
|
|
|
actual = actual';
|
2025-05-11 02:05:01 +02:00
|
|
|
expected = expected';
|
2025-05-04 21:53:51 +02:00
|
|
|
# discard string context, otherwise it's being built instantly which we don't want
|
|
|
|
|
actualDrv = builtins.unsafeDiscardStringContext (actualDrv.drvPath or "");
|
2025-05-31 17:20:19 +02:00
|
|
|
script =
|
|
|
|
|
if script != null
|
|
|
|
|
then builtins.unsafeDiscardStringContext (pkgs.writeShellScript "nixtest-${name}" script).drvPath
|
|
|
|
|
else null;
|
2025-05-03 22:05:29 +02:00
|
|
|
pos =
|
|
|
|
|
if pos == null
|
|
|
|
|
then ""
|
2025-05-10 22:14:56 +02:00
|
|
|
else "${fileRelative}:${toString pos.line}";
|
2025-05-03 22:05:29 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
'';
|
|
|
|
|
}
|