packages feed

assert 0.0.1.0 → 0.0.1.1

raw patch · 3 files changed

+18/−12 lines, 3 filesdep +bytestringdep ~system-posix-redirect

Dependencies added: bytestring

Dependency ranges changed: system-posix-redirect

Files

assert.cabal view
@@ -1,5 +1,5 @@ name:           assert-version:        0.0.1.0+version:        0.0.1.1 synopsis:       Helpers for Control.Exception.assert description:     GHC supports compile-time toggling of run-time assertions via the@@ -37,8 +37,8 @@     type: exitcode-stdio-1.0     hs-source-dirs: tests     main-is: rewrite.hs-    build-depends: assert, base, Cabal, directory, filepath,-        system-posix-redirect >= 1.0.0.1+    build-depends: assert, base, bytestring, Cabal, directory, filepath,+        system-posix-redirect >= 1.1     ghc-options: -Wall -fignore-asserts  -- vim: et sw=4 ts=4 sts=4:
src/Control/Exception/Assert.hs view
@@ -23,10 +23,10 @@         AssertionFailed failure <- fromException se         return (Arse failure) --- | Generic helper for 'assert' that includes a descriptive message to the--- 'AssertFailure' exception if thrown. Use this to build your own 'assert'--- helpers, such as 'byOrd'. A rule is included which rewrites--- 'assertMessage' to 'id' when compiling with @-fignore-asserts@.+-- | Generic helper for 'assert' that maps 'AssertFailure' 'Exception's to+-- 'Arse', adding a descriptive message along the way. Use this to build+-- your own 'assert' helpers, such as 'byOrd'. A rule is included which+-- rewrites 'assertMessage' to 'id' when compiling with @-fignore-asserts@. {-# INLINE [1] assertMessage #-} {-# RULES "assertMessage" forall name msg.     assertMessage name msg (\x -> x) = id #-}
tests/rewrite.hs view
@@ -1,6 +1,9 @@ import Prelude+import Control.Exception (IOException, catch) import Control.Exception.Assert import Control.Monad+import qualified Data.ByteString.Char8 as BS+import Data.Monoid import Distribution.PackageDescription import Distribution.Simple import Distribution.Simple.LocalBuildInfo@@ -19,13 +22,16 @@  hook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO () hook pd lbi uh bf = do-    forM_ ["hi", "o"] $ \ suf -> removeFile $-        buildDir lbi </> "rewrite" </> "rewrite-tmp" </> "Main" <.> suf+    -- more reliable way to force a rebuild?+    removeDirectoryRecursive (buildDir lbi </> "rewrite" </> "rewrite-tmp")+        `catch` \ e -> return () `const` (e :: IOException)++    -- some versions of GHC prints to stderr     (err, (out, _)) <- redirectStderr . redirectStdout $         buildHook simpleUserHooks pd lbi uh bf-    let combined = err ++ out-    unless ("Rule fired: assertMessage" `elem` lines combined) $ do-        putStr combined+    let combined = BS.lines err <> BS.lines out+    unless (BS.pack "Rule fired: assertMessage" `elem` combined) $ do+        mapM_ BS.putStrLn combined         putStrLn "Rule NOT fired: assertMessage"         exitWith (ExitFailure 1)