Hello community, here is the log from the commit of package ghc-extra for openSUSE:Factory checked in at 2015-08-23 15:43:06 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-extra (Old) and /work/SRC/openSUSE:Factory/.ghc-extra.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-extra" Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-extra/ghc-extra.changes 2015-05-21 08:36:51.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-extra.new/ghc-extra.changes 2015-08-23 17:38:54.000000000 +0200 @@ -1,0 +2,15 @@ +Fri Aug 7 07:01:42 UTC 2015 - [email protected] + +- update to 1.4.1 + * Make temp file functions workaround GHC bug #10731 + * Add retryBool + * Add stripInfix and stripInfixEnd + * support directory-1.2.3 + * Add whenJustM + * Add errorIO + * Add onceFork + * Make once async exception safe + * Fix a deadlock in once when two people request in parallel + * Fix a missing hClose in captureOutput + +------------------------------------------------------------------- Old: ---- extra-1.1.tar.gz New: ---- extra-1.4.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-extra.spec ++++++ --- /var/tmp/diff_new_pack.am0YEA/_old 2015-08-23 17:38:55.000000000 +0200 +++ /var/tmp/diff_new_pack.am0YEA/_new 2015-08-23 17:38:55.000000000 +0200 @@ -20,8 +20,8 @@ # no useful debuginfo for Haskell packages without C sources %global debug_package %{nil} %bcond_with tests -Name: ghc-%{pkg_name} -Version: 1.1 +Name: ghc-extra +Version: 1.4.1 Release: 0 Summary: Extra functions I use License: BSD-3-Clause ++++++ extra-1.1.tar.gz -> extra-1.4.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/CHANGES.txt new/extra-1.4.1/CHANGES.txt --- old/extra-1.1/CHANGES.txt 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/CHANGES.txt 2015-08-04 22:37:36.000000000 +0200 @@ -1,5 +1,20 @@ Changelog for Extra +1.4.1 + Make temp file functions workaround GHC bug #10731 + Add retryBool +1.4 + Add stripInfix and stripInfixEnd +1.3.1 + #9, support directory-1.2.3 +1.3 + Add whenJustM + Add errorIO +1.2 + Add onceFork + Make once async exception safe + Fix a deadlock in once when two people request in parallel + Fix a missing hClose in captureOutput 1.1 #7, add nubOrd, nubOrdOn, nubOrdBy #6, add groupSortOn and groupSortBy diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/Generate.hs new/extra-1.4.1/Generate.hs --- old/extra-1.1/Generate.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/Generate.hs 2015-08-04 22:37:36.000000000 +0200 @@ -9,6 +9,7 @@ import System.Directory import Data.Char import Data.Maybe +import Prelude main :: IO () @@ -19,7 +20,7 @@ src <- readFile $ joinPath ("src" : split (== '.') mod) <.> "hs" let funcs = filter validIdentifier $ takeWhile (/= "where") $ words $ replace "," " " $ drop1 $ dropWhile (/= '(') $ - unlines $ filter (not . isPrefixOf "--" . trim) $ lines src + unlines $ filter (\x -> not $ any (`isPrefixOf` trim x) ["--","#"]) $ lines src let tests = mapMaybe (stripPrefix "-- > ") $ lines src return (mod, funcs, tests) writeFileBinaryChanged "src/Extra.hs" $ unlines $ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/README.md new/extra-1.4.1/README.md --- old/extra-1.1/README.md 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/README.md 2015-08-04 22:37:36.000000000 +0200 @@ -5,7 +5,7 @@ * `Control.Monad.Extra.concatMapM` provides a monadic version of `concatMap`, in the same way that `mapM` is a monadic version of `map`. * `Data.Tuple.Extra.fst3` provides a function to get the first element of a triple. * `Control.Exception.Extra.retry` provides a function that retries an `IO` action a number of times. -* `System.Environment.Extra.lookupEnv` is a functional available in GHC 7.6 and above. On GHC 7.6 and above this package reexports the version from `System.Environment` while on GHC 7.4 and below it defines an equivalent version. +* `System.Environment.Extra.lookupEnv` is a function available in GHC 7.6 and above. On GHC 7.6 and above this package reexports the version from `System.Environment` while on GHC 7.4 and below it defines an equivalent version. The module `Extra` documents all functions provided by this library. Modules such as `Data.List.Extra` provide extra functions over `Data.List` and also reexport `Data.List`. Users are recommended to replace `Data.List` imports with `Data.List.Extra` if they need the extra functionality. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/extra.cabal new/extra-1.4.1/extra.cabal --- old/extra-1.1/extra.cabal 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/extra.cabal 2015-08-04 22:37:36.000000000 +0200 @@ -1,7 +1,7 @@ cabal-version: >= 1.10 build-type: Simple name: extra -version: 1.1 +version: 1.4.1 license: BSD3 license-file: LICENSE category: Development @@ -15,11 +15,12 @@ The module "Extra" documents all functions provided by this library. Modules such as "Data.List.Extra" provide extra functions over "Data.List" and also reexport "Data.List". Users are recommended to replace "Data.List" imports with "Data.List.Extra" if they need the extra functionality. homepage: https://github.com/ndmitchell/extra#readme bug-reports: https://github.com/ndmitchell/extra/issues -tested-with: GHC==7.10.1, GHC==7.8.3, GHC==7.6.3, GHC==7.4.2, GHC==7.2.2 +tested-with: GHC==7.10.1, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2, GHC==7.2.2 -extra-source-files: +extra-doc-files: CHANGES.txt README.md +extra-source-files: Generate.hs source-repository head @@ -68,8 +69,9 @@ if !os(windows) build-depends: unix hs-source-dirs: test - ghc-options: -main-is Test + ghc-options: -main-is Test -threaded -with-rtsopts=-N4 main-is: Test.hs other-modules: - TestUtil + TestCustom TestGen + TestUtil diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/src/Control/Concurrent/Extra.hs new/extra-1.4.1/src/Control/Concurrent/Extra.hs --- old/extra-1.1/src/Control/Concurrent/Extra.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/src/Control/Concurrent/Extra.hs 2015-08-04 22:37:36.000000000 +0200 @@ -15,7 +15,7 @@ module Control.Concurrent.Extra( module Control.Concurrent, getNumCapabilities, setNumCapabilities, withNumCapabilities, - forkFinally, once, + forkFinally, once, onceFork, -- * Lock Lock, newLock, withLock, withLockTry, -- * Var @@ -73,25 +73,42 @@ #endif -data Once a = OncePending | OnceRunning (Barrier a) | OnceDone a - - -- | Given an action, produce a wrapped action that runs at most once. -- If the function raises an exception, the same exception will be reraised each time. +-- +-- > let x ||| y = do t1 <- onceFork x; t2 <- onceFork y; t1; t2 +-- > \(x :: IO Int) -> void (once x) == return () +-- > \(x :: IO Int) -> join (once x) == x +-- > \(x :: IO Int) -> (do y <- once x; y; y) == x +-- > \(x :: IO Int) -> (do y <- once x; y ||| y) == x once :: IO a -> IO (IO a) once act = do var <- newVar OncePending - let run = either throw return - return $ join $ modifyVar var $ \v -> case v of - OnceDone x -> return (v, run x) - OnceRunning x -> return (v, run =<< waitBarrier x) + let run = either throwIO return + return $ mask $ \unmask -> join $ modifyVar var $ \v -> case v of + OnceDone x -> return (v, unmask $ run x) + OnceRunning x -> return (v, unmask $ run =<< waitBarrier x) OncePending -> do b <- newBarrier return $ (OnceRunning b,) $ do - res <- try_ act + res <- try_ $ unmask act + signalBarrier b res modifyVar_ var $ \_ -> return $ OnceDone res run res +data Once a = OncePending | OnceRunning (Barrier a) | OnceDone a + + +-- | Like 'once', but immediately starts running the computation on a background thread. +-- +-- > \(x :: IO Int) -> join (onceFork x) == x +-- > \(x :: IO Int) -> (do a <- onceFork x; a; a) == x +onceFork :: IO a -> IO (IO a) +onceFork act = do + bar <- newBarrier + forkFinally act $ signalBarrier bar + return $ either throwIO return =<< waitBarrier bar + --------------------------------------------------------------------- -- LOCK @@ -194,6 +211,7 @@ -- and in some ways is like a manually managed thunk. newtype Barrier a = Barrier (Var (Either (MVar ()) a)) -- Either a Left empty MVar you should wait or a Right result + -- With base 4.7 and above readMVar is atomic so you probably can implement Barrier directly on MVar a -- | Create a new 'Barrier'. newBarrier :: IO (Barrier a) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/src/Control/Exception/Extra.hs new/extra-1.4.1/src/Control/Exception/Extra.hs --- old/extra-1.1/src/Control/Exception/Extra.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/src/Control/Exception/Extra.hs 2015-08-04 22:37:36.000000000 +0200 @@ -1,11 +1,13 @@ +{-# LANGUAGE ScopedTypeVariables #-} -- | Extra functions for "Control.Exception". -- These functions provide retrying, showing in the presence of exceptions, -- and functions to catch\/ignore exceptions, including monomorphic (no 'Exception' context) versions. module Control.Exception.Extra( module Control.Exception, - retry, + retry, retryBool, showException, stringException, + errorIO, -- * Exception catching/ignoring ignore, catch_, handle_, try_, @@ -49,18 +51,32 @@ ignore = void . try_ +-- | Like error, but in the 'IO' monad. +-- Note that while 'fail' in 'IO' raises an 'IOException', this function raises an 'ErrorCall' exception. +-- +-- > try (errorIO "Hello") == return (Left (ErrorCall "Hello")) +errorIO :: String -> IO a +errorIO = throwIO . ErrorCall + + -- | Retry an operation at most /n/ times (/n/ must be positive). -- If the operation fails the /n/th time it will throw that final exception. -- -- > retry 1 (print "x") == print "x" -- > retry 3 (fail "die") == fail "die" retry :: Int -> IO a -> IO a -retry i x | i <= 0 = error "retry count must be 1 or more" -retry 1 x = x -retry i x = do - res <- try_ x +retry i x | i <= 0 = error "Control.Exception.Extra.retry: count must be 1 or more" +retry i x = retryBool (\(e :: SomeException) -> True) i x + +-- | Retry an operation at most /n/ times (/n/ must be positive), while the exception value and type match a predicate. +-- If the operation fails the /n/th time it will throw that final exception. +retryBool :: Exception e => (e -> Bool) -> Int -> IO a -> IO a +retryBool p i x | i <= 0 = error "Control.Exception.Extra.retryBool: count must be 1 or more" +retryBool p 1 x = x +retryBool p i x = do + res <- tryBool p x case res of - Left _ -> retry (i-1) x + Left _ -> retryBool p (i-1) x Right v -> return v @@ -106,5 +122,5 @@ tryBool :: Exception e => (e -> Bool) -> IO a -> IO (Either e a) tryBool f a = tryJust (bool f) a -bool :: Exception e => (e -> Bool) -> (e -> Maybe e) +bool :: (e -> Bool) -> (e -> Maybe e) bool f x = if f x then Just x else Nothing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/src/Control/Monad/Extra.hs new/extra-1.4.1/src/Control/Monad/Extra.hs --- old/extra-1.1/src/Control/Monad/Extra.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/src/Control/Monad/Extra.hs 2015-08-04 22:37:36.000000000 +0200 @@ -6,7 +6,7 @@ -- see <http://hackage.haskell.org/package/monad-loops monad-loops>. module Control.Monad.Extra( module Control.Monad, - whenJust, + whenJust, whenJustM, unit, -- * Loops loopM, whileM, @@ -31,6 +31,10 @@ whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m () whenJust mg f = maybe (pure ()) f mg +-- | Like 'whenJust', but where the test can be monadic. +whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m () +whenJustM mg f = maybe (return ()) f =<< mg + -- | The identity function which requires the inner argument to be @()@. Useful for functions -- with overloaded return types. -- @@ -122,7 +126,7 @@ (&&^) :: Monad m => m Bool -> m Bool -> m Bool (&&^) a b = ifM a b (return False) --- | A version of 'any' lifted to a moand. Retains the short-circuiting behaviour. +-- | A version of 'any' lifted to a monad. Retains the short-circuiting behaviour. -- -- > anyM Just [False,True ,undefined] == Just True -- > anyM Just [False,False,undefined] == undefined @@ -131,7 +135,7 @@ anyM p [] = return False anyM p (x:xs) = ifM (p x) (return True) (anyM p xs) --- | A version of 'all' lifted to a moand. Retains the short-circuiting behaviour. +-- | A version of 'all' lifted to a monad. Retains the short-circuiting behaviour. -- -- > allM Just [True,False,undefined] == Just False -- > allM Just [True,True ,undefined] == undefined @@ -140,7 +144,7 @@ allM p [] = return True allM p (x:xs) = ifM (p x) (allM p xs) (return False) --- | A version of 'or' lifted to a moand. Retains the short-circuiting behaviour. +-- | A version of 'or' lifted to a monad. Retains the short-circuiting behaviour. -- -- > orM [Just False,Just True ,undefined] == Just True -- > orM [Just False,Just False,undefined] == undefined @@ -148,7 +152,7 @@ orM :: Monad m => [m Bool] -> m Bool orM = anyM id --- | A version of 'and' lifted to a moand. Retains the short-circuiting behaviour. +-- | A version of 'and' lifted to a monad. Retains the short-circuiting behaviour. -- -- > andM [Just True,Just False,undefined] == Just False -- > andM [Just True,Just True ,undefined] == undefined diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/src/Data/List/Extra.hs new/extra-1.4.1/src/Data/List/Extra.hs --- old/extra-1.1/src/Data/List/Extra.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/src/Data/List/Extra.hs 2015-08-04 22:37:36.000000000 +0200 @@ -11,7 +11,8 @@ lower, upper, trim, trimStart, trimEnd, word1, -- * Splitting dropEnd, takeEnd, splitAtEnd, breakEnd, spanEnd, - dropWhileEnd, dropWhileEnd', takeWhileEnd, stripSuffix, + dropWhileEnd, dropWhileEnd', takeWhileEnd, + stripSuffix, stripInfix, stripInfixEnd, wordsBy, linesBy, breakOn, breakOnEnd, splitOn, split, chunksOf, -- * Basics @@ -26,11 +27,13 @@ replace, merge, mergeBy, ) where +import Control.Applicative import Data.List import Data.Maybe import Data.Function import Data.Char import Data.Tuple.Extra +import Prelude -- | Apply some operation repeatedly, producing an element of output @@ -317,6 +320,7 @@ -- > breakEnd isLower "youRE" == ("you","RE") -- > breakEnd isLower "youre" == ("youre","") -- > breakEnd isLower "YOURE" == ("","YOURE") +-- > \f xs -> breakEnd (not . f) xs == spanEnd f xs breakEnd :: (a -> Bool) -> [a] -> ([a], [a]) breakEnd f = swap . both reverse . break f . reverse @@ -324,7 +328,8 @@ -- -- > spanEnd isUpper "youRE" == ("you","RE") -- > spanEnd (not . isSpace) "x y z" == ("x y ","z") --- > \f xs-> spanEnd f xs == swap (both reverse (span f (reverse xs))) +-- > \f xs -> uncurry (++) (spanEnd f xs) == xs +-- > \f xs -> spanEnd f xs == swap (both reverse (span f (reverse xs))) spanEnd :: (a -> Bool) -> [a] -> ([a], [a]) spanEnd f = breakEnd (not . f) @@ -380,6 +385,7 @@ -- The first element of the returned tuple -- is the prefix of @haystack@ before @needle@ is matched. The second -- is the remainder of @haystack@, starting with the match. +-- If you want the remainder /without/ the patch, use 'stripInfix'. -- -- > breakOn "::" "a::b::c" == ("a", "::b::c") -- > breakOn "/" "foobar" == ("foobar", "") @@ -398,7 +404,7 @@ -- -- > breakOnEnd "::" "a::b::c" == ("a::b::", "c") breakOnEnd :: Eq a => [a] -> [a] -> ([a], [a]) -breakOnEnd needle haystack = (reverse *** reverse) $ swap $ breakOn (reverse needle) (reverse haystack) +breakOnEnd needle haystack = both reverse $ swap $ breakOn (reverse needle) (reverse haystack) -- | Break a list into pieces separated by the first @@ -467,6 +473,27 @@ stripSuffix a b = fmap reverse $ stripPrefix (reverse a) (reverse b) +-- | Return the the string before and after the search string, +-- or 'Nothing' if the search string is not present. +-- +-- Examples: +-- +-- > stripInfix "::" "a::b::c" == Just ("a", "b::c") +-- > stripInfix "/" "foobar" == Nothing +stripInfix :: Eq a => [a] -> [a] -> Maybe ([a], [a]) +stripInfix needle haystack | Just rest <- stripPrefix needle haystack = Just ([], rest) +stripInfix needle [] = Nothing +stripInfix needle (x:xs) = first (x:) <$> stripInfix needle xs + + +-- | Similar to 'stripInfix', but searches from the end of the +-- string. +-- +-- > stripInfixEnd "::" "a::b::c" == Just ("a::b", "c") +stripInfixEnd :: Eq a => [a] -> [a] -> Maybe ([a], [a]) +stripInfixEnd needle haystack = both reverse . swap <$> stripInfix (reverse needle) (reverse haystack) + + -- | Split a list into chunks of a given size. The last chunk may contain -- fewer than n elements. The chunk size must be positive. -- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/src/Extra.hs new/extra-1.4.1/src/Extra.hs --- old/extra-1.1/src/Extra.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/src/Extra.hs 2015-08-04 22:37:36.000000000 +0200 @@ -5,13 +5,13 @@ module Extra( -- * Control.Concurrent.Extra -- | Extra functions available in @"Control.Concurrent.Extra"@. - getNumCapabilities, setNumCapabilities, withNumCapabilities, forkFinally, once, Lock, newLock, withLock, withLockTry, Var, newVar, readVar, modifyVar, modifyVar_, withVar, Barrier, newBarrier, signalBarrier, waitBarrier, waitBarrierMaybe, + getNumCapabilities, setNumCapabilities, withNumCapabilities, forkFinally, once, onceFork, Lock, newLock, withLock, withLockTry, Var, newVar, readVar, modifyVar, modifyVar_, withVar, Barrier, newBarrier, signalBarrier, waitBarrier, waitBarrierMaybe, -- * Control.Exception.Extra -- | Extra functions available in @"Control.Exception.Extra"@. - retry, showException, stringException, ignore, catch_, handle_, try_, catchJust_, handleJust_, tryJust_, catchBool, handleBool, tryBool, + retry, retryBool, showException, stringException, errorIO, ignore, catch_, handle_, try_, catchJust_, handleJust_, tryJust_, catchBool, handleBool, tryBool, -- * Control.Monad.Extra -- | Extra functions available in @"Control.Monad.Extra"@. - whenJust, unit, loopM, whileM, partitionM, concatMapM, mapMaybeM, findM, firstJustM, whenM, unlessM, ifM, notM, (||^), (&&^), orM, andM, anyM, allM, + whenJust, whenJustM, unit, loopM, whileM, partitionM, concatMapM, mapMaybeM, findM, firstJustM, whenM, unlessM, ifM, notM, (||^), (&&^), orM, andM, anyM, allM, -- * Data.Either.Extra -- | Extra functions available in @"Data.Either.Extra"@. isLeft, isRight, fromLeft, fromRight, fromEither, @@ -20,7 +20,7 @@ modifyIORef', writeIORef', atomicModifyIORef', atomicWriteIORef, atomicWriteIORef', -- * Data.List.Extra -- | Extra functions available in @"Data.List.Extra"@. - lower, upper, trim, trimStart, trimEnd, word1, dropEnd, takeEnd, splitAtEnd, breakEnd, spanEnd, dropWhileEnd, dropWhileEnd', takeWhileEnd, stripSuffix, wordsBy, linesBy, breakOn, breakOnEnd, splitOn, split, chunksOf, list, uncons, unsnoc, cons, snoc, drop1, groupSort, groupSortOn, groupSortBy, nubOrd, nubOrdBy, nubOrdOn, nubOn, groupOn, sortOn, disjoint, allSame, anySame, repeatedly, for, firstJust, concatUnzip, concatUnzip3, replace, merge, mergeBy, + lower, upper, trim, trimStart, trimEnd, word1, dropEnd, takeEnd, splitAtEnd, breakEnd, spanEnd, dropWhileEnd, dropWhileEnd', takeWhileEnd, stripSuffix, stripInfix, stripInfixEnd, wordsBy, linesBy, breakOn, breakOnEnd, splitOn, split, chunksOf, list, uncons, unsnoc, cons, snoc, drop1, groupSort, groupSortOn, groupSortBy, nubOrd, nubOrdBy, nubOrdOn, nubOn, groupOn, sortOn, disjoint, allSame, anySame, repeatedly, for, firstJust, concatUnzip, concatUnzip3, replace, merge, mergeBy, -- * Data.Tuple.Extra -- | Extra functions available in @"Data.Tuple.Extra"@. first, second, (***), (&&&), dupe, both, fst3, snd3, thd3, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/src/System/Directory/Extra.hs new/extra-1.4.1/src/System/Directory/Extra.hs --- old/extra-1.1/src/System/Directory/Extra.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/src/System/Directory/Extra.hs 2015-08-04 22:37:36.000000000 +0200 @@ -1,10 +1,22 @@ {-# LANGUAGE CPP #-} +#ifndef MIN_VERSION_directory +#if __GLASGOW_HASKELL__ >= 711 +#define MIN_VERSION_directory(a,b,c) 1 +#else +#define MIN_VERSION_directory(a,b,c) 0 +#endif +#endif + + -- | Extra directory functions. Most of these functions provide cleaned up and generalised versions -- of 'getDirectoryContents', see 'listContents' for the differences. module System.Directory.Extra( module System.Directory, - withCurrentDirectory, createDirectoryPrivate, +#if !MIN_VERSION_directory(1,2,3) + withCurrentDirectory, +#endif + createDirectoryPrivate, listContents, listFiles, listFilesInside, listFilesRecursive ) where @@ -19,6 +31,7 @@ #endif +#if !MIN_VERSION_directory(1,2,3) -- | Set the current directory, perform an operation, then change back. -- Remember that the current directory is a global variable, so calling this function -- multithreaded is almost certain to go wrong. Avoid changing the current directory if you can. @@ -28,6 +41,7 @@ withCurrentDirectory dir act = bracket getCurrentDirectory setCurrentDirectory $ const $ do setCurrentDirectory dir; act +#endif -- | List the files and directories directly within a directory. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/src/System/IO/Extra.hs new/extra-1.4.1/src/System/IO/Extra.hs --- old/extra-1.1/src/System/IO/Extra.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/src/System/IO/Extra.hs 2015-08-04 22:37:36.000000000 +0200 @@ -24,9 +24,12 @@ import GHC.IO.Handle(hDuplicate,hDuplicateTo) import System.Directory.Extra import System.IO.Error +import System.IO.Unsafe import System.FilePath import Data.Char import Data.Time.Clock +import Data.Tuple.Extra +import Data.IORef -- File reading @@ -120,6 +123,7 @@ hDuplicateTo h out act `finally` do hDuplicateTo out2 out + hClose out2 hSetBuffering out buf @@ -130,7 +134,19 @@ hSetBuffering h m act --- Temporary file + +--------------------------------------------------------------------- +-- TEMPORARY FILE + +{-# NOINLINE tempRef #-} +tempRef :: IORef Int +tempRef = unsafePerformIO $ do + rand :: Integer <- fmap (read . take 50 . filter isDigit . show . utctDayTime) getCurrentTime + newIORef $ fromIntegral rand + +tempUnique :: IO Int +tempUnique = atomicModifyIORef tempRef $ succ &&& succ + -- | Provide a function to create a temporary file, and a way to delete a -- temporary file. Most users should use 'withTempFile' which @@ -143,7 +159,8 @@ where create = do tmpdir <- getTemporaryDirectory - (file, h) <- openTempFile tmpdir "extra" + val <- tempUnique + (file, h) <- retryBool (\(_ :: IOError) -> True) 5 $ openTempFile tmpdir $ "extra-file-" ++ show val ++ "-" hClose h return file @@ -167,21 +184,17 @@ -- combines these operations. newTempDir :: IO (FilePath, IO ()) newTempDir = do - dir <- create + tmpdir <- getTemporaryDirectory + dir <- retryBool (\(_ :: IOError) -> True) 5 $ create tmpdir del <- once $ ignore $ removeDirectoryRecursive dir return (dir, del) where - create = do - tmpdir <- getTemporaryDirectory - -- get the number of seconds during today (including floating point), and grab some interesting digits - rand :: Integer <- fmap (read . take 20 . filter isDigit . show . utctDayTime) getCurrentTime - find tmpdir rand - - find tmpdir x = do - let dir = tmpdir </> "extra" ++ show x + create tmpdir = do + v <- tempUnique + let dir = tmpdir </> "extra-dir-" ++ show v catchBool isAlreadyExistsError (createDirectoryPrivate dir >> return dir) $ - \e -> find tmpdir (x+1) + \e -> create tmpdir -- | Create a temporary directory inside the system temporary directory. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/test/Test.hs new/extra-1.4.1/test/Test.hs --- old/extra-1.1/test/Test.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/test/Test.hs 2015-08-04 22:37:36.000000000 +0200 @@ -3,6 +3,7 @@ import TestGen import TestUtil +import TestCustom -- Check that we managed to export everything _unused1 x = whenJust @@ -14,4 +15,6 @@ main :: IO () -main = runTests $ tests +main = runTests $ do + tests + testCustom diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/test/TestCustom.hs new/extra-1.4.1/test/TestCustom.hs --- old/extra-1.1/test/TestCustom.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/extra-1.4.1/test/TestCustom.hs 2015-08-04 22:37:36.000000000 +0200 @@ -0,0 +1,30 @@ + +module TestCustom(testCustom) where + +import Control.Concurrent.Extra +import Control.Monad +import System.IO.Extra +import Data.IORef +import TestUtil + + +testCustom :: IO () +testCustom = do + testRaw "withTempFile" $ do + xs <- replicateM 4 $ onceFork $ do + replicateM_ 100 $ withTempFile (const $ return ()) + putChar '.' + sequence_ xs + putStrLn "done" + + testRaw "withTempDir" $ do + xs <- replicateM 4 $ onceFork $ do + replicateM_ 100 $ withTempDir (const $ return ()) + putChar '.' + sequence_ xs + putStrLn "done" + + testGen "retry" $ do + ref <- newIORef 2 + retry 5 $ do modifyIORef ref pred; whenM ((/=) 0 <$> readIORef ref) $ fail "die" + (==== 0) <$> readIORef ref diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/test/TestGen.hs new/extra-1.4.1/test/TestGen.hs --- old/extra-1.1/test/TestGen.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/test/TestGen.hs 2015-08-04 22:37:36.000000000 +0200 @@ -4,12 +4,20 @@ default(Maybe Bool,Int,Double,Maybe (Maybe Bool),Maybe (Maybe Char)) tests :: IO () tests = do + let x ||| y = do t1 <- onceFork x; t2 <- onceFork y; t1; t2 + testGen "\\(x :: IO Int) -> void (once x) == return ()" $ \(x :: IO Int) -> void (once x) == return () + testGen "\\(x :: IO Int) -> join (once x) == x" $ \(x :: IO Int) -> join (once x) == x + testGen "\\(x :: IO Int) -> (do y <- once x; y; y) == x" $ \(x :: IO Int) -> (do y <- once x; y; y) == x + testGen "\\(x :: IO Int) -> (do y <- once x; y ||| y) == x" $ \(x :: IO Int) -> (do y <- once x; y ||| y) == x + testGen "\\(x :: IO Int) -> join (onceFork x) == x" $ \(x :: IO Int) -> join (onceFork x) == x + testGen "\\(x :: IO Int) -> (do a <- onceFork x; a; a) == x" $ \(x :: IO Int) -> (do a <- onceFork x; a; a) == x testGen "stringException \"test\" == return \"test\"" $ stringException "test" == return "test" testGen "stringException (\"test\" ++ undefined) == return \"test<Exception>\"" $ stringException ("test" ++ undefined) == return "test<Exception>" testGen "stringException (\"test\" ++ undefined ++ \"hello\") == return \"test<Exception>\"" $ stringException ("test" ++ undefined ++ "hello") == return "test<Exception>" testGen "stringException ['t','e','s','t',undefined] == return \"test<Exception>\"" $ stringException ['t','e','s','t',undefined] == return "test<Exception>" testGen "ignore (print 1) == print 1" $ ignore (print 1) == print 1 testGen "ignore (fail \"die\") == return ()" $ ignore (fail "die") == return () + testGen "try (errorIO \"Hello\") == return (Left (ErrorCall \"Hello\"))" $ try (errorIO "Hello") == return (Left (ErrorCall "Hello")) testGen "retry 1 (print \"x\") == print \"x\"" $ retry 1 (print "x") == print "x" testGen "retry 3 (fail \"die\") == fail \"die\"" $ retry 3 (fail "die") == fail "die" testGen "whenJust Nothing print == return ()" $ whenJust Nothing print == return () @@ -119,9 +127,11 @@ testGen "breakEnd isLower \"youRE\" == (\"you\",\"RE\")" $ breakEnd isLower "youRE" == ("you","RE") testGen "breakEnd isLower \"youre\" == (\"youre\",\"\")" $ breakEnd isLower "youre" == ("youre","") testGen "breakEnd isLower \"YOURE\" == (\"\",\"YOURE\")" $ breakEnd isLower "YOURE" == ("","YOURE") + testGen "\\f xs -> breakEnd (not . f) xs == spanEnd f xs" $ \f xs -> breakEnd (not . f) xs == spanEnd f xs testGen "spanEnd isUpper \"youRE\" == (\"you\",\"RE\")" $ spanEnd isUpper "youRE" == ("you","RE") testGen "spanEnd (not . isSpace) \"x y z\" == (\"x y \",\"z\")" $ spanEnd (not . isSpace) "x y z" == ("x y ","z") - testGen "\\f xs-> spanEnd f xs == swap (both reverse (span f (reverse xs)))" $ \f xs-> spanEnd f xs == swap (both reverse (span f (reverse xs))) + testGen "\\f xs -> uncurry (++) (spanEnd f xs) == xs" $ \f xs -> uncurry (++) (spanEnd f xs) == xs + testGen "\\f xs -> spanEnd f xs == swap (both reverse (span f (reverse xs)))" $ \f xs -> spanEnd f xs == swap (both reverse (span f (reverse xs))) testGen "wordsBy (== ':') \"::xyz:abc::123::\" == [\"xyz\",\"abc\",\"123\"]" $ wordsBy (== ':') "::xyz:abc::123::" == ["xyz","abc","123"] testGen "\\s -> wordsBy isSpace s == words s" $ \s -> wordsBy isSpace s == words s testGen "linesBy (== ':') \"::xyz:abc::123::\" == [\"\",\"\",\"xyz\",\"abc\",\"\",\"123\",\"\"]" $ linesBy (== ':') "::xyz:abc::123::" == ["","","xyz","abc","","123",""] @@ -155,6 +165,9 @@ testGen "stripSuffix \"bar\" \"foobar\" == Just \"foo\"" $ stripSuffix "bar" "foobar" == Just "foo" testGen "stripSuffix \"\" \"baz\" == Just \"baz\"" $ stripSuffix "" "baz" == Just "baz" testGen "stripSuffix \"foo\" \"quux\" == Nothing" $ stripSuffix "foo" "quux" == Nothing + testGen "stripInfix \"::\" \"a::b::c\" == Just (\"a\", \"b::c\")" $ stripInfix "::" "a::b::c" == Just ("a", "b::c") + testGen "stripInfix \"/\" \"foobar\" == Nothing" $ stripInfix "/" "foobar" == Nothing + testGen "stripInfixEnd \"::\" \"a::b::c\" == Just (\"a::b\", \"c\")" $ stripInfixEnd "::" "a::b::c" == Just ("a::b", "c") testGen "chunksOf 3 \"my test\" == [\"my \",\"tes\",\"t\"]" $ chunksOf 3 "my test" == ["my ","tes","t"] testGen "chunksOf 3 \"mytest\" == [\"myt\",\"est\"]" $ chunksOf 3 "mytest" == ["myt","est"] testGen "chunksOf 8 \"\" == []" $ chunksOf 8 "" == [] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/extra-1.1/test/TestUtil.hs new/extra-1.4.1/test/TestUtil.hs --- old/extra-1.1/test/TestUtil.hs 2015-02-17 20:16:16.000000000 +0100 +++ new/extra-1.4.1/test/TestUtil.hs 2015-08-04 22:37:36.000000000 +0200 @@ -1,5 +1,6 @@ +{-# LANGUAGE ScopedTypeVariables, CPP #-} -module TestUtil(runTests, testGen, erroneous, (====), module X) where +module TestUtil(runTests, testGen, testRaw, erroneous, (====), module X) where import Test.QuickCheck import Test.QuickCheck.Test @@ -22,6 +23,7 @@ import System.Directory as X import System.FilePath as X import System.Info as X +import Control.Exception as X import Test.QuickCheck as X((==>)) @@ -30,10 +32,14 @@ testCount = unsafePerformIO $ newIORef 0 testGen :: Testable prop => String -> prop -> IO () -testGen msg prop = do - putStrLn msg +testGen msg prop = testRaw msg $ do r <- quickCheckResult prop unless (isSuccess r) $ error "Test failed" + +testRaw :: String -> IO () -> IO () +testRaw msg test = do + putStrLn msg + test modifyIORef testCount (+1) @@ -43,6 +49,11 @@ (====) :: (Show a, Eq a) => a -> a -> Bool a ==== b = if a == b then True else error $ "Not equal!\n" ++ show a ++ "\n" ++ show b +#if __GLASGOW_HASKELL__ < 707 +instance Eq ErrorCall where + ErrorCall x == ErrorCall y = x == y +#endif + runTests :: IO () -> IO () runTests t = do writeIORef testCount 0 @@ -50,6 +61,10 @@ n <- readIORef testCount putStrLn $ "Success (" ++ show n ++ " tests)" +instance Testable () where + property = property . (`seq` True) + exhaustive _ = True + instance Testable a => Testable (IO a) where property = property . unsafePerformIO exhaustive = exhaustive . unsafePerformIO @@ -60,6 +75,17 @@ b <- try_ $ captureOutput b return $ a == b +instance Show (IO a) where + show _ = "<<IO>>" + +instance Arbitrary a => Arbitrary (IO a) where + arbitrary = do + (prnt :: Maybe Int, thrw :: Maybe Int, res) <- arbitrary + return $ do + whenJust prnt print + whenJust thrw (fail . show) + return res + instance Eq SomeException where a == b = show a == show b
