HaskellTapModule
From Test Anything Protocol
Contents |
[edit] TAP: A TAP-producing Haskell module
As an exercise while learning Haskell I thought it would be nice to write a TAP module for Haskell. The code can be found here: TAP.hs in SVN repo.
Note: Please keep in mind that I'm a Haskell newbie, so YMMV...
Here's the limited documentation that's currently available:
[edit] PLAN
planTests :: Int -> TAP () -- planTests nbTests
planNoPlan :: TAP () -- planNoPlan
planSkipAll :: String -> TAP () -- planSkipAll reason
[edit] TEST
ok :: Bool -> Maybe String -> TAP Bool -- ok test $ Just name -- ok test Nothing
is :: (Show a, Eq a) => a -> a -> Maybe String -> TAP Bool -- is result expected $ Just name -- is result expected $ Nothing
isnt :: (Show a, Eq a) => a -> a -> Maybe String -> TAP Bool -- isnt result expected $ Just name -- isnt result expected $ Nothing
like :: String -> String -> Maybe String -> TAP Bool -- like result pattern $ Just name -- like result pattern Nothing
unlike :: String -> String -> Maybe String -> TAP Bool -- unlike result pattern $ Just name -- unlike result pattern Nothing
pass :: Maybe String -> TAP Bool -- pass Just name -- pass Nothing
fail :: Maybe String -> TAP Bool -- fail Just name -- fail Nothing
[edit] SKIP
skip :: Int -> String -> TAP () -- skip nbTests reason
skipIf :: Bool -> Int -> String -> TAP a -> TAP () -- skipIf condition nbTests reason $ do -- ...
[edit] TODO
toDo :: String -> TAP a -> TAP () -- toDo description $ do -- ...
[edit] OTHER
runTests :: TAP a -> IO (a, TAPState) -- runTests $ do -- ...
diag :: String -> TAP () -- diag msg
bailOut :: String -> TAP a -- bailOut
[edit] EXAMPLE
import TAP
main = runTests $ do
planTests 6
let name = "Arthur Dent"
let answer = 42
let question = "Unknown"
is answer 42 $ Just "The Answer to Life, the Universe, and Everything"
like question "no" Nothing
skip 1 "for Marvin"
skipIf (name == "Arthur Dent") 2 "Arthur Ok" $ do
pass $ Just "Freebie"
TAP.fail Nothing -- conflicts with Prelude.fail
toDo "in 10 millions years" $ do
diag "check question"
is question "answered" $ Just "wondering"
-- Patrick LeBoutillier <patl@cpan.org>

