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.
 
 
 
 

79 lines
1.7 KiB

  1. {-# LANGUAGE OverloadedStrings #-}
  2. module HPath.IO.CanonicalizePathSpec where
  3. import Test.Hspec
  4. import System.IO.Error
  5. (
  6. ioeGetErrorType
  7. )
  8. import GHC.IO.Exception
  9. (
  10. IOErrorType(..)
  11. )
  12. import Utils
  13. upTmpDir :: IO ()
  14. upTmpDir = do
  15. setTmpDir "CanonicalizePathSpec"
  16. createTmpDir
  17. setupFiles :: IO ()
  18. setupFiles = do
  19. createRegularFile' "file"
  20. createDir' "dir"
  21. createSymlink' "dirSym" "dir/"
  22. createSymlink' "brokenSym" "nothing"
  23. createSymlink' "fileSym" "file"
  24. cleanupFiles :: IO ()
  25. cleanupFiles = do
  26. deleteFile' "file"
  27. deleteDir' "dir"
  28. deleteFile' "dirSym"
  29. deleteFile' "brokenSym"
  30. deleteFile' "fileSym"
  31. spec :: Spec
  32. spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
  33. describe "HPath.IO.canonicalizePath" $ do
  34. -- successes --
  35. it "canonicalizePath, all fine" $ do
  36. path <- withTmpDir "file" return
  37. canonicalizePath' "file"
  38. `shouldReturn` path
  39. it "canonicalizePath, all fine" $ do
  40. path <- withTmpDir "dir" return
  41. canonicalizePath' "dir"
  42. `shouldReturn` path
  43. it "canonicalizePath, all fine" $ do
  44. path <- withTmpDir "file" return
  45. canonicalizePath' "fileSym"
  46. `shouldReturn` path
  47. it "canonicalizePath, all fine" $ do
  48. path <- withTmpDir "dir" return
  49. canonicalizePath' "dirSym"
  50. `shouldReturn` path
  51. -- posix failures --
  52. it "canonicalizePath, broken symlink" $
  53. canonicalizePath' "brokenSym"
  54. `shouldThrow`
  55. (\e -> ioeGetErrorType e == NoSuchThing)
  56. it "canonicalizePath, file does not exist" $
  57. canonicalizePath' "nothingBlah"
  58. `shouldThrow`
  59. (\e -> ioeGetErrorType e == NoSuchThing)