runTests
lib.debug.runTests
Docs pulled from | This Revision | 8 minutes ago
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
- What was passed as
- result
- The actual
result
of the test
- The actual
Used for regression testing of the functions in lib; see tests.nix for more examples.
Important: Only attributes that start with test
are executed.
- If you want to run only a subset of the tests add the attribute
tests = ["testName"];
Inputs
tests
-
Tests to run
Type
runTests :: {
tests = [ String ];
${testName} :: {
expr :: a;
expected :: a;
};
}
->
[
{
name :: String;
expected :: a;
result :: a;
}
]
Examples
lib.debug.runTests
usage example
runTests {
testAndOk = {
expr = lib.and true false;
expected = false;
};
testAndFail = {
expr = lib.and true false;
expected = true;
};
}
->
[
{
name = "testAndFail";
expected = true;
result = false;
}
]
Noogle detected
Implementation
The following is the current implementation of this function.
runTests =
tests: concatLists (attrValues (mapAttrs (name: test:
let testsToRun = if tests ? tests then tests.tests else [];
in if (substring 0 4 name == "test" || elem name testsToRun)
&& ((testsToRun == []) || elem name tests.tests)
&& (test.expr != test.expected)
then [ { inherit name; expected = test.expected; result = test.expr; } ]
else [] ) tests));