Revision 509809db htools/test.hs

b/htools/test.hs
27 27

  
28 28
import Data.IORef
29 29
import Test.QuickCheck
30
import System.Console.GetOpt
30 31
import System.IO
31 32
import System.Exit
32 33
import System (getArgs)
33 34
import Text.Printf
34 35

  
35 36
import Ganeti.HTools.QC
37
import Ganeti.HTools.CLI
38
import Ganeti.HTools.Utils (sepSplit)
39

  
40
-- | Options list and functions
41
options :: [OptType]
42
options =
43
    [ oReplay
44
    , oVerbose
45
    , oShowVer
46
    , oShowHelp
47
    ]
36 48

  
37 49
fast :: Args
38 50
fast = stdArgs
......
101 113
  , ("Cluster", slow, testCluster)
102 114
  ]
103 115

  
116
transformTestOpts :: Args -> Options -> IO Args
117
transformTestOpts args opts = do
118
  r <- case optReplay opts of
119
         Nothing -> return Nothing
120
         Just str -> do
121
           let vs = sepSplit ',' str
122
           (case vs of
123
              [rng, size] -> return $ Just (read rng, read size)
124
              _ -> fail "Invalid state given")
125
  return args { chatty = optVerbose opts > 1,
126
                replay = r
127
              }
128

  
104 129
main :: IO ()
105 130
main = do
106 131
  errs <- newIORef 0
107 132
  let wrap = map (wrapTest errs)
108
  args <- getArgs
133
  cmd_args <- System.getArgs
134
  (opts, args) <- parseOpts cmd_args "test" options
109 135
  let tests = if null args
110 136
              then allTests
111 137
              else filter (\(name, _, _) -> name `elem` args) allTests
112 138
      max_count = maximum $ map (\(_, _, t) -> length t) tests
113
  mapM_ (\(name, opts, tl) -> runTests name opts (wrap tl) max_count) tests
139
  mapM_ (\(name, targs, tl) ->
140
             transformTestOpts targs opts >>= \newargs ->
141
             runTests name newargs (wrap tl) max_count) tests
114 142
  terr <- readIORef errs
115 143
  (if terr > 0
116 144
   then do

Also available in: Unified diff