2013-10-05 03:19:30 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2013-02-13 07:22:07 +00:00
|
|
|
module InfoSpec where
|
|
|
|
|
2013-10-05 03:08:17 +00:00
|
|
|
import Control.Applicative ((<$>))
|
2013-03-14 14:24:36 +00:00
|
|
|
import Data.List (isPrefixOf)
|
2013-05-20 02:29:44 +00:00
|
|
|
import Language.Haskell.GhcMod
|
2013-09-21 09:37:33 +00:00
|
|
|
import Language.Haskell.GhcMod.Cradle
|
2013-10-07 07:39:54 +00:00
|
|
|
#if __GLASGOW_HASKELL__ < 706
|
2013-10-05 03:19:30 +00:00
|
|
|
import System.Environment.Executable (getExecutablePath)
|
|
|
|
#else
|
2013-10-05 03:08:17 +00:00
|
|
|
import System.Environment (getExecutablePath)
|
2013-10-05 03:19:30 +00:00
|
|
|
#endif
|
2013-03-31 13:55:37 +00:00
|
|
|
import System.Exit
|
2013-10-05 03:08:17 +00:00
|
|
|
import System.FilePath
|
2013-05-20 02:29:44 +00:00
|
|
|
import System.Process
|
|
|
|
import Test.Hspec
|
2013-02-13 07:22:07 +00:00
|
|
|
|
2013-09-03 02:49:35 +00:00
|
|
|
import Dir
|
|
|
|
|
2013-02-13 07:22:07 +00:00
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
|
|
|
describe "typeExpr" $ do
|
|
|
|
it "shows types of the expression and its outers" $ do
|
2013-03-05 01:22:33 +00:00
|
|
|
withDirectory_ "test/data/ghc-mod-check" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2014-04-11 02:51:25 +00:00
|
|
|
res <- typeExpr defaultOptions cradle "Data/Foo.hs" 9 5
|
2013-02-13 07:22:07 +00:00
|
|
|
res `shouldBe` "9 5 11 40 \"Int -> a -> a -> a\"\n7 1 11 40 \"Int -> Integer\"\n"
|
2013-03-14 14:24:36 +00:00
|
|
|
|
|
|
|
it "works with a module using TemplateHaskell" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2014-04-11 02:51:25 +00:00
|
|
|
res <- typeExpr defaultOptions cradle "Bar.hs" 5 1
|
2013-03-14 14:24:36 +00:00
|
|
|
res `shouldBe` unlines ["5 1 5 20 \"[Char]\""]
|
|
|
|
|
|
|
|
it "works with a module that imports another module using TemplateHaskell" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2014-04-11 02:51:25 +00:00
|
|
|
res <- typeExpr defaultOptions cradle "Main.hs" 3 8
|
2013-03-14 14:24:36 +00:00
|
|
|
res `shouldBe` unlines ["3 8 3 16 \"String -> IO ()\"", "3 8 3 20 \"IO ()\"", "3 1 3 20 \"IO ()\""]
|
|
|
|
|
|
|
|
describe "infoExpr" $ do
|
2013-03-30 12:24:57 +00:00
|
|
|
it "works for non-export functions" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2014-04-11 02:51:25 +00:00
|
|
|
res <- infoExpr defaultOptions cradle "Info.hs" "fib"
|
2013-03-30 12:24:57 +00:00
|
|
|
res `shouldSatisfy` ("fib :: Int -> Int" `isPrefixOf`)
|
2013-04-01 05:19:15 +00:00
|
|
|
|
2013-03-14 14:24:36 +00:00
|
|
|
it "works with a module using TemplateHaskell" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2014-04-11 02:51:25 +00:00
|
|
|
res <- infoExpr defaultOptions cradle "Bar.hs" "foo"
|
2013-03-14 14:24:36 +00:00
|
|
|
res `shouldSatisfy` ("foo :: ExpQ" `isPrefixOf`)
|
|
|
|
|
|
|
|
it "works with a module that imports another module using TemplateHaskell" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2014-04-11 02:51:25 +00:00
|
|
|
res <- infoExpr defaultOptions cradle "Main.hs" "bar"
|
2013-03-14 14:24:36 +00:00
|
|
|
res `shouldSatisfy` ("bar :: [Char]" `isPrefixOf`)
|
2013-03-31 13:55:37 +00:00
|
|
|
|
|
|
|
it "doesn't fail on unicode output" $ do
|
2013-10-05 03:08:17 +00:00
|
|
|
dir <- getDistDir
|
|
|
|
code <- rawSystem (dir </> "build/ghc-mod/ghc-mod") ["info", "test/data/Unicode.hs", "Unicode", "unicode"]
|
2013-03-31 13:55:37 +00:00
|
|
|
code `shouldSatisfy` (== ExitSuccess)
|
2013-10-05 03:08:17 +00:00
|
|
|
|
|
|
|
getDistDir :: IO FilePath
|
|
|
|
getDistDir = takeDirectory . takeDirectory . takeDirectory <$> getExecutablePath
|