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,15 +2,18 @@
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";
results = [
{ {
success = true; success = true;
msg = "the describe function: works"; msg = "works";
} }
]; ];
};
actual = describe "the describe function" [ actual = describe "the describe function" [
{ {
success = true; success = true;
@ -18,4 +21,5 @@ describe "the describe function" [
} }
]; ];
}) })
])
] ]

View file

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

View file

@ -4,15 +4,20 @@
... ...
}: 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";
results = [
{
"msg" = "test's itself???";
"success" = true; "success" = true;
} }
]; ];
}
];
actual = (test ./it.test.nix).results; actual = (test ./it.test.nix).results;
}) })
(it "has a path" { (it "has a path" {
@ -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 ({ {
component = name;
results = map ({
msg, msg,
success, success,
actual ? null, actual ? null,
expected ? null, expected ? null,
} @ result: } @ result:
result // {msg = "${name}: ${msg}";}) 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[] | {
(.component): {
"${emotes.fail}": [
.results | map(select(.success==false))[] | {(.msg): {actual, expected}}
],
"${emotes.pass}": .results | map(select(.success) | .msg) | length "${emotes.pass}": .results | map(select(.success) | .msg) | length
} }
} }
}
''; '';
} }