Files
hpath/test/HPath/IO/CanonicalizePathSpec.hs

79 lines
1.7 KiB
Haskell
Raw Normal View History

2016-05-09 16:53:31 +02:00
{-# LANGUAGE OverloadedStrings #-}
module HPath.IO.CanonicalizePathSpec where
import Test.Hspec
import System.IO.Error
(
ioeGetErrorType
)
import GHC.IO.Exception
(
IOErrorType(..)
)
import Utils
2016-06-05 14:33:53 +02:00
upTmpDir :: IO ()
upTmpDir = do
setTmpDir "CanonicalizePathSpec"
createTmpDir
setupFiles :: IO ()
setupFiles = do
createRegularFile' "file"
createDir' "dir"
createSymlink' "dirSym" "dir/"
createSymlink' "brokenSym" "nothing"
createSymlink' "fileSym" "file"
cleanupFiles :: IO ()
cleanupFiles = do
deleteFile' "file"
deleteDir' "dir"
deleteFile' "dirSym"
deleteFile' "brokenSym"
deleteFile' "fileSym"
2016-05-09 16:53:31 +02:00
spec :: Spec
2016-06-05 15:25:57 +02:00
spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
2016-05-09 16:53:31 +02:00
describe "HPath.IO.canonicalizePath" $ do
-- successes --
it "canonicalizePath, all fine" $ do
path <- withTmpDir "file" return
canonicalizePath' "file"
2016-05-09 16:53:31 +02:00
`shouldReturn` path
it "canonicalizePath, all fine" $ do
path <- withTmpDir "dir" return
canonicalizePath' "dir"
2016-05-09 16:53:31 +02:00
`shouldReturn` path
it "canonicalizePath, all fine" $ do
path <- withTmpDir "file" return
canonicalizePath' "fileSym"
2016-05-09 16:53:31 +02:00
`shouldReturn` path
it "canonicalizePath, all fine" $ do
path <- withTmpDir "dir" return
canonicalizePath' "dirSym"
2016-05-09 16:53:31 +02:00
`shouldReturn` path
-- posix failures --
it "canonicalizePath, broken symlink" $
canonicalizePath' "brokenSym"
2016-05-09 16:53:31 +02:00
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)
it "canonicalizePath, file does not exist" $
canonicalizePath' "nothingBlah"
2016-05-09 16:53:31 +02:00
`shouldThrow`
(\e -> ioeGetErrorType e == NoSuchThing)