5 /* Print a trace message if pred is false.
6 Intended to be used to augment asserts with helpful error messages.
13 assert (assertMsg ("foo" == "bar") "foo is not bar, silly"); ""
14 stderr> trace: foo is not bar, silly
15 stderr> assert failed at …
18 assertMsg :: Bool -> String -> Bool
20 # TODO(Profpatsch): add tests that check stderr
21 assertMsg = pred: msg:
24 else builtins.trace msg false;
26 /* Specialized `assertMsg` for checking if val is one of the elements
27 of a list. Useful for checking enums.
30 let sslLibrary = "libressl"
31 in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ]
33 stderr> trace: sslLibrary must be one of "openssl", "bearssl", but is: "libressl"
36 assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool
38 assertOneOf = name: val: xs: assertMsg
40 "${name} must be one of ${
41 lib.generators.toPretty {} xs}, but is: ${
42 lib.generators.toPretty {} val}";