diff --git a/.travis.yml b/.travis.yml index ea01c3ce..05ed4e40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,10 +25,11 @@ install: script: - autoreconf -i - - cabal configure -v2 + - cabal configure -v2 --enable-tests - cabal build - cabal check - cabal sdist + - cabal test # The following scriptlet checks that the resulting source distribution can be built & installed - export SRC_TGZ=$(cabal info . | awk '{print $2 ".tar.gz";exit}') ; cd dist/; diff --git a/System/Directory.hs b/System/Directory.hs index 26600a06..5e77f4de 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -399,7 +399,7 @@ createDirectoryIfMissing create_parents path0 #else canIgnore <- (Posix.isDirectory `fmap` Posix.getFileStatus dir) #endif - `catch` ((\ _ -> return (isAlreadyExistsError e)) + `E.catch` ((\ _ -> return (isAlreadyExistsError e)) :: IOException -> IO Bool) unless canIgnore (throwIO e) | otherwise -> throwIO e @@ -839,13 +839,16 @@ getDirectoryContents path = bracket (Posix.openDirStream path) Posix.closeDirStream - loop + start where - loop dirp = do - e <- Posix.readDirStream dirp - if null e then return [] else do - es <- loop dirp - return (e:es) + start dirp = + loop id + where + loop acc = do + e <- Posix.readDirStream dirp + if null e + then return (acc []) + else loop (acc . (e:)) #else bracket (Win32.findFirstFile (path "*")) diff --git a/directory.cabal b/directory.cabal index 69266c67..83e4109f 100644 --- a/directory.cabal +++ b/directory.cabal @@ -31,7 +31,7 @@ extra-source-files: source-repository head type: git - location: http://git.haskell.org/packages/directory.git + location: https://github.com/haskell/directory Library default-language: Haskell2010 @@ -61,3 +61,12 @@ Library build-depends: unix >= 2.5.1 && < 2.8 ghc-options: -Wall + +test-suite test + default-language: Haskell2010 + hs-source-dirs: test + main-is: main.hs + type: exitcode-stdio-1.0 + build-depends: base + , directory + , containers diff --git a/test/main.hs b/test/main.hs new file mode 100644 index 00000000..7a9fcb3c --- /dev/null +++ b/test/main.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE NoImplicitPrelude #-} +-- Simplistic test suite for now. Worthwhile to add a dependency on a +-- test framework at some point. +module Main (main) where + +import qualified Data.Set as Set +import Prelude (IO, error, fmap, return, show, (==)) +import System.Directory (getDirectoryContents) + +main :: IO () +main = do + let expected = Set.fromList + [ "." + , ".." + , "main.hs" + ] + actual <- fmap Set.fromList (getDirectoryContents "test") + if expected == actual + then return () + else error (show (expected, actual))