2013-10-05 03:19:30 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2013-02-13 07:22:07 +00:00
|
|
|
module InfoSpec where
|
|
|
|
|
2015-09-01 08:27:12 +00:00
|
|
|
import Control.Applicative
|
2013-03-14 14:24:36 +00:00
|
|
|
import Data.List (isPrefixOf)
|
2017-01-12 15:36:47 +00:00
|
|
|
import GhcMod
|
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-10-05 03:08:17 +00:00
|
|
|
import System.FilePath
|
2013-05-20 02:29:44 +00:00
|
|
|
import Test.Hspec
|
2014-07-11 01:10:37 +00:00
|
|
|
import TestUtils
|
2015-08-31 06:55:49 +00:00
|
|
|
import Prelude
|
2013-09-03 02:49:35 +00:00
|
|
|
|
2013-02-13 07:22:07 +00:00
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
2014-07-11 01:10:37 +00:00
|
|
|
describe "types" $ do
|
2013-02-13 07:22:07 +00:00
|
|
|
it "shows types of the expression and its outers" $ do
|
2015-03-04 20:48:21 +00:00
|
|
|
let tdir = "test/data/ghc-mod-check"
|
2016-01-19 22:34:58 +00:00
|
|
|
res <- runD' tdir $ types False "lib/Data/Foo.hs" 9 5
|
2016-05-22 00:55:06 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 800
|
|
|
|
res `shouldBe` "9 5 11 40 \"Int -> t -> t -> t\"\n7 1 11 40 \"Int -> Integer\"\n"
|
|
|
|
#else
|
2015-03-04 20:48:21 +00:00
|
|
|
res `shouldBe` "9 5 11 40 \"Int -> a -> a -> a\"\n7 1 11 40 \"Int -> Integer\"\n"
|
2016-05-22 00:55:06 +00:00
|
|
|
#endif
|
|
|
|
|
2013-03-14 14:24:36 +00:00
|
|
|
|
2016-01-19 22:34:58 +00:00
|
|
|
it "shows types of the expression with constraints and its outers" $ do
|
|
|
|
let tdir = "test/data/ghc-mod-check"
|
|
|
|
res <- runD' tdir $ types True "lib/Data/Foo.hs" 9 5
|
2016-05-22 00:55:06 +00:00
|
|
|
#if __GLASGOW_HASKELL__ >= 800
|
|
|
|
res `shouldBe` "9 5 11 40 \"Num t => Int -> t -> t -> t\"\n7 1 11 40 \"Int -> Integer\"\n"
|
|
|
|
#else
|
2016-01-19 22:34:58 +00:00
|
|
|
res `shouldBe` "9 5 11 40 \"Num a => Int -> a -> a -> a\"\n7 1 11 40 \"Int -> Integer\"\n"
|
2016-05-22 00:55:06 +00:00
|
|
|
#endif
|
2016-01-19 22:34:58 +00:00
|
|
|
|
2013-03-14 14:24:36 +00:00
|
|
|
it "works with a module using TemplateHaskell" $ do
|
2015-03-04 20:48:21 +00:00
|
|
|
let tdir = "test/data/template-haskell"
|
2016-01-19 22:34:58 +00:00
|
|
|
res <- runD' tdir $ types False "Bar.hs" 5 1
|
2015-03-04 20:48:21 +00:00
|
|
|
res `shouldBe` unlines ["5 1 5 20 \"[Char]\""]
|
2013-03-14 14:24:36 +00:00
|
|
|
|
|
|
|
it "works with a module that imports another module using TemplateHaskell" $ do
|
2015-03-04 20:48:21 +00:00
|
|
|
let tdir = "test/data/template-haskell"
|
2016-01-19 22:34:58 +00:00
|
|
|
res <- runD' tdir $ types False "ImportsTH.hs" 3 8
|
2015-03-04 20:48:21 +00:00
|
|
|
res `shouldBe` unlines ["3 8 3 16 \"String -> IO ()\"", "3 8 3 20 \"IO ()\"", "3 1 3 20 \"IO ()\""]
|
2013-03-14 14:24:36 +00:00
|
|
|
|
2014-07-11 01:10:37 +00:00
|
|
|
describe "info" $ do
|
2015-03-04 20:48:21 +00:00
|
|
|
it "works for non exported functions" $ do
|
|
|
|
let tdir = "test/data/non-exported"
|
2015-06-01 15:10:37 +00:00
|
|
|
res <- runD' tdir $ info "Fib.hs" $ Expression "fib"
|
2015-03-04 20:48:21 +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
|
2015-03-04 20:48:21 +00:00
|
|
|
let tdir = "test/data/template-haskell"
|
2015-06-01 15:10:37 +00:00
|
|
|
res <- runD' tdir $ info "Bar.hs" $ Expression "foo"
|
2015-03-04 20:48:21 +00:00
|
|
|
res `shouldSatisfy` ("foo :: ExpQ" `isPrefixOf`)
|
2013-03-14 14:24:36 +00:00
|
|
|
|
|
|
|
it "works with a module that imports another module using TemplateHaskell" $ do
|
2015-03-04 20:48:21 +00:00
|
|
|
let tdir = "test/data/template-haskell"
|
2015-06-01 15:10:37 +00:00
|
|
|
res <- runD' tdir $ info "ImportsTH.hs" $ Expression "bar"
|
2015-03-04 20:48:21 +00:00
|
|
|
res `shouldSatisfy` ("bar :: [Char]" `isPrefixOf`)
|
2013-10-05 03:08:17 +00:00
|
|
|
|
|
|
|
getDistDir :: IO FilePath
|
|
|
|
getDistDir = takeDirectory . takeDirectory . takeDirectory <$> getExecutablePath
|