2023-12-31 21:33:42 +00:00
|
|
|
msg:
|
2024-01-01 13:48:26 +00:00
|
|
|
{ actual, expected ? { }, asString ? false, asJSON ? false
|
|
|
|
, removeDunders ? false, safeToPrint ? true, throws ? false }:
|
2024-01-01 08:10:32 +00:00
|
|
|
let
|
2024-01-01 09:43:52 +00:00
|
|
|
preProcess = v:
|
|
|
|
if removeDunders then
|
2024-01-01 12:42:18 +00:00
|
|
|
undunder v
|
2024-01-01 09:43:52 +00:00
|
|
|
else if asString then
|
|
|
|
toString v
|
|
|
|
else if asJSON then
|
|
|
|
builtins.toJSON v
|
|
|
|
else
|
|
|
|
v;
|
|
|
|
|
2024-01-01 08:10:32 +00:00
|
|
|
a = preProcess actual;
|
|
|
|
e = preProcess expected;
|
|
|
|
|
2024-01-01 13:48:26 +00:00
|
|
|
undunder = v:
|
|
|
|
if builtins.isAttrs v then
|
|
|
|
builtins.removeAttrs v [ "__toString" "__functor" ]
|
|
|
|
else
|
|
|
|
v;
|
|
|
|
|
|
|
|
out = (if safeToPrint then
|
2024-01-01 17:31:04 +00:00
|
|
|
builtins.toJSON (undunder (if throws then
|
|
|
|
(builtins.tryEval actual).value
|
|
|
|
else {
|
|
|
|
inherit actual expected;
|
|
|
|
}))
|
2024-01-01 13:48:26 +00:00
|
|
|
else
|
2024-01-01 17:31:04 +00:00
|
|
|
''{"msg": "cannot be stringified ):"}'');
|
2024-01-01 12:42:18 +00:00
|
|
|
|
2024-01-01 13:48:26 +00:00
|
|
|
success =
|
|
|
|
if throws then (builtins.tryEval actual).success == false else (a == e);
|
2024-01-01 12:42:18 +00:00
|
|
|
|
2024-01-02 04:01:19 +00:00
|
|
|
in {
|
|
|
|
inherit success msg;
|
|
|
|
} // (if success then
|
|
|
|
{ }
|
|
|
|
else
|
|
|
|
builtins.trace "FAILED ${msg}" { inherit actual expected; })
|