Testing library tlib documentation
tlib.test
Takes tests provided as an attrs in testSet, renders it to a bash script,
and executes the rendered script using pkgs.runCommand.
If the command runs successfully, the test set passes. Otherwise, a detailed error message describing the failed assertion is shown in the logs.
Type
test :: (String | AttrSet) -> TestSet -> Derivation
where:
TestSet :: Test | attrsOf (TestSet | Test)
Test :: Assertion | [ Assertion ]
Assertion :: String | { cond :: String; msg :: String; }
Arguments
- settings
-
Either a string or an attrs.
If it is a string, it will be taken as the name of the derivation built by
runCommand.If it is a set, at least one of the keys
nameorwrapperneed to be set with a string value.- If you are defining tests for wrappers you should set
settings.wrapperto the name of the wrapper. This way, thewrapper.meta.platformsis considered during test execution, and the test will only be run if the system it is running on is supported. - If
settings.wrapperis not set, the test will always be run. This makes sense if you are testing core options or library functions. - If only
settings.wrapperis set, the name will be derived from this value by suffixing it with-test. - If
settings.nameis set, it will be taken as the name of the derivation. - If both are set,
settings.nametakes precedence.
There is also an optional boolean option
settings.debug(default =false). If it is set totrue, the generated bash script is built as an executable script that can be inspected and run inresultwhen running a specific test.The test can be disabled by setting
settings.enable = false. - If you are defining tests for wrappers you should set
- testSet
-
The set of tests to run.
tlib.isDirectory
Returns an Assertion that checks whether path is an existing directory.
Type
isDirectory :: String -> Assertion
Arguments
- path
- The filesystem path to check.
tlib.isFile
Returns an Assertion that checks whether path is an existing regular file.
Type
isFile :: String -> Assertion
Arguments
- path
- The filesystem path to check.
tlib.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.
tlib.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.
tlib.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
tlib.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