Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing library tlib documentation

tlib.test

This function is a wrapped version of wlib.test.mkTestScript specific to the nix-wrapper-modules repository.

The tlib variable recieved by the tests in the nix-wrapper-modules repository contains all the values in wlib.test, plus this function.

Unlike wlib.test.mkTestScript this version returns a derivation rather than a string, and has more options available for the first argument.

This function takes tests provided as an attribute set 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 name or wrapper need to be set with a string value.

  • If you are defining tests for wrappers you should set settings.wrapper to the name of the wrapper. This way, the wrapper.meta.platforms is considered during test execution, and the test will only be run if the system it is running on is supported.
  • If settings.wrapper is not set, the test will always be run. This makes sense if you are testing core options or library functions.
  • If only settings.wrapper is set, the name will be derived from this value by suffixing it with -test.
  • If settings.name is set, it will be taken as the name of the derivation.
  • If both are set, settings.name takes precedence.

There is also an optional boolean option settings.debug (default = false). If it is set to true, the generated bash script is built as an executable script that can be inspected and run in result when running a specific test.

The test can be disabled by setting settings.enable = false.

testSet

The set of tests to run.