1 {-# LANGUAGE TemplateHaskell #-}
3 {-| Unittest helpers for ganeti-htools
9 Copyright (C) 2011 Google Inc.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 module Ganeti.HTools.QCHelper
32 import Test.QuickCheck
33 import Language.Haskell.TH
35 run :: Testable prop => prop -> Args -> IO Result
36 run = flip quickCheckWithResult
38 testSuite :: String -> [Name] -> Q [Dec]
39 testSuite tsname tdef = do
40 let fullname = mkName $ "test" ++ tsname
41 tests <- mapM (\n -> [| (run $(varE n), $(litE . StringL . nameBase $ n)) |])
43 sigtype <- [t| (String, [(Args -> IO Result, String)]) |]
44 return [ SigD fullname sigtype
45 , ValD (VarP fullname) (NormalB (TupE [LitE (StringL tsname),