Fix tests

This commit is contained in:
Daniel Gröber 2015-09-08 06:20:12 +02:00
parent 34fedd8ad3
commit 7ae22a9226
5 changed files with 46 additions and 26 deletions

View File

@ -243,6 +243,7 @@ Test-Suite spec
Spec
TestUtils
BrowseSpec
CustomPackageDbSpec
CheckSpec
FlagSpec
InfoSpec

View File

@ -79,25 +79,3 @@ spec = do
let ghcOpts = head opts
pkgs = pkgOptions ghcOpts
pkgs `shouldBe` ["Cabal","base"]
describe "getCustomPkgDbStack" $ do
it "works" $ do
let tdir = "test/data/custom-cradle"
Just stack <- runD' tdir $ getCustomPkgDbStack
stack `shouldBe` [ GlobalDb
, UserDb
, PackageDb "package-db-a"
, PackageDb "package-db-b"
, PackageDb "package-db-c"
]
describe "getPackageDbStack'" $ do
it "fixes out of sync custom pkg-db stack" $ do
withDirectory_ "test/data/custom-cradle" $ do
_ <- system "cabal configure"
(s, s') <- runD $ do
Just stack <- getCustomPkgDbStack
withCabal $ do
stack' <- getCabalPackageDbStack
return (stack, stack')
s' `shouldBe` s

View File

@ -0,0 +1,35 @@
module CustomPackageDbSpec where
import Language.Haskell.GhcMod.CabalHelper
import Language.Haskell.GhcMod.CustomPackageDb
import Language.Haskell.GhcMod.Error
import System.Process
import Test.Hspec
import Prelude
import Dir
import TestUtils
spec :: Spec
spec = do
describe "getCustomPkgDbStack" $ do
it "works" $ do
let tdir = "test/data/custom-cradle"
Just stack <- runD' tdir $ getCustomPkgDbStack
stack `shouldBe` [ GlobalDb
, UserDb
, PackageDb "package-db-a"
, PackageDb "package-db-b"
, PackageDb "package-db-c"
]
describe "getPackageDbStack'" $ do
it "fixes out of sync custom pkg-db stack" $ do
withDirectory_ "test/data/custom-cradle" $ do
_ <- system "cabal configure"
(s, s') <- runD $ do
Just stack <- getCustomPkgDbStack
withCabal $ do
stack' <- getCabalPackageDbStack
return (stack, stack')
s' `shouldBe` s

View File

@ -2,6 +2,7 @@ module GhcPkgSpec where
import Language.Haskell.GhcMod.GhcPkg
import Language.Haskell.GhcMod.CabalHelper
import Language.Haskell.GhcMod.CustomPackageDb
import Test.Hspec
import System.Process (system)

View File

@ -3,6 +3,7 @@ module PathsAndFilesSpec where
import Language.Haskell.GhcMod.PathsAndFiles
import Language.Haskell.GhcMod.Cradle
import qualified Language.Haskell.GhcMod.Utils as U
import Control.Monad.Trans.Maybe
import System.Directory
@ -25,10 +26,12 @@ spec = do
describe "findCabalFile" $ do
it "works" $ do
findCabalFile "test/data/cabal-project" `shouldReturn` Just "test/data/cabal-project/cabalapi.cabal"
p <- U.makeAbsolute' "test/data/cabal-project/cabalapi.cabal"
findCabalFile "test/data/cabal-project" `shouldReturn` Just p
it "finds cabal files in parent directories" $ do
findCabalFile "test/data/cabal-project/subdir1/subdir2" `shouldReturn` Just "test/data/cabal-project/cabalapi.cabal"
p <- U.makeAbsolute' "test/data/cabal-project/cabalapi.cabal"
findCabalFile "test/data/cabal-project/subdir1/subdir2" `shouldReturn` Just p
describe "findStackConfigFile" $ do
it "works" $ do
@ -36,7 +39,9 @@ spec = do
describe "findCabalSandboxDir" $ do
it "works" $ do
findCabalSandboxDir "test/data/cabal-project" `shouldReturn` Just "test/data/cabal-project"
p <- U.makeAbsolute' "test/data/cabal-project/cabalapi.cabal"
findCabalSandboxDir "test/data/cabal-project" `shouldReturn` Just p
it "finds sandboxes in parent directories" $ do
findCabalSandboxDir "test/data/cabal-project/subdir1/subdir2" `shouldReturn` Just "test/data/cabal-project"
p <- U.makeAbsolute' "test/data/cabal-project/"
findCabalSandboxDir "test/data/cabal-project/subdir1/subdir2" `shouldReturn` Just p