X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=tests%2FgetDirContents001.hs;h=d09b645ccdbf9f0483c2c07a965b4be884a16c7a;hb=e6e0fcd70d76aecbbbb73bebd1dd18ca6545d667;hp=9f3535144e17e80611ce9d04aaff6fe4cf04257a;hpb=8af1abacf899be128c3b195696b24c9fc81bc282;p=haskell-directory.git diff --git a/tests/getDirContents001.hs b/tests/getDirContents001.hs index 9f35351..d09b645 100644 --- a/tests/getDirContents001.hs +++ b/tests/getDirContents001.hs @@ -1,13 +1,18 @@ -import System.Directory (getDirectoryContents) -import Data.List (sort, isPrefixOf, isSuffixOf) +import System.Directory +import Control.Exception +import System.FilePath +import Data.List + +dir = "getDirContents001.dir" main = do - names <- getDirectoryContents "." - putStrLn (unlines (sort (filter ok names))) + try cleanup :: IO (Either IOException ()) + bracket (createDirectory dir) (const cleanup) $ \_ -> do + getDirectoryContents dir >>= print . sort + mapM_ (\s -> writeFile (dir ('f':show s)) (show s)) [1..100] + getDirectoryContents dir >>= print . sort -ok name = "getDirContents" `isPrefixOf` name - && not ("bak" `isSuffixOf` name) - && not ("prof" `isSuffixOf` name) - && not ("hp" `isSuffixOf` name) - && not ("ps" `isSuffixOf` name) - && not ("aux" `isSuffixOf` name) +cleanup = do + files <- getDirectoryContents dir + mapM_ (removeFile . (dir )) (filter (not . ("." `isPrefixOf`)) files) + removeDirectory dir