status: working, IO not yet implemented
This commit is contained in:
commit
188d6dbbe5
14 changed files with 1333 additions and 0 deletions
36
test/Test/TemplateStuff.hs
Normal file
36
test/Test/TemplateStuff.hs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
module Test.TemplateStuff (mkSimpleCheck) where
|
||||
|
||||
import Distribution.TestSuite (TestInstance (TestInstance, name, options, run, setOption, tags))
|
||||
import Language.Haskell.TH (Dec, Name, Pat, Q, conT, mkName, normalB, pprint, sigD, valD, varE, varP)
|
||||
|
||||
mkSimpleCheck :: String -> Name -> String -> Q Pat -> String -> Q [Dec]
|
||||
mkSimpleCheck fn p str qv n = do
|
||||
let funName = mkName fn
|
||||
v <- qv
|
||||
let strv = pprint v
|
||||
sig <- sigD funName (conT ''TestInstance)
|
||||
def <-
|
||||
valD
|
||||
(varP funName)
|
||||
( normalB
|
||||
[|
|
||||
TestInstance
|
||||
{ run =
|
||||
return $
|
||||
Finished
|
||||
( case runParser $(varE p) str of
|
||||
Just $(pure v) -> Pass
|
||||
Just o -> Fail $ "expected " ++ strv ++ ", got " ++ show o ++ " instead"
|
||||
Nothing -> Error "runParser failed and returned no output"
|
||||
),
|
||||
name = n,
|
||||
tags = [],
|
||||
options = [],
|
||||
setOption = const $ const $ Right $(varE funName)
|
||||
}
|
||||
|]
|
||||
)
|
||||
[]
|
||||
pure [sig, def]
|
||||
Loading…
Add table
Add a link
Reference in a new issue