mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-12 02:00:18 +01:00
chore: allow setting pos for entire suite & remove column from pos
This commit is contained in:
parent
e029fae0b8
commit
4aaaf32621
3 changed files with 59 additions and 44 deletions
78
flake.nix
78
flake.nix
|
|
@ -44,45 +44,43 @@
|
|||
nixtest = {
|
||||
skip = "skip.*d";
|
||||
suites = {
|
||||
"suite-one" = [
|
||||
{
|
||||
name = "test-one";
|
||||
# required to figure out file and line, but optional
|
||||
pos = __curPos;
|
||||
expected = 1;
|
||||
actual = 1;
|
||||
}
|
||||
{
|
||||
name = "fail";
|
||||
pos = __curPos;
|
||||
expected = 0;
|
||||
actual = "meow";
|
||||
}
|
||||
{
|
||||
name = "snapshot-test";
|
||||
type = "snapshot";
|
||||
pos = __curPos;
|
||||
actual = "test";
|
||||
}
|
||||
{
|
||||
name = "test-snapshot-drv";
|
||||
type = "snapshot";
|
||||
pos = __curPos;
|
||||
actualDrv = pkgs.runCommand "test-snapshot" {} ''
|
||||
echo '"snapshot drv"' > $out
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "test-error-drv";
|
||||
pos = __curPos;
|
||||
expected = null;
|
||||
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" = [
|
||||
"suite-one" = {
|
||||
pos = __curPos;
|
||||
tests = [
|
||||
{
|
||||
name = "test-one";
|
||||
# required to figure out file and line, but optional
|
||||
expected = 1;
|
||||
actual = 1;
|
||||
}
|
||||
{
|
||||
name = "fail";
|
||||
expected = 0;
|
||||
actual = "meow";
|
||||
}
|
||||
{
|
||||
name = "snapshot-test";
|
||||
type = "snapshot";
|
||||
actual = "test";
|
||||
}
|
||||
{
|
||||
name = "test-snapshot-drv";
|
||||
type = "snapshot";
|
||||
actualDrv = pkgs.runCommand "test-snapshot" {} ''
|
||||
echo '"snapshot drv"' > $out
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "test-error-drv";
|
||||
expected = null;
|
||||
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 = [
|
||||
{
|
||||
name = "obj-snapshot";
|
||||
type = "snapshot";
|
||||
|
|
@ -93,6 +91,7 @@
|
|||
name = "pretty-snapshot";
|
||||
type = "snapshot";
|
||||
format = "pretty";
|
||||
pos = __curPos;
|
||||
actual = {
|
||||
example = args: {};
|
||||
example2 = {
|
||||
|
|
@ -112,7 +111,6 @@
|
|||
}
|
||||
{
|
||||
name = "skipped";
|
||||
pos = __curPos;
|
||||
expected = null;
|
||||
actual = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
pos =
|
||||
if pos == null
|
||||
then ""
|
||||
else "${fileRelative}:${toString pos.line}:${toString pos.column}";
|
||||
else "${fileRelative}:${toString pos.line}";
|
||||
};
|
||||
mkSuite = name: tests: {
|
||||
inherit name tests;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,18 @@ in {
|
|||
description = "Which tests to skip (regex)";
|
||||
};
|
||||
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 = {};
|
||||
};
|
||||
};
|
||||
|
|
@ -34,11 +45,17 @@ in {
|
|||
config.legacyPackages = rec {
|
||||
"nixtests" = let
|
||||
suites = map (suiteName: let
|
||||
tests = builtins.getAttr suiteName config.nixtest.suites;
|
||||
suite = builtins.getAttr suiteName config.nixtest.suites;
|
||||
in
|
||||
nixtests-lib.mkSuite
|
||||
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);
|
||||
in
|
||||
nixtests-lib.exportSuites suites;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue