packages feed

system-canonicalpath 0.3.0.0 → 0.3.1.0

raw patch · 3 files changed

+73/−29 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Filesystem/CanonicalPath.hs view
@@ -20,7 +20,7 @@  'CanonicalPath' also comes with additional useful property. When it is created, it points to real file or directory. Honestly, it can't guarantee that this path will refer to existing file or directory always (someone can remove or move it to another path - and it's almost impossible to be aware of such cruelty), but you can always reconstruct 'CanonicalPath'. -One more thing about path canonicalization. As I mentioned before, under the hood it uses 'System.Directory.canonicalizePath' function. So here are two warnings. Firstly, it behaves differently on different platforms. Sometime too damn differently. So you better watch your steps. Secodly, it's impossible to guarantee that the implication @same file/dir \<=\> same canonicalizedPath@ holds in either direction: this function can make only a best-effort attempt.+One more thing about path canonicalization. As I mentioned before, under the hood it uses 'System.Directory.canonicalizePath' function. So here are two warnings. Firstly, it behaves differently on different platforms. Sometime too damn differently. So you better watch your steps. Secondly, it's impossible to guarantee that the implication @same file/dir \<=\> same canonicalizedPath@ holds in either direction: this function can make only a best-effort attempt.  Happy Haskell Hacking! -}
system-canonicalpath.cabal view
@@ -1,5 +1,5 @@ name:                system-canonicalpath-version:             0.3.0.0+version:             0.3.1.0 synopsis:            Abstract data type for canonical paths with some utilities description:         This library provides abstract data type named 'Filesystem.CanonicalPath.CanonicalPath' and some useful functions for working with it. homepage:            https://github.com/d12frosted/CanonicalPath@@ -12,6 +12,10 @@ build-type:          Custom cabal-version:       >=1.10 extra-source-files:  changelog.md+extra-tmp-files:     test-root+source-repository head+  type:              git+  location:          https://github.com/d12frosted/CanonicalPath  library   exposed-modules:   Filesystem.CanonicalPath@@ -27,7 +31,7 @@                    , system-filepath >= 0.4                    , text -  ghc-options:       -Wall -O2+  ghc-options:       -Wall   default-language:  Haskell2010  test-suite canonicalpath_tests@@ -42,6 +46,6 @@                    , system-canonicalpath                    , system-filepath -  ghc-options:       -Wall -O2+  ghc-options:       -Wall   cc-options:        -Wall   default-language:  Haskell2010
tests/CanonicalPathTests.hs view
@@ -11,29 +11,44 @@ import           Test.Chell  main :: IO ()-main = defaultMain [testCanonicalPath]+main =+  do createTestFiles+     defaultMain [testCanonicalPath] +createTestFiles :: IO ()+createTestFiles =+  do r <- canonicalPathE rootdir+     either (\_ -> return ()) removeDirectoryRecursive r+     wd <- getCurrentDirectory+     root <- createDirectory wd rootdir+     d1 <- createDirectory root "dir"+     d2 <- createDirectory d1 "ab"+     createDirectory_ root "file-or-dir"+     writeFile' root "file" ""+     writeFile' d1 "file" ""+     writeFile' d1 "file1.txt" ""+     writeFile' d2 "file2.txt" ""+     return ()+ testCanonicalPath :: Suite testCanonicalPath =   suite "canonical path constructors" $-  [testConstructor]--testConstructor :: Test-testConstructor =-  assertions "canonicalPathE tests" $-  do let left' v = v >>= \v' -> return $ left v'-         equal' v w = do-           v' <- v-           w' <- w-           return $ equal v' w'-         check p1 p2 = equal' (canonicalize' p1) (liftM Right $ inCurrentDir p2)+  [testLeftSide+  ,testRightSide+  ,testVariables] -     $expect $ left' (canonicalize' "diro/")-     $expect $ left' (canonicalize' "dir.txt")-     $expect $ left' (canonicalize' "dir/ab/../../dir/ab/./../file1.tx")-     $expect $ left' (canonicalize' deepFile)+testLeftSide :: Test+testLeftSide =+  assertions "test for expected lefts" $+  do $expect $ left' (mkPath' "diro/")+     $expect $ left' (mkPath' "dir.txt")+     $expect $ left' (mkPath' "dir/ab/../../dir/ab/./../file1.tx")+     $expect $ left' (mkPath' deepFile) -     $expect $ check "dir/" "dir"+testRightSide :: Test+testRightSide =+  assertions "test for expected rights" $+  do $expect $ check "dir/" "dir"      $expect $ check "dir" "dir"      $expect $ check "file" "file"      -- check "file/" "file" will fail on linux@@ -46,20 +61,42 @@      $expect $ check "dir/ab/./file2.txt" "dir/ab/file2.txt"      $expect $ check "dir/ab/../../dir/ab/./../file1.txt" "dir/file1.txt" -     $expect $ equal' (canonicalize "$HOME") (liftM Right getHomeDirectory)-     $expect $ equal' (canonicalize "$HOME/") (liftM Right getHomeDirectory)-     $expect $ equal' (canonicalize "~/") (liftM Right getHomeDirectory)+testVariables :: Test+testVariables =+  assertions "test for extracting environment variables" $+  do $expect $ equal' (mkPath "$HOME/") (mkPath "~/")+     $expect $ right' (mkPath "$TMPDIR") +-- Chell helpers++left' :: (Show b, Monad m) => m (Either a b) -> m Assertion+left' v = v >>= \v' -> return $ left v'++right' :: (Show a, Monad m) => m (Either a b) -> m Assertion+right' v = v >>= \v' -> return $ right v'++equal' :: (Show a, Monad m, Eq a) => m a -> m a -> m Assertion+equal' v w = do+  v' <- v+  w' <- w+  return $ equal v' w'++check :: FilePath -> FilePath -> IO Assertion+check p1 p2 = equal' (mkPath' p1) (liftM Right $ inCurrentDir p2)+ -- Helper functions -canonicalize :: FilePath -> IO (Either Text CanonicalPath)-canonicalize = canonicalPathE+mkPath :: FilePath -> IO (Either Text CanonicalPath)+mkPath = canonicalPathE -canonicalize' :: FilePath -> IO (Either Text FilePath)-canonicalize' p = inCurrentDir p >>= liftM (Arrow.right unsafePath) . canonicalize+mkPath' :: FilePath -> IO (Either Text FilePath)+mkPath' p = inCurrentDir p >>= liftM unsafe . mkPath +unsafe :: Either Text CanonicalPath -> Either Text FilePath+unsafe = Arrow.right unsafePath+ currentDir :: IO FilePath-currentDir = liftM ((</> "tests") . unsafePath) getCurrentDirectory+currentDir = liftM ((</> rootdir) . unsafePath) getCurrentDirectory  inCurrentDir :: FilePath -> IO FilePath inCurrentDir p =@@ -68,3 +105,6 @@  deepFile :: FilePath deepFile = concat $ replicate 500 "deep-hell"++rootdir :: IsString a => a+rootdir = "test-root"