root / htools / Ganeti / HTools / QCHelper.hs @ 3c3c796e
History | View | Annotate | Download (1.4 kB)
1 |
{-# LANGUAGE TemplateHaskell #-} |
---|---|
2 |
|
3 |
{-| Unittest helpers for ganeti-htools |
4 |
|
5 |
-} |
6 |
|
7 |
{- |
8 |
|
9 |
Copyright (C) 2011 Google Inc. |
10 |
|
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. |
15 |
|
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. |
20 |
|
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 |
24 |
02110-1301, USA. |
25 |
|
26 |
-} |
27 |
|
28 |
module Ganeti.HTools.QCHelper |
29 |
( testSuite |
30 |
) where |
31 |
|
32 |
import Test.QuickCheck |
33 |
import Language.Haskell.TH |
34 |
|
35 |
run :: Testable prop => prop -> Args -> IO Result |
36 |
run = flip quickCheckWithResult |
37 |
|
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)) |]) |
42 |
tdef |
43 |
sigtype <- [t| (String, [(Args -> IO Result, String)]) |] |
44 |
return [ SigD fullname sigtype |
45 |
, ValD (VarP fullname) (NormalB (TupE [LitE (StringL tsname), |
46 |
ListE tests])) [] |
47 |
] |