You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

85 lines
1.8 KiB

  1. {-# LANGUAGE OverloadedStrings #-}
  2. module HPath.IO.DeleteFileSpec where
  3. import Test.Hspec
  4. import HPath.IO
  5. import System.IO.Error
  6. (
  7. ioeGetErrorType
  8. )
  9. import System.Posix.Files.ByteString
  10. (
  11. getSymbolicLinkStatus
  12. )
  13. import GHC.IO.Exception
  14. (
  15. IOErrorType(..)
  16. )
  17. import Utils
  18. upTmpDir :: IO ()
  19. upTmpDir = do
  20. setTmpDir "DeleteFileSpec"
  21. createTmpDir
  22. setupFiles :: IO ()
  23. setupFiles = do
  24. createRegularFile' "foo"
  25. createSymlink' "syml" "foo"
  26. createDir' "dir"
  27. createDir' "noPerms"
  28. noPerms "noPerms"
  29. cleanupFiles :: IO ()
  30. cleanupFiles = do
  31. normalDirPerms "noPerms"
  32. deleteFile' "foo"
  33. deleteFile' "syml"
  34. deleteDir' "dir"
  35. deleteDir' "noPerms"
  36. spec :: Spec
  37. spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
  38. describe "HPath.IO.deleteFile" $ do
  39. -- successes --
  40. it "deleteFile, regular file, all fine" $ do
  41. createRegularFile' "testFile"
  42. deleteFile' "testFile"
  43. getSymbolicLinkStatus "testFile"
  44. `shouldThrow`
  45. (\e -> ioeGetErrorType e == NoSuchThing)
  46. it "deleteFile, symlink, all fine" $ do
  47. recreateSymlink' "syml"
  48. "testFile"
  49. Strict
  50. deleteFile' "testFile"
  51. getSymbolicLinkStatus "testFile"
  52. `shouldThrow`
  53. (\e -> ioeGetErrorType e == NoSuchThing)
  54. -- posix failures --
  55. it "deleteFile, wrong file type (directory)" $
  56. deleteFile' "dir"
  57. `shouldThrow`
  58. (\e -> ioeGetErrorType e == InappropriateType)
  59. it "deleteFile, file does not exist" $
  60. deleteFile' "doesNotExist"
  61. `shouldThrow`
  62. (\e -> ioeGetErrorType e == NoSuchThing)
  63. it "deleteFile, can't read directory" $
  64. deleteFile' "noPerms/blah"
  65. `shouldThrow`
  66. (\e -> ioeGetErrorType e == PermissionDenied)