Statistics
| Branch: | Tag: | Revision:

root / test.hs @ 38f536cb

History | View | Annotate | Download (2 kB)

1 9b1e1cc9 Iustin Pop
{-| Unittest runner for ganeti-htools
2 15f4c8ca Iustin Pop
3 15f4c8ca Iustin Pop
-}
4 15f4c8ca Iustin Pop
5 e2fa2baf Iustin Pop
{-
6 e2fa2baf Iustin Pop
7 e2fa2baf Iustin Pop
Copyright (C) 2009 Google Inc.
8 e2fa2baf Iustin Pop
9 e2fa2baf Iustin Pop
This program is free software; you can redistribute it and/or modify
10 e2fa2baf Iustin Pop
it under the terms of the GNU General Public License as published by
11 e2fa2baf Iustin Pop
the Free Software Foundation; either version 2 of the License, or
12 e2fa2baf Iustin Pop
(at your option) any later version.
13 e2fa2baf Iustin Pop
14 e2fa2baf Iustin Pop
This program is distributed in the hope that it will be useful, but
15 e2fa2baf Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
16 e2fa2baf Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 e2fa2baf Iustin Pop
General Public License for more details.
18 e2fa2baf Iustin Pop
19 e2fa2baf Iustin Pop
You should have received a copy of the GNU General Public License
20 e2fa2baf Iustin Pop
along with this program; if not, write to the Free Software
21 e2fa2baf Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 e2fa2baf Iustin Pop
02110-1301, USA.
23 e2fa2baf Iustin Pop
24 e2fa2baf Iustin Pop
-}
25 e2fa2baf Iustin Pop
26 15f4c8ca Iustin Pop
module Main(main) where
27 15f4c8ca Iustin Pop
28 38f536cb Iustin Pop
import Control.Monad
29 38f536cb Iustin Pop
import Data.IORef
30 15f4c8ca Iustin Pop
import Test.QuickCheck.Batch
31 38f536cb Iustin Pop
import System.IO
32 38f536cb Iustin Pop
import System.Exit
33 38f536cb Iustin Pop
34 15f4c8ca Iustin Pop
import Ganeti.HTools.QC
35 15f4c8ca Iustin Pop
36 38f536cb Iustin Pop
options :: TestOptions
37 15f4c8ca Iustin Pop
options = TestOptions
38 15f4c8ca Iustin Pop
      { no_of_tests         = 500
39 15f4c8ca Iustin Pop
      , length_of_tests     = 5
40 15f4c8ca Iustin Pop
      , debug_tests         = False }
41 15f4c8ca Iustin Pop
42 38f536cb Iustin Pop
43 38f536cb Iustin Pop
incIORef :: IORef Int -> IO ()
44 38f536cb Iustin Pop
incIORef ir = atomicModifyIORef ir (\x -> (x + 1, ()))
45 38f536cb Iustin Pop
46 38f536cb Iustin Pop
-- | Wrapper over a test runner with error counting
47 38f536cb Iustin Pop
wrapTest :: IORef Int
48 38f536cb Iustin Pop
         -> (TestOptions -> IO TestResult)
49 38f536cb Iustin Pop
         -> TestOptions -> IO TestResult
50 38f536cb Iustin Pop
wrapTest ir t to = do
51 38f536cb Iustin Pop
    tr <- t to
52 38f536cb Iustin Pop
    case tr of
53 38f536cb Iustin Pop
      TestFailed _ _ -> incIORef ir
54 38f536cb Iustin Pop
      TestAborted _ -> incIORef ir
55 38f536cb Iustin Pop
      _ -> return ()
56 38f536cb Iustin Pop
    return tr
57 38f536cb Iustin Pop
58 38f536cb Iustin Pop
main :: IO ()
59 15f4c8ca Iustin Pop
main = do
60 38f536cb Iustin Pop
  errs <- newIORef 0
61 38f536cb Iustin Pop
  let wrap lst = map (wrapTest errs) lst
62 38f536cb Iustin Pop
  runTests "PeerMap" options $ wrap test_PeerMap
63 38f536cb Iustin Pop
  runTests "Container" options $ wrap test_Container
64 38f536cb Iustin Pop
  runTests "Instance" options $ wrap test_Instance
65 38f536cb Iustin Pop
  runTests "Node" options $ wrap test_Node
66 38f536cb Iustin Pop
  runTests "Text" options $ wrap test_Text
67 38f536cb Iustin Pop
  runTests "Cluster" options $ wrap test_Cluster
68 38f536cb Iustin Pop
  terr <- readIORef errs
69 38f536cb Iustin Pop
  (if (terr > 0)
70 38f536cb Iustin Pop
   then do
71 38f536cb Iustin Pop
     hPutStrLn stderr $ "A total of " ++ show terr ++ " tests failed."
72 38f536cb Iustin Pop
     exitWith $ ExitFailure 1
73 38f536cb Iustin Pop
   else putStrLn "All tests succeeded.")