test for Cradle.
This commit is contained in:
parent
b7cacee767
commit
89dc02f185
2
Types.hs
2
Types.hs
@ -69,7 +69,7 @@ data Cradle = Cradle {
|
||||
, cradleCabalDir :: Maybe FilePath
|
||||
, cradleCabalFile :: Maybe FilePath
|
||||
, cradlePackageConf :: Maybe FilePath
|
||||
} deriving Show
|
||||
} deriving (Eq, Show)
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
|
@ -11,7 +11,7 @@ spec :: Spec
|
||||
spec = do
|
||||
describe "checkSyntax" $ do
|
||||
it "can check even if an executable depends on its library" $ do
|
||||
withDirectory "test/data/ghc-mod-check" $ do
|
||||
withDirectory_ "test/data/ghc-mod-check" $ do
|
||||
(strVer,_) <- getGHCVersion
|
||||
cradle <- findCradle Nothing strVer
|
||||
res <- checkSyntax defaultOptions cradle "main.hs"
|
||||
|
27
test/CradleSpec.hs
Normal file
27
test/CradleSpec.hs
Normal file
@ -0,0 +1,27 @@
|
||||
module CradleSpec where
|
||||
|
||||
import Cradle
|
||||
import Expectation
|
||||
import System.Directory
|
||||
import Test.Hspec
|
||||
import Types
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "findCradle" $ do
|
||||
it "returns the current directory" $ do
|
||||
withDirectory_ "/" $
|
||||
findCradle Nothing "7.4.1" `shouldReturn` Cradle {cradleCurrentDir = "/", cradleCabalDir = Nothing, cradleCabalFile = Nothing, cradlePackageConf = Nothing}
|
||||
|
||||
it "finds a cabal file" $ do
|
||||
withDirectory "test/data/subdir1/subdir2" $ \dir ->
|
||||
findCradle Nothing "7.4.1" `shouldReturn` Cradle {cradleCurrentDir = "/Users/kazu/work/ghc-mod/test/data", cradleCabalDir = Just "/Users/kazu/work/ghc-mod/test/data", cradleCabalFile = Just "/Users/kazu/work/ghc-mod/test/data/cabalapi.cabal", cradlePackageConf = Nothing}
|
||||
|
||||
it "finds a sandbox" $ do
|
||||
withDirectory "test/data/subdir1/subdir2" $ \dir ->
|
||||
findCradle Nothing "7.6.2" `shouldReturn` Cradle {cradleCurrentDir = "/Users/kazu/work/ghc-mod/test/data", cradleCabalDir = Just "/Users/kazu/work/ghc-mod/test/data", cradleCabalFile = Just "/Users/kazu/work/ghc-mod/test/data/cabalapi.cabal", cradlePackageConf = Just "/Users/kazu/work/ghc-mod/test/data/cabal-dev/packages-7.6.2.conf"}
|
||||
|
||||
it "finds a sandbox if exists" $ do
|
||||
withDirectory "/" $ \dir ->
|
||||
findCradle (Just "/Users/kazu/work/ghc-mod/test/data/cabal-dev") "7.6.2" `shouldReturn` Cradle {cradleCurrentDir = "/", cradleCabalDir = Nothing, cradleCabalFile = Nothing, cradlePackageConf = Just "/Users/kazu/work/ghc-mod/test/data/cabal-dev/packages-7.6.2.conf"}
|
||||
|
@ -9,7 +9,12 @@ shouldContain containers element = do
|
||||
let res = element `elem` containers
|
||||
res `shouldBe` True
|
||||
|
||||
withDirectory :: FilePath -> IO a -> IO a
|
||||
withDirectory dir action = bracket getCurrentDirectory
|
||||
withDirectory_ :: FilePath -> IO a -> IO a
|
||||
withDirectory_ dir action = bracket getCurrentDirectory
|
||||
setCurrentDirectory
|
||||
(\_ -> setCurrentDirectory dir >> action)
|
||||
|
||||
withDirectory :: FilePath -> (FilePath -> IO a) -> IO a
|
||||
withDirectory dir action = bracket getCurrentDirectory
|
||||
setCurrentDirectory
|
||||
(\d -> setCurrentDirectory dir >> action d)
|
||||
|
@ -11,7 +11,7 @@ spec :: Spec
|
||||
spec = do
|
||||
describe "typeExpr" $ do
|
||||
it "shows types of the expression and its outers" $ do
|
||||
withDirectory "test/data/ghc-mod-check" $ do
|
||||
withDirectory_ "test/data/ghc-mod-check" $ do
|
||||
(strVer,_) <- getGHCVersion
|
||||
cradle <- findCradle Nothing strVer
|
||||
res <- typeExpr defaultOptions cradle "Data.Foo" 9 5 "Data/Foo.hs"
|
||||
|
Loading…
Reference in New Issue
Block a user