1 HUnitLang98.lhs -- HUnit language support, generic Haskell 98 variant
3 Note: The Haskell system you use needs to find this file when looking
4 for module `HUnitLang`.
6 $Id: HUnitLang98.lhs,v 1.2 2002/02/14 19:27:56 heringto Exp $
17 When adapting this module for other Haskell language systems, change
18 the imports and the implementations but not the interfaces.
25 > import List
(isPrefixOf)
26 > import IO (ioeGetErrorString, try)
33 An assertion is an `IO` computation with trivial result.
35 > type Assertion
= IO ()
37 `assertFailure` signals an assertion failure with a given message.
39 > assertFailure
:: String -> Assertion
41 `performTestCase` performs a single test case. The meaning of the
43 Nothing test case success
44 Just (True, msg) test case failure with the given message
45 Just (False, msg) test case error with the given message
47 > performTestCase
:: Assertion
-> IO (Maybe (Bool, String))
53 > hunitPrefix
= "HUnit:"
55 > hugsPrefix
= "IO Error: User error\nReason: "
56 > nhc98Prefix
= "I/O error (user-defined), call to function `userError':\n "
57 > -- GHC prepends no prefix to the user
-supplied
string.
59 > assertFailure msg
= ioError (userError (hunitPrefix
++ msg
))
61 > performTestCase action
= do r
<- try action
62 > case r
of Right
() -> return Nothing
63 > Left e
-> return (Just
(decode e
))
65 > decode e
= let s0
= ioeGetErrorString e
66 > (_
, s1
) = dropPrefix hugsPrefix s0
67 > (_
, s2
) = dropPrefix nhc98Prefix s1
68 > in dropPrefix hunitPrefix s2
69 > dropPrefix pref str
= if pref `
isPrefixOf` str
70 > then (True, drop (length pref
) str
)