From 70c36dcfb8bcd293171c0faae2d4056334d1e744 Mon Sep 17 00:00:00 2001 From: hsjobeki Date: Thu, 23 Feb 2023 10:21:58 +0100 Subject: [PATCH 1/2] add better documentation comments to lib.runTests --- lib/debug.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/lib/debug.nix b/lib/debug.nix index e3ca3352397e..9ec0169e66e2 100644 --- a/lib/debug.nix +++ b/lib/debug.nix @@ -109,6 +109,8 @@ rec { traceSeqN 2 { a.b.c = 3; } null trace: { a = { b = {…}; }; } => null + + Type: traceSeqN :: Int -> a -> b -> b */ traceSeqN = depth: x: y: let snip = v: if isList v then noQuotes "[…]" v @@ -173,17 +175,68 @@ rec { # -- TESTING -- - /* Evaluate a set of tests. A test is an attribute set `{expr, - expected}`, denoting an expression and its expected result. The - result is a list of failed tests, each represented as `{name, - expected, actual}`, denoting the attribute name of the failing + /* Evaluates a set of tests. + + A test is an attribute set `{expr, expected}`, + denoting an expression and its expected result. + + The result is a `list` of __failed tests__, each represented as + `{name, expected, result}`, + + - expected + - What was passed as `expected` + - result + - The actual `result` of the test + + Denoting the attribute name of the failing test and its expected and actual results. Used for regression testing of the functions in lib; see - tests.nix for an example. Only tests having names starting with + tests.nix for an example. + + > Important: In general only `tests` having names starting with "test" are run. - Add attr { tests = ["testName"]; } to run these tests only. + - Add attr { tests = ["testName"]; } to run tests from list only. + - If `tests` in not specififed all tests will be evaluated. + + Example: + + runTests { + testAndOk = { + expr = lib.and true false; + expected = false; + }; + testAndFail = { + expr = lib.and true false; + expected = true; + }; + } + -> + [ + { + name = "testAndFail"; + expected = true; + result = false; + } + ] + + Type: + runTests :: { + tests = [ String ]; + ${testName} :: { + expr :: a; + expected :: a; + }; + } + -> + [ + { + name :: String; + expected :: a; + result :: a; + } + ] */ runTests = # Tests to run From 09ee6241b55545d44011ae97fd48c9f46567db03 Mon Sep 17 00:00:00 2001 From: hsjobeki Date: Thu, 23 Feb 2023 11:24:47 +0100 Subject: [PATCH 2/2] improves: comprehensiveness --- lib/debug.nix | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/debug.nix b/lib/debug.nix index 9ec0169e66e2..35ca4c7dfb20 100644 --- a/lib/debug.nix +++ b/lib/debug.nix @@ -188,17 +188,12 @@ rec { - result - The actual `result` of the test - Denoting the attribute name of the failing - test and its expected and actual results. - Used for regression testing of the functions in lib; see - tests.nix for an example. + tests.nix for more examples. - > Important: In general only `tests` having names starting with - "test" are run. + Important: Only attributes that start with `test` are executed. - - Add attr { tests = ["testName"]; } to run tests from list only. - - If `tests` in not specififed all tests will be evaluated. + - If you want to run only a subset of the tests add the attribute `tests = ["testName"];` Example: