X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/ebf380646857819d447b10dd36f82edffc9bea00..13f2321cc5e852dd2183faa1de1c5e14569a5599:/htools/test.hs diff --git a/htools/test.hs b/htools/test.hs index 0e51db5..6e43427 100644 --- a/htools/test.hs +++ b/htools/test.hs @@ -4,7 +4,7 @@ {- -Copyright (C) 2009, 2011 Google Inc. +Copyright (C) 2009, 2011, 2012 Google Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,11 +28,12 @@ module Main(main) where import Data.Char import Data.IORef import Data.List -import Test.QuickCheck +import Data.Maybe (fromMaybe) import System.Console.GetOpt () -import System.IO +import System.Environment (getArgs) import System.Exit -import System (getArgs) +import System.IO +import Test.QuickCheck import Text.Printf import Ganeti.HTools.QC @@ -46,6 +47,7 @@ options = , oVerbose , oShowVer , oShowHelp + , oTestCount ] fast :: Args @@ -115,10 +117,15 @@ allTests = , (fast, testInstance) , (fast, testNode) , (fast, testText) + , (fast, testSimu) , (fast, testOpCodes) , (fast, testJobs) , (fast, testLoader) , (fast, testTypes) + , (fast, testCLI) + , (fast, testJSON) + , (fast, testLUXI) + , (fast, testSsconf) , (slow, testCluster) ] @@ -136,39 +143,41 @@ transformTestOpts args opts = do Nothing -> return Nothing Just str -> do let vs = sepSplit ',' str - (case vs of - [rng, size] -> return $ Just (read rng, read size) - _ -> fail "Invalid state given") - return args { chatty = optVerbose opts > 1, - replay = r + case vs of + [rng, size] -> return $ Just (read rng, read size) + _ -> fail "Invalid state given" + return args { chatty = optVerbose opts > 1 + , replay = r + , maxSuccess = fromMaybe (maxSuccess args) (optTestCount opts) + , maxDiscard = fromMaybe (maxDiscard args) (optTestCount opts) } main :: IO () main = do errs <- newIORef 0 let wrap = map (wrapTest errs) - cmd_args <- System.getArgs + cmd_args <- getArgs (opts, args) <- parseOpts cmd_args "test" options - tests <- (if null args - then return allTests - else (let args' = map lower args - selected = filter ((`elem` args') . lower . - extractName) allTests - in if null selected - then do - hPutStrLn stderr $ "No tests matching '" - ++ intercalate " " args ++ "', available tests: " - ++ intercalate ", " (map extractName allTests) - exitWith $ ExitFailure 1 - else return selected)) + tests <- if null args + then return allTests + else let args' = map lower args + selected = filter ((`elem` args') . lower . + extractName) allTests + in if null selected + then do + hPutStrLn stderr $ "No tests matching '" + ++ unwords args ++ "', available tests: " + ++ intercalate ", " (map extractName allTests) + exitWith $ ExitFailure 1 + else return selected let max_count = maximum $ map (\(_, (_, t)) -> length t) tests mapM_ (\(targs, (name, tl)) -> transformTestOpts targs opts >>= \newargs -> runTests name newargs (wrap tl) max_count) tests terr <- readIORef errs - (if terr > 0 - then do - hPutStrLn stderr $ "A total of " ++ show terr ++ " tests failed." - exitWith $ ExitFailure 1 - else putStrLn "All tests succeeded.") + if terr > 0 + then do + hPutStrLn stderr $ "A total of " ++ show terr ++ " tests failed." + exitWith $ ExitFailure 1 + else putStrLn "All tests succeeded."