Skip to content
Snippets Groups Projects
Commit 38f536cb authored by Iustin Pop's avatar Iustin Pop
Browse files

Make the test suite return an reasonable exit code

Test.QuickCheck.Batch.runTests doesn't return any error statistics,
which makes the test suite just display errorrs and always exit with
exit code 0. This is not good, since one cannot then actually batch run
tests.

This patch adds a wrapper over Batch.run which also modifies a passed
IORef Int to keep track of how many test failures or test aborts we had.
This makes it easy then to exit with an appropriate exit code.
parent fbb95f28
No related branches found
No related tags found
No related merge requests found
......@@ -25,18 +25,49 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Main(main) where
import Control.Monad
import Data.IORef
import Test.QuickCheck.Batch
import System.IO
import System.Exit
import Ganeti.HTools.QC
options :: TestOptions
options = TestOptions
{ no_of_tests = 500
, length_of_tests = 5
, debug_tests = False }
incIORef :: IORef Int -> IO ()
incIORef ir = atomicModifyIORef ir (\x -> (x + 1, ()))
-- | Wrapper over a test runner with error counting
wrapTest :: IORef Int
-> (TestOptions -> IO TestResult)
-> TestOptions -> IO TestResult
wrapTest ir t to = do
tr <- t to
case tr of
TestFailed _ _ -> incIORef ir
TestAborted _ -> incIORef ir
_ -> return ()
return tr
main :: IO ()
main = do
runTests "PeerMap" options test_PeerMap
runTests "Container" options test_Container
runTests "Instance" options test_Instance
runTests "Node" options test_Node
runTests "Text" options test_Text
runTests "Cluster" options test_Cluster
errs <- newIORef 0
let wrap lst = map (wrapTest errs) lst
runTests "PeerMap" options $ wrap test_PeerMap
runTests "Container" options $ wrap test_Container
runTests "Instance" options $ wrap test_Instance
runTests "Node" options $ wrap test_Node
runTests "Text" options $ wrap test_Text
runTests "Cluster" options $ wrap test_Cluster
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.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment