Bring test suite up to date
This commit is contained in:
parent
417cacbf81
commit
36ed081d54
@ -28,5 +28,5 @@ spec = do
|
|||||||
describe "`browse' in a project directory" $ do
|
describe "`browse' in a project directory" $ do
|
||||||
it "lists symbols defined in a a local module (e.g. `Baz.baz)" $ do
|
it "lists symbols defined in a a local module (e.g. `Baz.baz)" $ do
|
||||||
withDirectory_ "test/data" $ do
|
withDirectory_ "test/data" $ do
|
||||||
syms <- runID $ lines <$> browse "Baz"
|
syms <- runD $ lines <$> browse "Baz"
|
||||||
syms `shouldContain` ["baz"]
|
syms `shouldContain` ["baz"]
|
||||||
|
@ -40,20 +40,45 @@ spec = do
|
|||||||
ghcOptions = ghcOptions res
|
ghcOptions = ghcOptions res
|
||||||
, includeDirs = map (toRelativeDir dir) (includeDirs res)
|
, includeDirs = map (toRelativeDir dir) (includeDirs res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let [fGlobalPkg, fNoUserPkg, fPkg, sb, _] = ghcOptions res'
|
||||||
|
|
||||||
|
sb `shouldSatisfy`
|
||||||
|
isPkgConfDAt (cwd </> "test/data/.cabal-sandbox")
|
||||||
|
|
||||||
if ghcVersion < 706
|
if ghcVersion < 706
|
||||||
then ghcOptions res' `shouldContain` ["-global-package-conf", "-no-user-package-conf","-package-conf",cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"]
|
then do
|
||||||
else ghcOptions res' `shouldContain` ["-global-package-db", "-no-user-package-db","-package-db",cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"]
|
fGlobalPkg `shouldBe` "-global-package-conf"
|
||||||
includeDirs res' `shouldBe` ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"]
|
fNoUserPkg `shouldBe` "-no-user-package-conf"
|
||||||
|
fPkg `shouldBe` "-package-conf"
|
||||||
|
|
||||||
|
else do
|
||||||
|
fGlobalPkg `shouldBe` "-global-package-db"
|
||||||
|
fNoUserPkg `shouldBe` "-no-user-package-db"
|
||||||
|
fPkg `shouldBe` "-package-db"
|
||||||
|
|
||||||
|
includeDirs res' `shouldBe` [
|
||||||
|
"test/data",
|
||||||
|
"test/data/dist/build",
|
||||||
|
"test/data/dist/build/autogen",
|
||||||
|
"test/data/subdir1/subdir2",
|
||||||
|
"test/data/test"]
|
||||||
|
|
||||||
(pkgName `map` depPackages res') `shouldContain` ["Cabal"]
|
(pkgName `map` depPackages res') `shouldContain` ["Cabal"]
|
||||||
|
|
||||||
describe "cabalSourceDirs" $ do
|
describe "cabalSourceDirs" $ do
|
||||||
it "extracts all hs-source-dirs" $ do
|
it "extracts all hs-source-dirs" $ do
|
||||||
crdl <- findCradle' "test/data/check-test-subdir"
|
crdl <- findCradle' "test/data/check-test-subdir"
|
||||||
dirs <- cabalSourceDirs . cabalAllBuildInfo <$> runD (parseCabalFile crdl "test/data/check-test-subdir/check-test-subdir.cabal")
|
let cabalFile = "test/data/check-test-subdir/check-test-subdir.cabal"
|
||||||
|
dirs <- cabalSourceDirs . cabalAllBuildInfo
|
||||||
|
<$> runD (parseCabalFile crdl cabalFile)
|
||||||
|
|
||||||
dirs `shouldBe` ["src", "test"]
|
dirs `shouldBe` ["src", "test"]
|
||||||
|
|
||||||
it "extracts all hs-source-dirs including \".\"" $ do
|
it "extracts all hs-source-dirs including \".\"" $ do
|
||||||
crdl <- findCradle' "test/data/"
|
crdl <- findCradle' "test/data/"
|
||||||
dirs <- cabalSourceDirs . cabalAllBuildInfo <$> runD (parseCabalFile crdl "test/data/cabalapi.cabal")
|
dirs <- cabalSourceDirs . cabalAllBuildInfo
|
||||||
|
<$> runD (parseCabalFile crdl "test/data/cabalapi.cabal")
|
||||||
dirs `shouldBe` [".", "test"]
|
dirs `shouldBe` [".", "test"]
|
||||||
|
|
||||||
describe "cabalAllBuildInfo" $ do
|
describe "cabalAllBuildInfo" $ do
|
||||||
|
@ -14,38 +14,38 @@ spec = do
|
|||||||
describe "checkSyntax" $ do
|
describe "checkSyntax" $ do
|
||||||
it "works even if an executable depends on the library defined in the same cabal file" $ do
|
it "works even if an executable depends on the library defined in the same cabal file" $ do
|
||||||
withDirectory_ "test/data/ghc-mod-check" $ do
|
withDirectory_ "test/data/ghc-mod-check" $ do
|
||||||
res <- runID $ checkSyntax ["main.hs"]
|
res <- runD $ checkSyntax ["main.hs"]
|
||||||
res `shouldBe` "main.hs:5:1:Warning: Top-level binding with no type signature: main :: IO ()\n"
|
res `shouldBe` "main.hs:5:1:Warning: Top-level binding with no type signature: main :: IO ()\n"
|
||||||
|
|
||||||
it "works even if a module imports another module from a different directory" $ do
|
it "works even if a module imports another module from a different directory" $ do
|
||||||
withDirectory_ "test/data/check-test-subdir" $ do
|
withDirectory_ "test/data/check-test-subdir" $ do
|
||||||
res <- runID $ checkSyntax ["test/Bar/Baz.hs"]
|
res <- runD $ checkSyntax ["test/Bar/Baz.hs"]
|
||||||
res `shouldSatisfy` (("test" </> "Foo.hs:3:1:Warning: Top-level binding with no type signature: foo :: [Char]\n") `isSuffixOf`)
|
res `shouldSatisfy` (("test" </> "Foo.hs:3:1:Warning: Top-level binding with no type signature: foo :: [Char]\n") `isSuffixOf`)
|
||||||
|
|
||||||
it "detects cyclic imports" $ do
|
it "detects cyclic imports" $ do
|
||||||
withDirectory_ "test/data" $ do
|
withDirectory_ "test/data" $ do
|
||||||
res <- runID $ checkSyntax ["Mutual1.hs"]
|
res <- runD $ checkSyntax ["Mutual1.hs"]
|
||||||
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
|
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
|
||||||
|
|
||||||
it "works with modules using QuasiQuotes" $ do
|
it "works with modules using QuasiQuotes" $ do
|
||||||
withDirectory_ "test/data" $ do
|
withDirectory_ "test/data" $ do
|
||||||
res <- runID $ checkSyntax ["Baz.hs"]
|
res <- runD $ checkSyntax ["Baz.hs"]
|
||||||
res `shouldSatisfy` ("Baz.hs:5:1:Warning:" `isPrefixOf`)
|
res `shouldSatisfy` ("Baz.hs:5:1:Warning:" `isPrefixOf`)
|
||||||
|
|
||||||
#if __GLASGOW_HASKELL__ >= 708
|
#if __GLASGOW_HASKELL__ >= 708
|
||||||
it "works with modules using PatternSynonyms" $ do
|
it "works with modules using PatternSynonyms" $ do
|
||||||
withDirectory_ "test/data/pattern-synonyms" $ do
|
withDirectory_ "test/data/pattern-synonyms" $ do
|
||||||
res <- runID $ checkSyntax ["B.hs"]
|
res <- runD $ checkSyntax ["B.hs"]
|
||||||
res `shouldSatisfy` ("B.hs:6:9:Warning:" `isPrefixOf`)
|
res `shouldSatisfy` ("B.hs:6:9:Warning:" `isPrefixOf`)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
it "works with foreign exports" $ do
|
it "works with foreign exports" $ do
|
||||||
withDirectory_ "test/data" $ do
|
withDirectory_ "test/data" $ do
|
||||||
res <- runID $ checkSyntax ["ForeignExport.hs"]
|
res <- runD $ checkSyntax ["ForeignExport.hs"]
|
||||||
res `shouldBe` ""
|
res `shouldBe` ""
|
||||||
|
|
||||||
context "when no errors are found" $ do
|
context "when no errors are found" $ do
|
||||||
it "doesn't output an empty line" $ do
|
it "doesn't output an empty line" $ do
|
||||||
withDirectory_ "test/data/ghc-mod-check/Data" $ do
|
withDirectory_ "test/data/ghc-mod-check/Data" $ do
|
||||||
res <- runID $ checkSyntax ["Foo.hs"]
|
res <- runD $ checkSyntax ["Foo.hs"]
|
||||||
res `shouldBe` ""
|
res `shouldBe` ""
|
||||||
|
@ -9,6 +9,7 @@ import System.FilePath ((</>), pathSeparator)
|
|||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
|
|
||||||
import Dir
|
import Dir
|
||||||
|
import TestUtils
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
@ -26,24 +27,37 @@ spec = do
|
|||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
withDirectory "test/data/subdir1/subdir2" $ \dir -> do
|
withDirectory "test/data/subdir1/subdir2" $ \dir -> do
|
||||||
res <- relativeCradle dir <$> findCradle
|
res <- relativeCradle dir <$> findCradle
|
||||||
cradleCurrentDir res `shouldBe` "test" </> "data" </> "subdir1" </> "subdir2"
|
|
||||||
|
cradleCurrentDir res `shouldBe`
|
||||||
|
"test" </> "data" </> "subdir1" </> "subdir2"
|
||||||
|
|
||||||
cradleRootDir res `shouldBe` "test" </> "data"
|
cradleRootDir res `shouldBe` "test" </> "data"
|
||||||
cradleCabalFile res `shouldBe` Just ("test" </> "data" </> "cabalapi.cabal")
|
|
||||||
cradlePkgDbStack res `shouldBe` [GlobalDb, PackageDb (cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d")]
|
cradleCabalFile res `shouldBe`
|
||||||
|
Just ("test" </> "data" </> "cabalapi.cabal")
|
||||||
|
|
||||||
|
let [GlobalDb, sb] = cradlePkgDbStack res
|
||||||
|
sb `shouldSatisfy` isPkgDbAt (cwd </> "test/data/.cabal-sandbox")
|
||||||
|
|
||||||
it "works even if a sandbox config file is broken" $ do
|
it "works even if a sandbox config file is broken" $ do
|
||||||
withDirectory "test/data/broken-sandbox" $ \dir -> do
|
withDirectory "test/data/broken-sandbox" $ \dir -> do
|
||||||
res <- relativeCradle dir <$> findCradle
|
res <- relativeCradle dir <$> findCradle
|
||||||
cradleCurrentDir res `shouldBe` "test" </> "data" </> "broken-sandbox"
|
cradleCurrentDir res `shouldBe`
|
||||||
cradleRootDir res `shouldBe` "test" </> "data" </> "broken-sandbox"
|
"test" </> "data" </> "broken-sandbox"
|
||||||
cradleCabalFile res `shouldBe` Just ("test" </> "data" </> "broken-sandbox" </> "dummy.cabal")
|
|
||||||
|
cradleRootDir res `shouldBe`
|
||||||
|
"test" </> "data" </> "broken-sandbox"
|
||||||
|
|
||||||
|
cradleCabalFile res `shouldBe`
|
||||||
|
Just ("test" </> "data" </> "broken-sandbox" </> "dummy.cabal")
|
||||||
|
|
||||||
cradlePkgDbStack res `shouldBe` [GlobalDb, UserDb]
|
cradlePkgDbStack res `shouldBe` [GlobalDb, UserDb]
|
||||||
|
|
||||||
relativeCradle :: FilePath -> Cradle -> Cradle
|
relativeCradle :: FilePath -> Cradle -> Cradle
|
||||||
relativeCradle dir cradle = cradle {
|
relativeCradle dir crdl = crdl {
|
||||||
cradleCurrentDir = toRelativeDir dir $ cradleCurrentDir cradle
|
cradleCurrentDir = toRelativeDir dir $ cradleCurrentDir crdl
|
||||||
, cradleRootDir = toRelativeDir dir $ cradleRootDir cradle
|
, cradleRootDir = toRelativeDir dir $ cradleRootDir crdl
|
||||||
, cradleCabalFile = toRelativeDir dir <$> cradleCabalFile cradle
|
, cradleCabalFile = toRelativeDir dir <$> cradleCabalFile crdl
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Work around GHC 7.2.2 where `canonicalizePath "/"` returns "/.".
|
-- Work around GHC 7.2.2 where `canonicalizePath "/"` returns "/.".
|
||||||
|
@ -24,7 +24,7 @@ main = do
|
|||||||
genGhcPkgCache dir = system $ "ghc-pkg recache --force -f" ++ dir
|
genGhcPkgCache dir = system $ "ghc-pkg recache --force -f" ++ dir
|
||||||
genSandboxCfg `mapM_` sandboxes
|
genSandboxCfg `mapM_` sandboxes
|
||||||
genGhcPkgCache `mapM_` pkgDirs
|
genGhcPkgCache `mapM_` pkgDirs
|
||||||
void $ system "find test -name setup-config -name ghc-mod.cache -exec rm {} \\;"
|
void $ system "find test \\( -name setup-config -o -name ghc-mod.cache \\) -exec rm {} \\;"
|
||||||
void $ system "cabal --version"
|
void $ system "cabal --version"
|
||||||
putStrLn $ "ghc-mod was built with Cabal version " ++ VERSION_Cabal
|
putStrLn $ "ghc-mod was built with Cabal version " ++ VERSION_Cabal
|
||||||
void $ system "ghc --version"
|
void $ system "ghc --version"
|
||||||
|
@ -3,14 +3,13 @@ module PathsAndFilesSpec where
|
|||||||
|
|
||||||
import Language.Haskell.GhcMod.PathsAndFiles
|
import Language.Haskell.GhcMod.PathsAndFiles
|
||||||
#if __GLASGOW_HASKELL__ <= 706
|
#if __GLASGOW_HASKELL__ <= 706
|
||||||
import Language.Haskell.GhcMod.Types
|
|
||||||
import Language.Haskell.GhcMod.GhcPkg
|
import Language.Haskell.GhcMod.GhcPkg
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.Environment
|
import System.FilePath
|
||||||
import System.FilePath ((</>))
|
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
|
import TestUtils
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
@ -18,25 +17,29 @@ spec = do
|
|||||||
-- ghc < 7.8
|
-- ghc < 7.8
|
||||||
#if __GLASGOW_HASKELL__ <= 706
|
#if __GLASGOW_HASKELL__ <= 706
|
||||||
it "does include a sandbox with ghc < 7.8" $ do
|
it "does include a sandbox with ghc < 7.8" $ do
|
||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
getPackageDbStack "test/data/" `shouldReturn` [GlobalDb, PackageDb $ cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"]
|
[GlobalDb, sbPkgDb] <- getPackageDbStack "test/data/"
|
||||||
|
sbPkgDb `shouldSatisfy` isPkgDbAt (cwd </> "test/data/.cabal-sandbox")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
it "can parse a config file and extract the sandbox package-db" $ do
|
it "can parse a config file and extract the sandbox package-db" $ do
|
||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
pkgDb <- getSandboxDb "test/data/"
|
Just db <- getSandboxDb "test/data/"
|
||||||
pkgDb `shouldBe` Just (cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d")
|
db `shouldSatisfy` isPkgDbAt (cwd </> "test/data/.cabal-sandbox")
|
||||||
|
|
||||||
it "returns Nothing if the sandbox config file is broken" $ do
|
it "returns Nothing if the sandbox config file is broken" $ do
|
||||||
getSandboxDb "test/data/broken-sandbox" `shouldReturn` Nothing
|
getSandboxDb "test/data/broken-sandbox" `shouldReturn` Nothing
|
||||||
|
|
||||||
describe "getCabalFiles" $ do
|
|
||||||
it "doesn't think $HOME/.cabal is a cabal file" $ do
|
|
||||||
(getCabalFiles =<< getEnv "HOME") `shouldReturn` []
|
|
||||||
|
|
||||||
describe "findCabalFile" $ do
|
describe "findCabalFile" $ do
|
||||||
it "works" $ do
|
it "works" $ do
|
||||||
findCabalFile "test/data" `shouldReturn` Just "test/data/cabalapi.cabal"
|
findCabalFile "test/data" `shouldReturn` Just "test/data/cabalapi.cabal"
|
||||||
|
|
||||||
it "finds cabal files in parent directories" $ do
|
it "finds cabal files in parent directories" $ do
|
||||||
findCabalFile "test/data/subdir1/subdir2" `shouldReturn` Just "test/data/cabalapi.cabal"
|
findCabalFile "test/data/subdir1/subdir2" `shouldReturn` Just "test/data/cabalapi.cabal"
|
||||||
|
|
||||||
|
describe "findCabalSandboxDir" $ do
|
||||||
|
it "works" $ do
|
||||||
|
findCabalSandboxDir "test/data" `shouldReturn` Just "test/data"
|
||||||
|
|
||||||
|
it "finds sandboxes in parent directories" $ do
|
||||||
|
findCabalSandboxDir "test/data/subdir1/subdir2" `shouldReturn` Just "test/data"
|
||||||
|
@ -3,10 +3,12 @@ module TestUtils (
|
|||||||
, runD
|
, runD
|
||||||
, runD'
|
, runD'
|
||||||
, runI
|
, runI
|
||||||
, runID
|
-- , runID
|
||||||
, runIsolatedGhcMod
|
, runIsolatedGhcMod
|
||||||
, isolateCradle
|
, isolateCradle
|
||||||
, shouldReturnError
|
, shouldReturnError
|
||||||
|
, isPkgDbAt
|
||||||
|
, isPkgConfDAt
|
||||||
, module Language.Haskell.GhcMod.Monad
|
, module Language.Haskell.GhcMod.Monad
|
||||||
, module Language.Haskell.GhcMod.Types
|
, module Language.Haskell.GhcMod.Types
|
||||||
) where
|
) where
|
||||||
@ -14,6 +16,8 @@ module TestUtils (
|
|||||||
import Language.Haskell.GhcMod.Monad
|
import Language.Haskell.GhcMod.Monad
|
||||||
import Language.Haskell.GhcMod.Types
|
import Language.Haskell.GhcMod.Types
|
||||||
|
|
||||||
|
import Data.List.Split
|
||||||
|
import System.FilePath
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
|
|
||||||
isolateCradle :: IOish m => GhcModT m a -> GhcModT m a
|
isolateCradle :: IOish m => GhcModT m a -> GhcModT m a
|
||||||
@ -34,8 +38,8 @@ runIsolatedGhcMod opt action = do
|
|||||||
extract $ runGhcModT opt $ isolateCradle action
|
extract $ runGhcModT opt $ isolateCradle action
|
||||||
|
|
||||||
-- | Run GhcMod in isolated cradle with default options
|
-- | Run GhcMod in isolated cradle with default options
|
||||||
runID :: GhcModT IO a -> IO a
|
--runID :: GhcModT IO a -> IO a
|
||||||
runID = runIsolatedGhcMod defaultOptions
|
--runID = runIsolatedGhcMod defaultOptions
|
||||||
|
|
||||||
-- | Run GhcMod in isolated cradle
|
-- | Run GhcMod in isolated cradle
|
||||||
runI :: Options -> GhcModT IO a -> IO a
|
runI :: Options -> GhcModT IO a -> IO a
|
||||||
@ -61,3 +65,18 @@ shouldReturnError action = do
|
|||||||
where
|
where
|
||||||
isLeft (Left _) = True
|
isLeft (Left _) = True
|
||||||
isLeft _ = False
|
isLeft _ = False
|
||||||
|
|
||||||
|
isPkgConfD :: FilePath -> Bool
|
||||||
|
isPkgConfD d = let
|
||||||
|
(_dir, pkgconfd) = splitFileName d
|
||||||
|
in case splitOn "-" pkgconfd of
|
||||||
|
[_arch, _platform, _compiler, _compver, "packages.conf.d"] -> True
|
||||||
|
_ -> False
|
||||||
|
|
||||||
|
isPkgConfDAt :: FilePath -> FilePath -> Bool
|
||||||
|
isPkgConfDAt d d' | d == takeDirectory d' && isPkgConfD d' = True
|
||||||
|
isPkgConfDAt _ _ = False
|
||||||
|
|
||||||
|
isPkgDbAt :: FilePath -> GhcPkgDb -> Bool
|
||||||
|
isPkgDbAt d (PackageDb dir) = isPkgConfDAt d dir
|
||||||
|
isPkgDbAt _ _ = False
|
||||||
|
Loading…
Reference in New Issue
Block a user