mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2026-02-02 03:15:12 +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
14
flake.nix
14
flake.nix
|
|
@ -44,37 +44,34 @@
|
||||||
nixtest = {
|
nixtest = {
|
||||||
skip = "skip.*d";
|
skip = "skip.*d";
|
||||||
suites = {
|
suites = {
|
||||||
"suite-one" = [
|
"suite-one" = {
|
||||||
|
pos = __curPos;
|
||||||
|
tests = [
|
||||||
{
|
{
|
||||||
name = "test-one";
|
name = "test-one";
|
||||||
# required to figure out file and line, but optional
|
# required to figure out file and line, but optional
|
||||||
pos = __curPos;
|
|
||||||
expected = 1;
|
expected = 1;
|
||||||
actual = 1;
|
actual = 1;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "fail";
|
name = "fail";
|
||||||
pos = __curPos;
|
|
||||||
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";
|
||||||
pos = __curPos;
|
|
||||||
actualDrv = pkgs.runCommand "test-snapshot" {} ''
|
actualDrv = pkgs.runCommand "test-snapshot" {} ''
|
||||||
echo '"snapshot drv"' > $out
|
echo '"snapshot drv"' > $out
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "test-error-drv";
|
name = "test-error-drv";
|
||||||
pos = __curPos;
|
|
||||||
expected = null;
|
expected = null;
|
||||||
actualDrv = pkgs.runCommand "test-error-drv" {} ''
|
actualDrv = pkgs.runCommand "test-error-drv" {} ''
|
||||||
echo "This works, but its better to just write 'fail' to \$out and expect 'success' or sth."
|
echo "This works, but its better to just write 'fail' to \$out and expect 'success' or sth."
|
||||||
|
|
@ -82,7 +79,8 @@
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
"other-suite" = [
|
};
|
||||||
|
"other-suite".tests = [
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue