2016-05-09 14:53:31 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module HPath.IO.CanonicalizePathSpec where
|
|
|
|
|
|
|
|
|
|
|
|
import Test.Hspec
|
|
|
|
import System.IO.Error
|
|
|
|
(
|
|
|
|
ioeGetErrorType
|
|
|
|
)
|
|
|
|
import GHC.IO.Exception
|
|
|
|
(
|
|
|
|
IOErrorType(..)
|
|
|
|
)
|
|
|
|
import Utils
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-29 15:29:13 +00:00
|
|
|
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 14:53:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
spec :: Spec
|
2016-05-29 15:29:13 +00:00
|
|
|
spec = before_ setupFiles $ after_ cleanupFiles $
|
2016-05-09 14:53:31 +00:00
|
|
|
describe "HPath.IO.canonicalizePath" $ do
|
|
|
|
|
|
|
|
-- successes --
|
|
|
|
it "canonicalizePath, all fine" $ do
|
2016-05-29 15:29:13 +00:00
|
|
|
path <- withTmpDir "file" return
|
|
|
|
canonicalizePath' "file"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldReturn` path
|
|
|
|
|
|
|
|
it "canonicalizePath, all fine" $ do
|
2016-05-29 15:29:13 +00:00
|
|
|
path <- withTmpDir "dir" return
|
|
|
|
canonicalizePath' "dir"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldReturn` path
|
|
|
|
|
|
|
|
it "canonicalizePath, all fine" $ do
|
2016-05-29 15:29:13 +00:00
|
|
|
path <- withTmpDir "file" return
|
|
|
|
canonicalizePath' "fileSym"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldReturn` path
|
|
|
|
|
|
|
|
it "canonicalizePath, all fine" $ do
|
2016-05-29 15:29:13 +00:00
|
|
|
path <- withTmpDir "dir" return
|
|
|
|
canonicalizePath' "dirSym"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldReturn` path
|
|
|
|
|
|
|
|
|
|
|
|
-- posix failures --
|
|
|
|
it "canonicalizePath, broken symlink" $
|
2016-05-29 15:29:13 +00:00
|
|
|
canonicalizePath' "brokenSym"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == NoSuchThing)
|
|
|
|
|
|
|
|
it "canonicalizePath, file does not exist" $
|
2016-05-29 15:29:13 +00:00
|
|
|
canonicalizePath' "nothingBlah"
|
2016-05-09 14:53:31 +00:00
|
|
|
`shouldThrow`
|
|
|
|
(\e -> ioeGetErrorType e == NoSuchThing)
|
|
|
|
|