Haskell
Tests
Tests are to be written with the HaskellUnit module, which can be found in
the repository. First, the HaskellUnit module must be
imported in the test files:
module Main where
import HaskellUnit
Next, define the test cases using the testcase function provided by HaskellUnit:
testcase :: (Eq a, Show a) => String -> String -> a -> a -> IO Bool
The function takes the following parameters in the given order:
- the test name
- the failure message
- the expected result
- the actual result
For example:
test1 = testcase "factorial 1" "(factorial 5) falsch" 120 (factorial 5)
Then, the test file must define a main function using the runTests function provided by
HaskellUnit to run all test cases:
main = runTests [test1, test2, test3]
Conventions
- Allowed file extensions for Haskell source files are:
.hsfor direct Haskell source files.lhsfor inverse-commented literate Haskell style
- A source file must contain a Haskell module.
- Only one of the test files may have a
mainfunction. This file must haveMainas its module name. If you want to use multiple test files, you can import the tests from the other files into the test file with themainfunction.
Environments
Currently, the only available environment is hs, which includes the GHC version provided by Ubuntu
22.04. It also includes a small set of Haskell libraries, including random, HCodecs, parallel,
network, and lens. For a complete list of installed packages, see the repository's Dockerfile.