File: PackageDBsSpec.hs

package info (click to toggle)
haskell-doctest 0.22.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: haskell: 3,148; makefile: 5; ansic: 3
file content (40 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module PackageDBsSpec (main, spec) where

import           Imports

import qualified Control.Exception         as E
import           Data.List                 (intercalate)
import           PackageDBs
import           System.Environment
import           System.FilePath           (searchPathSeparator)
import           Test.Hspec

import           Test.Mockery.Directory

main :: IO ()
main = hspec spec

withEnv :: String -> String -> IO a -> IO a
withEnv k v action = E.bracket save restore $ \_ -> do
  setEnv k v >> action
  where
    save    = lookup k <$> getEnvironment
    restore = maybe (unsetEnv k) (setEnv k)

clearEnv :: IO a -> IO a
clearEnv =
    withEnv "GHC_PACKAGE_PATH" ""

combineDirs :: [FilePath] -> String
combineDirs = intercalate [searchPathSeparator]

spec :: Spec
spec = around_ clearEnv $ do
  describe "getPackageDBsFromEnv" $ do
    around_ (inTempDirectory) $ do
      it "uses global and user when no env used" $ do
        getPackageDBsFromEnv `shouldReturn` PackageDBs True True []

      it "respects GHC_PACKAGE_PATH" $
        withEnv "GHC_PACKAGE_PATH" (combineDirs ["foo", "bar", ""]) $ do
          getPackageDBsFromEnv `shouldReturn` PackageDBs False True ["foo", "bar"]