From 8d948366f999c5b35bddcd5e3ff8811f791a0d5b Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 29 May 2016 17:43:43 +0200 Subject: [PATCH] Add hspec for createSymlink --- hpath.cabal | 1 + test/HPath/IO/CreateSymlinkSpec.hs | 63 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 test/HPath/IO/CreateSymlinkSpec.hs diff --git a/hpath.cabal b/hpath.cabal index d0f2ebc..5c8aacb 100644 --- a/hpath.cabal +++ b/hpath.cabal @@ -80,6 +80,7 @@ test-suite spec HPath.IO.CopyFileOverwriteSpec HPath.IO.CreateDirSpec HPath.IO.CreateRegularFileSpec + HPath.IO.CreateSymlinkSpec HPath.IO.DeleteDirRecursiveSpec HPath.IO.DeleteDirSpec HPath.IO.DeleteFileSpec diff --git a/test/HPath/IO/CreateSymlinkSpec.hs b/test/HPath/IO/CreateSymlinkSpec.hs new file mode 100644 index 0000000..7c5a8f1 --- /dev/null +++ b/test/HPath/IO/CreateSymlinkSpec.hs @@ -0,0 +1,63 @@ +{-# LANGUAGE OverloadedStrings #-} + +module HPath.IO.CreateSymlinkSpec where + + +import Test.Hspec +import HPath.IO.Errors +import System.IO.Error + ( + ioeGetErrorType + ) +import GHC.IO.Exception + ( + IOErrorType(..) + ) +import Utils +import qualified Data.ByteString as BS +import Data.ByteString.UTF8 (toString) + + +setupFiles :: IO () +setupFiles = do + createRegularFile' "alreadyExists" + createDir' "noPerms" + createDir' "noWritePerms" + noPerms "noPerms" + noWritableDirPerms "noWritePerms" + + +cleanupFiles :: IO () +cleanupFiles = do + normalDirPerms "noPerms" + normalDirPerms "noWritePerms" + deleteFile' "alreadyExists" + deleteDir' "noPerms" + deleteDir' "noWritePerms" + + +spec :: Spec +spec = before_ setupFiles $ after_ cleanupFiles $ + describe "HPath.IO.createSymlink" $ do + + -- successes -- + it "createSymlink, all fine" $ do + createSymlink' "newSymL" "alreadyExists/" + removeFileIfExists "newSymL" + + -- posix failures -- + it "createSymlink, can't write to destination directory" $ + createSymlink' "noWritePerms/newDir" "lala" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "createSymlink, can't write to destination directory" $ + createSymlink' "noPerms/newDir" "lala" + `shouldThrow` + (\e -> ioeGetErrorType e == PermissionDenied) + + it "createSymlink, destination file already exists" $ + createSymlink' "alreadyExists" "lala" + `shouldThrow` + (\e -> ioeGetErrorType e == AlreadyExists) +