packages feed

hedgehog-extras 0.4.3.0 → 0.4.4.1

raw patch · 4 files changed

+34/−10 lines, 4 filesdep ~aesondep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: aeson, base

API changes (from Hackage documentation)

- Hedgehog.Extras.Stock.String: readM :: (Read a, Show a, MonadTest m, MonadCatch m, HasCallStack) => String -> m a
+ Hedgehog.Extras.Stock.String: readNoteM :: (Read a, Show a, MonadTest m, MonadCatch m, HasCallStack) => String -> m a
+ Hedgehog.Extras.Test.Base: assertWith :: (MonadTest m, Show p, HasCallStack) => p -> (p -> Bool) -> m ()
+ Hedgehog.Extras.Test.Base: assertWithM :: (MonadTest m, Show p, HasCallStack) => p -> (p -> m Bool) -> m ()

Files

hedgehog-extras.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4  name:                   hedgehog-extras-version:                0.4.3.0+version:                0.4.4.1 synopsis:               Supplemental library for hedgehog description:            Supplemental library for hedgehog. category:               Test@@ -16,10 +16,10 @@   type:                 git   location:             https://github.com/input-output-hk/hedgehog-extras -common aeson                        { build-depends: aeson                            >= 1.5.6.0                  }+common aeson                        { build-depends: aeson                            >= 2.1.0.0                  } common aeson-pretty                 { build-depends: aeson-pretty                     >= 0.8.5                    } common async                        { build-depends: async                                                        }-common base                         { build-depends: base                             >= 4.12       && < 4.17     }+common base                         { build-depends: base                             >= 4.12       && < 4.19     } common bytestring                   { build-depends: bytestring                                                   } common deepseq                      { build-depends: deepseq                                                      } common Diff                         { build-depends: Diff                                                         }
src/Hedgehog/Extras/Stock/String.hs view
@@ -2,11 +2,13 @@   ( strip   , lastLine   , firstLine-  , readM+  , readNoteM   ) where  import           Control.Monad.Catch (MonadCatch)+import           Data.Bifunctor import           Data.Function+import           Data.Semigroup import           Data.String import           GHC.Stack import           Text.Read@@ -17,7 +19,7 @@ import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H --- | Strip whitepsace from the beginning and end of the string.+-- | Strip whitespace from the beginning and end of the string. strip :: String -> String strip = T.unpack . T.strip . T.pack @@ -29,6 +31,13 @@ firstLine :: String -> String firstLine = strip . L.unlines . L.take 1 . L.lines --- | Trim leading and trailing whitespace and read the string into a value-readM :: (Read a, Show a, H.MonadTest m, MonadCatch m, HasCallStack) => String -> m a-readM = withFrozenCallStack . H.noteShowM . H.evalEither . readEither . strip+-- | Trim leading and trailing whitespace and read the string into a value. Report the read value in the test+-- annotations.+readNoteM :: (Read a, Show a, H.MonadTest m, MonadCatch m, HasCallStack) => String -> m a+readNoteM inputStr =+  withFrozenCallStack+  $ H.noteShowM+  . H.evalEither+  . first (<> ": " <> inputStr)+  . readEither+  $ strip inputStr
src/Hedgehog/Extras/Stock/Time.hs view
@@ -6,7 +6,6 @@   ) where  import           Data.Int-import           Data.Maybe import           Data.String import           Data.Time.Clock (UTCTime) import           Prelude (floor)@@ -21,4 +20,4 @@  -- | Format the given time as an ISO 8601 date-time string formatIso8601 :: UTCTime -> String-formatIso8601 = DT.formatTime DT.defaultTimeLocale (DT.iso8601DateFormat (Just "%H:%M:%SZ"))+formatIso8601 = DT.formatTime DT.defaultTimeLocale "%Y-%m-%dT%H:%M:%SZ"
src/Hedgehog/Extras/Test/Base.hs view
@@ -52,6 +52,8 @@   , assertByDeadlineIO   , assertByDeadlineMFinally   , assertByDeadlineIOFinally+  , assertWith+  , assertWithM   , assertM   , assertIO   , assertWithinTolerance@@ -452,6 +454,20 @@         H.annotateShow currentTime         g         failMessage GHC.callStack "Condition not met by deadline"++-- | Run the test function against the value. Report the value on the failure.+assertWith :: (H.MonadTest m, Show p, HasCallStack) => p -> (p -> Bool) -> m ()+assertWith v f = GHC.withFrozenCallStack $ assertWithM v (pure . f)++-- | Run the test function against the value. Report the value on the failure.+assertWithM :: (H.MonadTest m, Show p, HasCallStack) => p -> (p -> m Bool) -> m ()+assertWithM v f = GHC.withFrozenCallStack $ do+  result <- f v+  if result+     then H.success+     else do+       noteShow_ v+       H.assert result  -- | Run the monadic action 'f' and assert the return value is 'True'. assertM :: (MonadTest m, HasCallStack) => m Bool -> m ()