Add 'test' command for running QuickCheck props
This commit is contained in:
43
Language/Haskell/GhcMod/Test.hs
Normal file
43
Language/Haskell/GhcMod/Test.hs
Normal file
@@ -0,0 +1,43 @@
|
||||
module Language.Haskell.GhcMod.Test where
|
||||
|
||||
import Data.List
|
||||
import System.FilePath
|
||||
import System.Directory
|
||||
|
||||
import Language.Haskell.GhcMod.Types
|
||||
import Language.Haskell.GhcMod.Monad
|
||||
import Language.Haskell.GhcMod.DynFlags
|
||||
|
||||
import GHC --(ModSummary(..), ModLocation(..), moduleName, findModule)
|
||||
import GHC.Exception
|
||||
import OccName
|
||||
|
||||
test :: IOish m
|
||||
=> FilePath -> GhcModT m String
|
||||
test f = runGmlT' [Left f] (return . setHscInterpreted) $ do
|
||||
mg <- getModuleGraph
|
||||
root <- cradleRootDir <$> cradle
|
||||
f' <- makeRelative root <$> liftIO (canonicalizePath f)
|
||||
let Just ms = find ((==Just f') . ml_hs_file . ms_location) mg
|
||||
mdl = ms_mod ms
|
||||
mn = moduleName mdl
|
||||
|
||||
Just mi <- getModuleInfo mdl
|
||||
let exs = map (occNameString . getOccName) $ modInfoExports mi
|
||||
cqs = filter ("prop_" `isPrefixOf`) exs
|
||||
|
||||
setContext [ IIDecl $ simpleImportDecl mn
|
||||
, IIDecl $ simpleImportDecl $ mkModuleName "Test.QuickCheck"
|
||||
]
|
||||
|
||||
_res <- mapM runTest cqs
|
||||
|
||||
return ""
|
||||
|
||||
runTest :: GhcMonad m => String -> m (Maybe SomeException)
|
||||
runTest fn = do
|
||||
res <- runStmt ("quickCheck " ++ fn) RunToCompletion
|
||||
return $ case res of
|
||||
RunOk [] -> Nothing
|
||||
RunException se -> Just se
|
||||
_ -> error "runTest"
|
||||
Reference in New Issue
Block a user