File: example-literate.lhs

package info (click to toggle)
haskell-tasty-th 0.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 80 kB
  • sloc: haskell: 152; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 899 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
This is an example of using tasty-th with literate haskell files.
First, we need to import the library and enable template haskell:

> {-# LANGUAGE TemplateHaskell #-}
> import Test.Tasty
> import Test.Tasty.TH
> import Test.Tasty.QuickCheck
> import Test.Tasty.HUnit

Now, we can write some quickcheck properties:

> prop_length_append :: [Int] -> [Int] -> Bool
> prop_length_append as bs = length (as ++ bs) == length as + length bs

Or write a HUnit test case:

> case_length_1 :: Assertion
> case_length_1 = 1 @=? length [()]

Properties in comments are not run:

prop_comment :: Assertion
prop_comment = assertFailure "property in comment should not be run"

We can also create test trees:

> test_plus :: [TestTree]
> test_plus =
>   [ testCase "3 + 4" (7 @=? (3 + 4))
>     --  ...
>   ]

We only need a main now that collects all our tests:

> main :: IO ()
> main = $(defaultMainGenerator)