pretty printing

This commit is contained in:
Tristan 2024-01-03 07:18:33 +00:00
parent bee204701e
commit 6f72a66019
5 changed files with 22 additions and 14 deletions

View file

@ -1,5 +1,5 @@
name: name:
builtins.trace "testing ${name}" builtins.trace "tix: ${name}"
map ({ map ({
msg, msg,
success, success,

4
tix/emotes.nix Normal file
View file

@ -0,0 +1,4 @@
{
pass = "";
fail = "";
}

View file

@ -1,9 +1,11 @@
{ let
emotes = import ./emotes.nix;
in {
overview = '' overview = ''
.[] | { .[] | {
(.path): { (.path): {
"": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}], "${emotes.fail}": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
"": .results | map(select(.success) | .msg) | length "${emotes.pass}": .results | map(select(.success) | .msg) | length
} }
} }
''; '';

View file

@ -7,6 +7,8 @@ msg: {
safeToPrint ? true, safeToPrint ? true,
throws ? false, throws ? false,
}: let }: let
emotes = import ./emotes.nix;
preProcess = v: preProcess = v:
if removeDunders if removeDunders
then undunder v then undunder v
@ -24,19 +26,19 @@ msg: {
then builtins.removeAttrs v ["__toString" "__functor"] then builtins.removeAttrs v ["__toString" "__functor"]
else v; else v;
success = success = (
builtins.trace "testing if it ${msg}" if throws
( then (builtins.tryEval actual).success == false
if throws else (a == e)
then (builtins.tryEval actual).success == false );
else (a == e)
);
in in
{ {
inherit success msg; inherit success msg;
} }
// ( // (
if success if success
then {} then builtins.trace "tix: ${emotes.pass} ${msg}" {}
else builtins.trace "FAILED ${msg}" {inherit actual expected;} else
builtins.trace "tix: ${emotes.fail} ${msg}"
{inherit actual expected;}
) )

View file

@ -3,7 +3,7 @@ path: let
describe = import ./describe.nix; describe = import ./describe.nix;
suite = import path; suite = import path;
in in
builtins.trace ("testing " + builtins.baseNameOf path) builtins.trace ("tix: " + builtins.baseNameOf path)
( (
if !builtins.isFunction suite if !builtins.isFunction suite
then throw "A test suite should be in the form { it }: [ <tests> ]." then throw "A test suite should be in the form { it }: [ <tests> ]."