From ac1ae0a58e4fa3d7d5065850b2c82dc2935d0636 Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Tue, 8 Jun 2021 07:03:12 -0700 Subject: doc: auto-generate asserts and attrset library docs If all the docs are auto-generated, it should be easier to convert them to Commonmark. Co-Authored-By: Valentin Gagarin Co-Authored-By: Silvan Mosberger --- lib/asserts.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/asserts.nix') diff --git a/lib/asserts.nix b/lib/asserts.nix index 9ae357cbc935e..98e0b490acf29 100644 --- a/lib/asserts.nix +++ b/lib/asserts.nix @@ -16,11 +16,15 @@ rec { assertMsg :: Bool -> String -> Bool */ # TODO(Profpatsch): add tests that check stderr - assertMsg = pred: msg: + assertMsg = + # Predicate that needs to succeed, otherwise `msg` is thrown + pred: + # Message to throw in case `pred` fails + msg: pred || builtins.throw msg; - /* Specialized `assertMsg` for checking if val is one of the elements - of a list. Useful for checking enums. + /* Specialized `assertMsg` for checking if `val` is one of the elements + of the list `xs`. Useful for checking enums. Example: let sslLibrary = "libressl"; @@ -33,7 +37,14 @@ rec { Type: assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool */ - assertOneOf = name: val: xs: assertMsg + assertOneOf = + # The name of the variable the user entered `val` into, for inclusion in the error message + name: + # The value of what the user provided, to be compared against the values in `xs` + val: + # The list of valid values + xs: + assertMsg (lib.elem val xs) "${name} must be one of ${ lib.generators.toPretty {} xs}, but is: ${ -- cgit 1.4.1