wlib.test set documentation
wlib.test.mkTestScript
Takes tests provided as an attribute set in testSet, renders it to a bash script returned as a string.
If the script runs successfully, the test set passes.
Otherwise, it exits with the error code 1 and a detailed error message describing the failed assertion is printed.
Type
mkTestScript :: String -> TestSet -> String
where:
TestSet :: Test | attrsOf (TestSet | Test)
Test :: Assertion | [ Assertion ]
Assertion :: String | { cond :: String; msg :: String; }
Arguments
Example
{ pkgs, wlib }: let
name = "math-tests";
inherit (wlib.test) areEqual;
testSet = {
addition = [
(areEqual 2 (1 + 1))
(areEqual 7 (5 + 2))
];
multiplication = [
(areEqual 1 (1 * 1))
(areEqual 10 (5 * 2))
];
};
in pkgs.runCommand name {} ''
${wlib.test.mkTestScript name testSet}
touch $out
'';
wlib.test.isDirectory
Returns an Assertion that checks whether path is an existing directory.
Type
isDirectory :: String -> Assertion
Arguments
- path
- The filesystem path to check.
wlib.test.isFile
Returns an Assertion that checks whether path is an existing regular file.
Type
isFile :: String -> Assertion
Arguments
- path
- The filesystem path to check.
wlib.test.notIsFile
Returns an Assertion that checks whether path does not exist as a regular file.
Type
notIsFile :: String -> Assertion
Arguments
- path
- The filesystem path that should be absent.
wlib.test.notIsDirectory
Returns an Assertion that checks whether path does not exist as a directory.
Type
notIsFile :: String -> Assertion
Arguments
- path
- The filesystem path that should be absent.
wlib.test.fileContains
Returns an Assertion that checks whether file contains a line matching pattern.
The check is performed with grep -Eq, so pattern is treated as an extended regular expression.
Type
fileContains :: String -> String -> Assertion
Arguments
wlib.test.notFileContains
Returns an Assertion that checks whether file does not contain a line matching pattern.
The check is performed with ! grep -Eq, so pattern is treated as an extended regular expression.
Type
notFileContains :: String -> String -> Assertion
Arguments
wlib.test.areEqual
Returns an Assertion that checks whether expected and actual are equal.
The comparison is performed in Nix at evaluation time. If the values differ, the assertion message shows both values serialised as JSON.
Type
areEqual :: Any -> Any -> Assertion
Arguments
wlib.test.toSanitizedJSON
Recieves any nix value and prints a json representation of it.
Calls builtins.toJSON, but replaces all functions with a description first.
Useful for printing values as part of messages for failed tests.
Will recurse into functors, but not derivations.