nixite/testing/it.nix

26 lines
641 B
Nix
Raw Normal View History

msg:
2024-01-01 11:12:37 +00:00
{ actual, expected, asString ? false, asJSON ? false, removeDunders ? false
, safeToPrint ? true }:
2024-01-01 08:10:32 +00:00
let
2024-01-01 09:43:52 +00:00
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;
2024-01-01 08:10:32 +00:00
a = preProcess actual;
e = preProcess expected;
2024-01-01 09:43:52 +00:00
in if (a == e) then ''
echo 'it ${msg}'
'' else
2024-01-01 11:12:37 +00:00
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}
''