[英]PutText in haskell HUnit
I have recently been using the HUnit testing framework to run unit tests in haskell. 我最近一直在使用HUnit测试框架在haskell中运行单元测试。
I came across this function PutText and runTestText which takes PutText st as its first argument. 我遇到了这个函数PutText和runTestText,它以PutText st作为第一个参数。
However i am not sure how to use this and would like some help in understanding how to use this? 但是我不确定如何使用此功能,希望对了解如何使用此功能有帮助吗?
A PutText value allows you to customize the way to messages generated from running a test are reported. PutText值允许您自定义报告运行测试所生成的消息的方式。
A simple way to create one is use putTextToHandle stdout True
to output messages to standard out. 创建消息的一种简单方法是使用
putTextToHandle stdout True
将消息输出到标准输出。 The True
parameter means to also emit progress messages. True
参数表示还发出进度消息。
The PutText protocol allows you to maintain state. PutText协议允许您维护状态。 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. runTestText
还返回此状态的最终值,作为返回的元组的第二个组件。
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. 这里的
testCounts
是已运行/通过/失败/等等的测试数量的msgCount
是上次调用PutText函数返回的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.