chore: allow setting pos for entire suite & remove column from pos

This commit is contained in:
technofab 2025-05-10 22:14:56 +02:00
parent e029fae0b8
commit 4aaaf32621
3 changed files with 59 additions and 44 deletions

View file

@ -44,45 +44,43 @@
nixtest = { nixtest = {
skip = "skip.*d"; skip = "skip.*d";
suites = { suites = {
"suite-one" = [ "suite-one" = {
{ pos = __curPos;
name = "test-one"; tests = [
# required to figure out file and line, but optional {
pos = __curPos; name = "test-one";
expected = 1; # required to figure out file and line, but optional
actual = 1; expected = 1;
} actual = 1;
{ }
name = "fail"; {
pos = __curPos; name = "fail";
expected = 0; expected = 0;
actual = "meow"; actual = "meow";
} }
{ {
name = "snapshot-test"; name = "snapshot-test";
type = "snapshot"; type = "snapshot";
pos = __curPos; actual = "test";
actual = "test"; }
} {
{ name = "test-snapshot-drv";
name = "test-snapshot-drv"; type = "snapshot";
type = "snapshot"; actualDrv = pkgs.runCommand "test-snapshot" {} ''
pos = __curPos; echo '"snapshot drv"' > $out
actualDrv = pkgs.runCommand "test-snapshot" {} '' '';
echo '"snapshot drv"' > $out }
''; {
} name = "test-error-drv";
{ expected = null;
name = "test-error-drv"; actualDrv = pkgs.runCommand "test-error-drv" {} ''
pos = __curPos; echo "This works, but its better to just write 'fail' to \$out and expect 'success' or sth."
expected = null; exit 1
actualDrv = pkgs.runCommand "test-error-drv" {} '' '';
echo "This works, but its better to just write 'fail' to \$out and expect 'success' or sth." }
exit 1 ];
''; };
} "other-suite".tests = [
];
"other-suite" = [
{ {
name = "obj-snapshot"; name = "obj-snapshot";
type = "snapshot"; type = "snapshot";
@ -93,6 +91,7 @@
name = "pretty-snapshot"; name = "pretty-snapshot";
type = "snapshot"; type = "snapshot";
format = "pretty"; format = "pretty";
pos = __curPos;
actual = { actual = {
example = args: {}; example = args: {};
example2 = { example2 = {
@ -112,7 +111,6 @@
} }
{ {
name = "skipped"; name = "skipped";
pos = __curPos;
expected = null; expected = null;
actual = null; actual = null;
} }

View file

@ -27,7 +27,7 @@
pos = pos =
if pos == null if pos == null
then "" then ""
else "${fileRelative}:${toString pos.line}:${toString pos.column}"; else "${fileRelative}:${toString pos.line}";
}; };
mkSuite = name: tests: { mkSuite = name: tests: {
inherit name tests; inherit name tests;

View file

@ -23,7 +23,18 @@ in {
description = "Which tests to skip (regex)"; description = "Which tests to skip (regex)";
}; };
suites = mkOption { suites = mkOption {
type = types.attrsOf (types.listOf types.attrs); type = types.attrsOf (types.submodule {
options = {
tests = mkOption {
type = types.listOf types.attrs;
default = [];
};
pos = mkOption {
type = types.nullOr types.attrs;
default = null;
};
};
});
default = {}; default = {};
}; };
}; };
@ -34,11 +45,17 @@ in {
config.legacyPackages = rec { config.legacyPackages = rec {
"nixtests" = let "nixtests" = let
suites = map (suiteName: let suites = map (suiteName: let
tests = builtins.getAttr suiteName config.nixtest.suites; suite = builtins.getAttr suiteName config.nixtest.suites;
in in
nixtests-lib.mkSuite nixtests-lib.mkSuite
suiteName suiteName
(map (test: nixtests-lib.mkTest test) tests)) (map (test:
nixtests-lib.mkTest ({
# default pos to suite's pos if given
pos = suite.pos;
}
// test))
suite.tests))
(builtins.attrNames config.nixtest.suites); (builtins.attrNames config.nixtest.suites);
in in
nixtests-lib.exportSuites suites; nixtests-lib.exportSuites suites;