Added an option to TestMain to support outputting plain text as test output rather than the normal TT-erase scheme
This commit is contained in:
parent
0e35f5cd38
commit
df4c0ed1e7
39
TestMain.hs
39
TestMain.hs
|
@ -42,6 +42,7 @@ module TestMain () where
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
import System.Environment
|
import System.Environment
|
||||||
|
import System.IO
|
||||||
import Test.HUnit
|
import Test.HUnit
|
||||||
|
|
||||||
import qualified ArrayUsageCheckTest (qcTests)
|
import qualified ArrayUsageCheckTest (qcTests)
|
||||||
|
@ -57,19 +58,29 @@ import qualified RainUsageCheckTest (tests)
|
||||||
import TestUtils
|
import TestUtils
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
|
data TestOption =
|
||||||
|
QC (Either String (Maybe QuickCheckLevel))
|
||||||
|
| OutputType Bool -- True is plain, False is erasing
|
||||||
|
|
||||||
-- We run all the HUnit tests before all the QuickCheck tests.
|
-- We run all the HUnit tests before all the QuickCheck tests.
|
||||||
-- We run them apart so that the output from QuickCheck doesn't get
|
-- We run them apart so that the output from QuickCheck doesn't get
|
||||||
-- confusing by being amongst the HUnit output,
|
-- confusing by being amongst the HUnit output,
|
||||||
-- and we run HUnit first because these are typically the more
|
-- and we run HUnit first because these are typically the more
|
||||||
-- interesting (and most worked on tests) so we see failures earlier.
|
-- interesting (and most worked on tests) so we see failures earlier.
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do opts <- getArgs >>* getOpt RequireOrder options
|
main = do (opts, nonOpts, errs) <- getArgs >>* getOpt RequireOrder options
|
||||||
qcLevel <- case opts of
|
when (not $ null errs) $ err (concat errs)
|
||||||
([Right level], [], []) -> return level
|
when (not $ null nonOpts) $ err ("Options not recognised: " ++ concat nonOpts)
|
||||||
([Left unknownLevel], [], []) -> err ("Unknown level: " ++ unknownLevel)
|
qcLevel <- case findLevel opts of
|
||||||
(_,_,errs) -> err (concat errs)
|
Right level -> return level
|
||||||
|
Left unknownLevel -> err ("Unknown level: " ++ unknownLevel)
|
||||||
|
let testType = case findType opts of
|
||||||
|
Just True -> True
|
||||||
|
_ -> False
|
||||||
|
|
||||||
hunitTests >>= runTestTT
|
hunitTests >>= if testType
|
||||||
|
then liftM fst . runTestText (putTextToHandle stdout False)
|
||||||
|
else runTestTT
|
||||||
case qcLevel of
|
case qcLevel of
|
||||||
-- Monadic mess!
|
-- Monadic mess!
|
||||||
Just level -> join $ liftM sequence_ $ (liftM $ applyAll level) qcTests
|
Just level -> join $ liftM sequence_ $ (liftM $ applyAll level) qcTests
|
||||||
|
@ -78,10 +89,20 @@ main = do opts <- getArgs >>* getOpt RequireOrder options
|
||||||
err msg = ioError (userError (msg ++ usageInfo header options))
|
err msg = ioError (userError (msg ++ usageInfo header options))
|
||||||
header = "Usage: tocktest [OPTION..]"
|
header = "Usage: tocktest [OPTION..]"
|
||||||
options = [Option [] ["qc","quickcheck"]
|
options = [Option [] ["qc","quickcheck"]
|
||||||
(ReqArg matchLevel "LEVEL (off, low, medium, high, extensive)") "QuickCheck level"]
|
(ReqArg matchLevel "LEVEL (off, low, medium, high, extensive)") "QuickCheck level"
|
||||||
|
,Option [] ["plain"] (NoArg (OutputType True)) "Show the test output as plain text"]
|
||||||
|
|
||||||
|
findLevel :: [TestOption] -> Either String (Maybe QuickCheckLevel)
|
||||||
|
findLevel (QC qc:_) = qc
|
||||||
|
findLevel (_:os) = findLevel os
|
||||||
|
|
||||||
|
findType :: [TestOption] -> Maybe Bool
|
||||||
|
findType (OutputType t:_) = Just t
|
||||||
|
findType (_:os) = findType os
|
||||||
|
findType [] = Nothing
|
||||||
|
|
||||||
matchLevel :: String -> Either String (Maybe QuickCheckLevel)
|
matchLevel :: String -> TestOption
|
||||||
matchLevel s = case s of
|
matchLevel s = QC $ case s of
|
||||||
"off" -> Right Nothing
|
"off" -> Right Nothing
|
||||||
"low" -> Right $ Just QC_Low
|
"low" -> Right $ Just QC_Low
|
||||||
"medium" -> Right $ Just QC_Medium
|
"medium" -> Right $ Just QC_Medium
|
||||||
|
|
Loading…
Reference in New Issue
Block a user