packages feed

assert-failure 0.1.2.3 → 0.1.2.4

raw patch · 2 files changed

+49/−45 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Control/Exception/Assert/Sugar.hs view
@@ -11,13 +11,14 @@ -- no effect at all. module Control.Exception.Assert.Sugar   ( assert, blame, showFailure, swith, allB-  , failure, twith, forceEither+    -- * DEPRECATED+  , twith, failure, forceEither   ) where -import Control.Exception (assert)-import Data.Text (Text)-import Debug.Trace (trace)-import Prelude+import           Control.Exception (assert)+import           Data.Text (Text)+import           Debug.Trace (trace)+import           Prelude import qualified Text.Show.Pretty as Show.Pretty (ppShow)  infix 1 `blame`@@ -26,34 +27,14 @@ -- -- > assert (age < 120 `blame` age) $ savings / (120 - age) blame :: Show a => Bool -> a -> Bool-{-# INLINE blame #-}+{-# NOINLINE blame #-} blame True _ = True blame False blamed = trace (blameMessage blamed) False  blameMessage :: Show a => a -> String-{-# NOINLINE blameMessage #-} blameMessage blamed = "Contract failed and the following is to blame:\n  "                       ++ Show.Pretty.ppShow blamed -infix 1 `failure`--- | Like 'error', but shows the source position (in newer GHCs--- @error@ shows source position as well, hence deprecation)--- and also the value to blame for the failure. To be used as in------ > case xs of--- >   0 : _ -> assert `failure` (xs, "has an insignificant zero")-{-# DEPRECATED failure-      "use 'error' and 'showFailure' instead, now that 'error' prints source positions." #-}-failure :: Show a => (forall x. Bool -> x -> x) -> a -> b-{-# NOINLINE failure #-}-failure asrt blamed =-  let s = "Internal failure occurred and the following is to blame:\n  "-          ++ Show.Pretty.ppShow blamed-  in trace s-     $ asrt False-     $ error "Control.Exception.Assert.Sugar.failure"-         -- Lack of no-ignore-asserts or GHC < 7.4.- infix 2 `showFailure` -- | A helper function for 'error'. To be used as in --@@ -70,18 +51,6 @@   ++ s ++ "\n  "   ++ Show.Pretty.ppShow v -infix 2 `twith`--- | Syntactic sugar for the pair operation, to be used for 'blame' as in------ > assert (age < 120 `blame` "age too high" `twith` age) $ savings / (120 - age)--- Fixing the first component of the pair to @Text@ prevents warnings--- about defaulting, even when @OverloadedStrings@ extension is enabled.-{-# DEPRECATED twith-      "consider using 'swith' instead, for simplicity, because GHC optimizes lazy 'String' constants very well." #-}-twith :: Text -> b -> (Text, b)-{-# INLINE twith #-}-twith t b = (t, b)- infix 2 `swith` -- | Syntactic sugar for the pair operation, to be used for 'blame' as in --@@ -98,14 +67,46 @@ -- -- > assert (allB (<= height) [yf, y1, y2]) allB :: Show a => (a -> Bool) -> [a] -> Bool-{-# INLINE allB #-}+{-# NOINLINE allB #-} allB predicate l = blame (all predicate l) $ allBMessage predicate l  allBMessage :: Show a => (a -> Bool) -> [a] -> String-{-# NOINLINE allBMessage #-} allBMessage predicate l = Show.Pretty.ppShow (filter (not . predicate) l)                           ++ " in the context of "                           ++ Show.Pretty.ppShow l++-- * DEPRECATED++infix 2 `twith`+-- | Syntactic sugar for the pair operation, to be used for 'blame' as in+--+-- > assert (age < 120 `blame` "age too high" `twith` age) $ savings / (120 - age)+-- Fixing the first component of the pair to @Text@ prevents warnings+-- about defaulting, even when @OverloadedStrings@ extension is enabled.+{-# DEPRECATED twith+      "consider using 'swith' instead, for simplicity, because GHC optimizes lazy 'String' constants very well." #-}+twith :: Text -> b -> (Text, b)+{-# INLINE twith #-}+twith t b = (t, b)++infix 1 `failure`+-- | Like 'error', but shows the source position (in newer GHCs+-- @error@ shows source position as well, hence deprecation)+-- and also the value to blame for the failure. To be used as in+--+-- > case xs of+-- >   0 : _ -> assert `failure` (xs, "has an insignificant zero")+{-# DEPRECATED failure+      "use 'error' and 'showFailure' instead, now that 'error' prints source positions." #-}+failure :: Show a => (forall x. Bool -> x -> x) -> a -> b+{-# NOINLINE failure #-}+failure asrt blamed =+  let s = "Internal failure occurred and the following is to blame:\n  "+          ++ Show.Pretty.ppShow blamed+  in trace s+     $ asrt False+     $ error "Control.Exception.Assert.Sugar.failure"+         -- Lack of no-ignore-asserts or GHC < 7.4.  infix 1 `forceEither` -- | Assuming that @Left@ signifies an error condition,
assert-failure.cabal view
@@ -1,3 +1,4 @@+cabal-version: >= 1.10 name:          assert-failure -- The package version. See the Haskell package versioning policy (PVP) -- for standards guiding when and how versions should be incremented.@@ -5,7 +6,7 @@ -- PVP summary:+-+------- breaking API changes --             | | +----- non-breaking API additions --             | | | +--- code changes with no API change-version:       0.1.2.3+version:       0.1.2.4 synopsis:      Syntactic sugar improving 'assert' and 'error' description:   This library contains syntactic sugar that makes it easier                to write simple contracts with 'assert' and 'error'@@ -14,13 +15,12 @@ bug-reports:   https://github.com/Mikolaj/assert-failure/issues license:       BSD3 license-file:  LICENSE-tested-with:   GHC >= 7.6 && <= 8.10+tested-with:   GHC >= 7.10 && <= 8.10 data-files:    LICENSE, README.md author:        Mikolaj Konarski maintainer:    Mikolaj Konarski <mikolaj.konarski@funktory.com> category:      Control, Contract build-type:    Simple-cabal-version: >= 1.10  source-repository head   type:               git@@ -35,8 +35,11 @@    default-language:   Haskell2010   default-extensions: MonoLocalBinds, ScopedTypeVariables, OverloadedStrings-                      BangPatterns, RecordWildCards, NamedFieldPuns, MultiWayIf+                      BangPatterns, RecordWildCards, NamedFieldPuns, MultiWayIf,+                      LambdaCase, DefaultSignatures, InstanceSigs,+                      PatternSynonyms+-- TODO: , StrictData   other-extensions:   RankNTypes   ghc-options:        -Wall -fwarn-orphans -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates -fwarn-implicit-prelude -fwarn-identities--- TODO:  ghc-options:        -Wall -Wcompat -Worphans -Wincomplete-uni-patterns -Wincomplete-record-updates -Wimplicit-prelude -Wmissing-home-modules -Widentities+-- TODO:  ghc-options:        -Wall -Wcompat -Worphans -Wincomplete-uni-patterns -Wincomplete-record-updates -Wimplicit-prelude -Wmissing-home-modules -Widentities -Wredundant-constraints -Wmissing-export-lists -Wpartial-fields   ghc-options:        -fno-ignore-asserts