nixite/testing/it.nix
2024-01-01 11:12:37 +00:00

26 lines
641 B
Nix

msg:
{ actual, expected, asString ? false, asJSON ? false, removeDunders ? false
, safeToPrint ? true }:
let
preProcess = v:
if removeDunders then
builtins.removeAttrs v [ "__toString" "__functor" ]
else if asString then
toString v
else if asJSON then
builtins.toJSON v
else
v;
a = preProcess actual;
e = preProcess expected;
in if (a == e) then ''
echo 'it ${msg}'
'' else
builtins.trace "FAILED ${msg}" builtins.trace
(if safeToPrint then builtins.toJSON actual else actual) builtins.trace
(if safeToPrint then builtins.toJSON expected else expected) ''
echo FAILED ${msg}
''