tix/tix/it.nix

53 lines
1,002 B
Nix

name: {
actual,
expected ? {},
asString ? false,
asJSON ? false,
removeDunders ? false,
safeToPrint ? true,
throws ? false,
debug ? false,
}: let
emotes = import ./emotes.nix;
preProcess = v:
if removeDunders
then undunder v
else if asString
then toString v
else if asJSON
then builtins.toJSON v
else v;
a = preProcess actual;
e = preProcess expected;
undunder = v:
if builtins.isAttrs v
then builtins.removeAttrs v ["__toString" "__functor"]
else v;
success =
if debug
then break
else
builtins.trace "tix: ${name}"
(
if throws
then (builtins.tryEval actual).success == false
else (a == e)
);
in {
inherit name;
value =
{
inherit success;
}
// (
if success
then builtins.trace "tix: ${emotes.pass}" {}
else
builtins.trace "tix: ${emotes.fail}"
{inherit actual expected;}
);
}