Test

CSL tests are written in definitions that have the test modifier. The value of a val test definition must be a test.

Tests are run from the JVM-based CSL interaction APIs. Examples of this for Kotlin and Clojure are available in the example CSL app repository.

unitTest : String -> (Unit -> UnitTest) -> Test

The simplest form of a test is a unit test, which is intended to test one small part of a CSL program. The string argument is a human-readable name to be used in test reports. When a unit test is run, the function is invoked, and it will either pass or fail.

Unit tests are built from three operations:

pass : UnitTest

A test that passes.

fail : a -> UnitTest

A test that fails, reporting its argument as the reason for the failure.

expected : a -> b -> UnitTest

A test that fails, reporting a mismatch between its first and second arguments as the reason for the failure. The first argument is interpreted as the expected result, while the second is what was provided.

In addition, a few helpers are provided:

assert : Bool -> UnitTest

Fails when its argument is False, passes otherwise.

assertEqual : a -> a -> UnitTest

Uses the default equal function to check the two arguments for equality, failing if they are not equal. The first value is interpreted as the expected value, the second as the actual one.

assertEqualBy : (a -> b -> Bool) -> a -> b -> UnitTest

Uses the provided function to check the other two arguments for equality, failing if they are not equal. The first value is interpreted as the expected value, the second as the actual one.

assertEqualEpsilon : Float -> Float -> UnitTest

Asserts that two values differ by at most 0.0000001.

suite : String -> List Test -> Test

Collect a list of tests into a single test suite to be run together. The first argument is a human-readable name for the test suite.

withData : String -> (a -> Test) -> Test

States that a test depends on externally-provided data. The string argument is a name used in the JVM test runner to provide data, while the function argument computes a new test from the provided data.

suiteWithData : String -> (a -> Tuple String (Unit -> UnitTest)) -> Test

Construct a test suite from externally-provided data. The external data is expected to have type List a, and the test suite is constructed by applying the function argument to each element of the list, with the tuple being used for the name and the individual test. The string argument is both the name of the suite and the name of the data source.