rework describe function

This commit is contained in:
tristan 2024-01-03 10:14:28 +00:00
parent f125ec4c31
commit 2df95bbc56
7 changed files with 77 additions and 52 deletions

View file

@ -22,11 +22,16 @@
./mytest.nix ./mytest.nix
]; ];
packages.x86_64-linux.watch = tix.watch { packages.x86_64-linux.watchpipe = tix.watch {
cmd = "nix run --show-trace .#test file"; cmd = "nix run --show-trace .#test file";
view = "tee -a /tmp/tix-output"; view = "tee -a /tmp/tix-output";
}; };
packages.x86_64-linux.watch = tix.watch {
cmd = "nix run --show-trace .#test";
view = "cat";
};
packages.x86_64-linux.results = pkgs.writeShellScriptBin "results" '' packages.x86_64-linux.results = pkgs.writeShellScriptBin "results" ''
tail -f -n1 /tmp/tix-output | { tail -f -n1 /tmp/tix-output | {
while read out while read out

View file

@ -2,20 +2,24 @@
describe, describe,
it, it,
... ...
}: }: [
describe "the describe function" [ (describe "the describe function" [
(it "returns an array with the message changed" { (it "returns an array with the message changed" {
expected = [ expected = {
{ component = "the describe function";
success = true; results = [
msg = "the describe function: works"; {
} success = true;
]; msg = "works";
actual = describe "the describe function" [ }
{ ];
success = true; };
msg = "works"; actual = describe "the describe function" [
} {
]; success = true;
}) msg = "works";
}
];
})
])
] ]

View file

@ -2,16 +2,17 @@
it, it,
describe, describe,
... ...
}: }: [
describe "it" [ (describe "it" [
(it "test's itself???" rec { (it "test's itself???" rec {
expected = { expected = {
success = true; success = true;
msg = "test's itself???"; msg = "test's itself???";
}; };
actual = it "test's itself???" { actual = it "test's itself???" {
expected = expected; expected = expected;
actual = expected; actual = expected;
}; };
}) })
])
] ]

View file

@ -4,13 +4,18 @@
... ...
}: let }: let
test = import ../tix/test.nix; test = import ../tix/test.nix;
in in [
describe "the test function" [ (describe "the test function" [
(it "get's test results" { (it "get's test results" {
expected = [ expected = [
{ {
"msg" = "it: test's itself???"; "component" = "it";
"success" = true; results = [
{
"msg" = "test's itself???";
"success" = true;
}
];
} }
]; ];
actual = (test ./it.test.nix).results; actual = (test ./it.test.nix).results;
@ -23,4 +28,5 @@ in
actual = test ./bad/string.nix; actual = test ./bad/string.nix;
throws = true; throws = true;
}) })
] ])
]

View file

@ -1,9 +1,13 @@
name: name: tests:
builtins.trace "tix: ${name}" builtins.trace "tix: ${name}"
map ({ {
msg, component = name;
success, results = map ({
actual ? null, msg,
expected ? null, success,
} @ result: actual ? null,
result // {msg = "${name}: ${msg}";}) expected ? null,
} @ result:
result)
tests;
}

View file

@ -3,10 +3,15 @@ let
in { in {
overview = '' overview = ''
.[] | { .[] | {
(.path): { (.path):
"${emotes.fail}": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}], .results[] | {
"${emotes.pass}": .results | map(select(.success) | .msg) | length (.component): {
} "${emotes.fail}": [
.results | map(select(.success==false))[] | {(.msg): {actual, expected}}
],
"${emotes.pass}": .results | map(select(.success) | .msg) | length
}
}
} }
''; '';
} }

View file

@ -26,13 +26,13 @@ msg: {
then builtins.removeAttrs v ["__toString" "__functor"] then builtins.removeAttrs v ["__toString" "__functor"]
else v; else v;
success = success =
builtins.trace "tix: ${msg}" builtins.trace "tix: ${msg}"
( (
if throws if throws
then (builtins.tryEval actual).success == false then (builtins.tryEval actual).success == false
else (a == e) else (a == e)
); );
in in
{ {
inherit success msg; inherit success msg;