Merge pull request #108 from eagletmt/more-th-check

info and type sub-commands also need TH check
This commit is contained in:
Kazu Yamamoto 2013-03-14 20:33:18 -07:00
commit 0647819921
2 changed files with 31 additions and 0 deletions

View File

@ -4,6 +4,7 @@
module Info (infoExpr, typeExpr) where
import Control.Applicative
import Control.Monad (when)
import CoreUtils
import Data.Function
import Data.Generics
@ -145,11 +146,15 @@ inModuleContext opt cradle fileName modstr action errmsg =
valid = do
_ <- initializeFlagsWithCradle opt cradle ["-w"] False
setTargetFile fileName
slow <- needsTemplateHaskell <$> depanal [] False
when slow setSlowDynFlags
_ <- load LoadAllTargets
doif setContextFromTarget action
invalid = do
_ <- initializeFlagsWithCradle opt cradle ["-w"] False
setTargetBuffer
slow <- needsTemplateHaskell <$> depanal [] False
when slow setSlowDynFlags
_ <- load LoadAllTargets
doif setContextFromTarget action
setTargetBuffer = do

View File

@ -2,6 +2,7 @@ module InfoSpec where
import CabalApi
import Cradle
import Data.List (isPrefixOf)
import Expectation
import Info
import Test.Hspec
@ -16,3 +17,28 @@ spec = do
cradle <- findCradle Nothing strVer
res <- typeExpr defaultOptions cradle "Data.Foo" 9 5 "Data/Foo.hs"
res `shouldBe` "9 5 11 40 \"Int -> a -> a -> a\"\n7 1 11 40 \"Int -> Integer\"\n"
it "works with a module using TemplateHaskell" $ do
withDirectory_ "test/data" $ do
cradle <- getGHCVersion >>= findCradle Nothing . fst
res <- typeExpr defaultOptions cradle "Bar" 5 1 "Bar.hs"
res `shouldBe` unlines ["5 1 5 20 \"[Char]\""]
it "works with a module that imports another module using TemplateHaskell" $ do
withDirectory_ "test/data" $ do
cradle <- getGHCVersion >>= findCradle Nothing . fst
res <- typeExpr defaultOptions cradle "Main" 3 8 "Main.hs"
res `shouldBe` unlines ["3 8 3 16 \"String -> IO ()\"", "3 8 3 20 \"IO ()\"", "3 1 3 20 \"IO ()\""]
describe "infoExpr" $ do
it "works with a module using TemplateHaskell" $ do
withDirectory_ "test/data" $ do
cradle <- getGHCVersion >>= findCradle Nothing . fst
res <- infoExpr defaultOptions cradle "Bar" "foo" "Bar.hs"
res `shouldSatisfy` ("foo :: ExpQ" `isPrefixOf`)
it "works with a module that imports another module using TemplateHaskell" $ do
withDirectory_ "test/data" $ do
cradle <- getGHCVersion >>= findCradle Nothing . fst
res <- infoExpr defaultOptions cradle "Main" "bar" "Main.hs"
res `shouldSatisfy` ("bar :: [Char]" `isPrefixOf`)