better testing experience

This commit is contained in:
tristan 2024-01-02 04:01:19 +00:00
parent 4f28cbfda7
commit 9421a0a910
10 changed files with 96 additions and 49 deletions

View file

@ -133,7 +133,10 @@ in with html; [
}))
(it "renders on / off attrs" ({
actual = toString (tag "p" {on = true; off = false;});
actual = toString (tag "p" {
on = true;
off = false;
});
expected = "<p on></p>";
}))

View file

@ -1,6 +1,7 @@
path:
builtins.trace ("testing " + builtins.baseNameOf path) ''
echo
echo 'TEST: ${builtins.baseNameOf path}'
echo
'' + builtins.concatStringsSep "\n" (import path)
builtins.trace ("testing " + builtins.baseNameOf path)
{
inherit path;
results = (import path);
}

View file

@ -33,12 +33,9 @@ let
success =
if throws then (builtins.tryEval actual).success == false else (a == e);
in if success then ''
echo 'it ${msg}'
'' else
builtins.trace "FAILED ${msg}" (let file = builtins.toFile "value" out;
in ''
echo FAILED ${msg}
echo '${file}'
cat '${file}' | jq '.'
'')
in {
inherit success msg;
} // (if success then
{ }
else
builtins.trace "FAILED ${msg}" { inherit actual expected; })

View file

@ -34,7 +34,7 @@ in with md; [
'';
expected = {
matched = true;
block = elems.List ["something"];
block = elems.List [ "something" ];
};
asJSON = true;
}))
@ -46,10 +46,7 @@ in with md; [
'';
expected = {
matched = true;
block = elems.List [
"something"
"something else"
];
block = elems.List [ "something" "something else" ];
};
asJSON = true;
}))
@ -62,10 +59,22 @@ in with md; [
expected = {
matched = true;
block = elems.List [
[(elems.input {type = "checkbox"; disabled = true; checked = false; } "")
"something"]
[(elems.input {type = "checkbox"; disabled = true; checked = true; } "")
"something else"]
[
(elems.input {
type = "checkbox";
disabled = true;
checked = false;
} "")
"something"
]
[
(elems.input {
type = "checkbox";
disabled = true;
checked = true;
} "")
"something else"
]
];
};
asJSON = true;
@ -77,10 +86,7 @@ in with md; [
- something else'';
expected = {
matched = true;
block = elems.List [
"something"
"something else"
];
block = elems.List [ "something" "something else" ];
};
asJSON = true;
}))

View file

@ -1,5 +1,16 @@
pkgs:
let test = import ./import.nix;
in files:
(pkgs.writeShellScriptBin "test"
(builtins.concatStringsSep "\n" (map test files)))
pkgs: files:
let
test = import ./import.nix;
res = map test files;
resFile = builtins.toFile "results" (builtins.toJSON res);
filter = ''
.[] | {
(.path): {
failures: [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
success: .results | map(select(.success) | .msg) | length
}
}
'';
in (pkgs.writeShellScriptBin "test" ''
cat '${resFile}' | ${pkgs.jq}/bin/jq '${filter}' | ${pkgs.fx}/bin/fx
'')

10
testing/watch.nix Normal file
View file

@ -0,0 +1,10 @@
pkgs: cmd: pname:
pkgs.writeShellScriptBin "watch" ''
while true
do
${cmd} &
${pkgs.inotify-tools}/bin/inotifywait -e modify -r .
pkill ${pname}
done
''