2017-05-28 02:22:56 +00:00
|
|
|
module GhcMod.Exe.Test where
|
2015-12-15 23:25:15 +00:00
|
|
|
|
2015-12-16 20:45:16 +00:00
|
|
|
import Control.Applicative
|
2015-12-15 23:25:15 +00:00
|
|
|
import Data.List
|
|
|
|
import System.FilePath
|
|
|
|
import System.Directory
|
2015-12-16 20:45:16 +00:00
|
|
|
import Prelude
|
2015-12-15 23:25:15 +00:00
|
|
|
|
2017-05-28 02:22:56 +00:00
|
|
|
import GhcMod.Types
|
|
|
|
import GhcMod.Monad
|
|
|
|
import GhcMod.DynFlags
|
2015-12-15 23:25:15 +00:00
|
|
|
|
2015-12-16 20:45:16 +00:00
|
|
|
import GHC
|
2015-12-15 23:25:15 +00:00
|
|
|
import GHC.Exception
|
|
|
|
import OccName
|
|
|
|
|
|
|
|
test :: IOish m
|
|
|
|
=> FilePath -> GhcModT m String
|
2015-12-28 12:59:59 +00:00
|
|
|
test f = runGmlT' [Left f] (fmap setHscInterpreted . deferErrors) $ do
|
2015-12-15 23:25:15 +00:00
|
|
|
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"
|