Skip to main content

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:

  1. the test name
  2. the failure message
  3. the expected result
  4. 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:
    • .hs for direct Haskell source files
    • .lhs for inverse-commented literate Haskell style
  • A source file must contain a Haskell module.
  • Only one of the test files may have a main function. This file must have Main as 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 the main function.

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.