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
];
packages.x86_64-linux.watch = tix.watch {
packages.x86_64-linux.watchpipe = tix.watch {
cmd = "nix run --show-trace .#test file";
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" ''
tail -f -n1 /tmp/tix-output | {
while read out

View file

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

View file

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

View file

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

View file

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

View file

@ -3,10 +3,15 @@ let
in {
overview = ''
.[] | {
(.path): {
"${emotes.fail}": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
"${emotes.pass}": .results | map(select(.success) | .msg) | length
}
(.path):
.results[] | {
(.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"]
else v;
success =
success =
builtins.trace "tix: ${msg}"
(
if throws
then (builtins.tryEval actual).success == false
else (a == e)
);
(
if throws
then (builtins.tryEval actual).success == false
else (a == e)
);
in
{
inherit success msg;