A PutText value allows you to customize the way to messages generated from running a test are reported.
A simple way to create one is use putTextToHandle stdout True
to output messages to standard out. The True
parameter means to also emit progress messages.
The PutText protocol allows you to maintain state. This is an example of one that keeps track of the number of messages emitted. The final value
of this state is also returned by runTestText
as the second component
of the returned tuple.
reportMsg :: String -> Bool -> Int -> IO Int
reportMsg message isProgress count = do
putStrLn $ "#" ++ show (count+1) ++ ": " ++ message
return (count+1)
myPutText = PutText reportMsg 0 :: PutText Int
And then you can use it like this:
(testCounts, msgCount) <- runTestText myPutText tests
putStrLn $ "Messages emitted: " ++ show msgCount
Here testCounts
is a tally of the number of tests which were run / passed / failed / etc. The msgCount
is the value returned by the last call to the PutText function.