packages feed

benri-hspec 0.1.0.0 → 0.1.0.1

raw patch · 5 files changed

+94/−30 lines, 5 filesdep +doctestdep ~basedep ~hspecsetup-changedPVP ok

version bump matches the API change (PVP)

Dependencies added: doctest

Dependency ranges changed: base, hspec

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -2,6 +2,12 @@  `benri-hspec` uses [PVP Versioning][1]. ++## 0.1.0.1 -- 2022-12-23++* Added doctests along with other documentation fixes++ ## 0.1.0.0 -- 2022-11-10  * Initial version.
Setup.hs view
@@ -1,2 +1,4 @@ import Distribution.Simple++ main = defaultMain
benri-hspec.cabal view
@@ -1,11 +1,12 @@ cabal-version:      3.0 name:               benri-hspec-version:            0.1.0.0+version:            0.1.0.1 synopsis:           Simplify tests where Either or Maybe types are returned from monadic code description:   A small library of __convenient__ functions for writing hspec tests. -  It's simplifies test code that returns `Either` or `Maybe` types from monadic code.+  It simplifies tests where `Either`, `Maybe` and other types are returned from+  monadic code.    The [README](https://github.com/adetokunbo/benri-hspec#readme) provides usage examples. @@ -57,3 +58,23 @@     , base     , benri-hspec     , hspec++Flag use-doc-tests+  description: Include the doctests in the package tests+  default:     False++test-suite doctests+  if flag(use-doc-tests)+     buildable:     True+  else+     buildable:     False+  type:             exitcode-stdio-1.0+  main-is:          Main.hs+  build-depends:+    , base+    , doctest   >=0.8+    , benri-hspec+    , hspec+  hs-source-dirs:   doctest+  default-language: Haskell2010+  ghc-options:      -threaded
+ doctest/Main.hs view
@@ -0,0 +1,6 @@+-- file doctests.hs+import Test.DocTest+++main :: IO ()+main = doctest ["-isrc", "src/Test/Hspec/Benri.hs"]
src/Test/Hspec/Benri.hs view
@@ -4,18 +4,19 @@ Maintainer  : Tim Emiola <adetokunbo@emio.la> SPDX-License-Identifier: BSD3 -Provides \convenient\ functions for writing hspec tests+Provides \convenient\ functions for writing hspec tests where test values are+returned from a monad. -} module Test.Hspec.Benri (-  -- * expect a monadic value+  -- * match a predicate   endsThen, -  -- * expect a monadic @Maybe@+  -- * @Maybe@ values   endsJust,   endsJust_,   endsNothing, -  -- * expect a monadic @Either@+  -- * @Either@ values   endsLeft,   endsLeft_,   endsRight,@@ -26,67 +27,95 @@ import Test.Hspec (Expectation, HasCallStack, shouldBe, shouldSatisfy)  -{- |- @action \`endsRight\` @expected@ sets the expectation that @action@- returns @Right@ @expected@.+{- $setup+ >>> import Text.Read (readEither, readMaybe)+ >>> import Data.Maybe (isNothing, isJust) -}+++{- | @action \`endsRight\` expected@ sets the expectation that @action@+ __returns__ @Right expected@.++==== __Example__++>>> pure (readEither "1" :: Either String Int) `endsRight` 1+-} endsRight :: (HasCallStack, Show a, Eq a, Show b, Eq b) => IO (Either a b) -> b -> Expectation action `endsRight` expected = action >>= (`shouldBe` Right expected)  -{- |- @action \`endsLeft\` @expected@ sets the expectation that @action@- returns @Left@ @expected@.+{- | @action \`endsLeft\` expected@ sets the expectation that @action@ __returns__+ @Left expected@.++==== __Example__++>>> pure (readEither "not an int" :: Either String Int) `endsLeft` "Prelude.read: no parse" -} endsLeft ::   (HasCallStack, Show a, Eq a, Show b, Eq b) => IO (Either a b) -> a -> Expectation action `endsLeft` expected = action >>= (`shouldBe` Left expected)  -{- |- @action \`endsRight_\` sets the expectation that @action@- returns @Right _@.+{- | @endsRight_ action@ sets the expectation that @action@ __returns__ @Right b@.++==== __Example__++>>> endsRight_ $ pure (readEither "1" :: Either String Int) -} endsRight_ :: (Show a, Show b) => IO (Either a b) -> IO () endsRight_ action = endsThen action $ either (const False) (const True)  -{- |- @action \`endsLeft_\` sets the expectation that @action@- returns @Left _@.+{- | @endsLeft_ action@ sets the expectation that @action@ __returns__ @Left a@.++==== __Example__++>>> endsLeft_ $ pure (readEither "not an int" :: Either String Int) -} endsLeft_ :: (Show a, Show b) => IO (Either a b) -> IO () endsLeft_ action = endsThen action $ either (const True) (const False)  -{- |- @action \`endsJust\`  @expected@ sets the expectation that @action@- returns @Just@ @expected@.+{- | @action \`endsJust\` expected@ sets the expectation that @action@ __returns__+ @Just expected@.++==== __Example__++>>> pure (readMaybe "1" :: Maybe Int) `endsJust` 1 -} endsJust ::   (HasCallStack, Show a, Eq a) => IO (Maybe a) -> a -> Expectation action `endsJust` expected = action >>= (`shouldBe` Just expected)  -{- |- @action \`endsNothing\` expected@ sets the expectation that @action@- returns @Nothing@.+{- | @endsNothing action@ sets the expectation that @action@ __returns__+ @Nothing@.++==== __Example__++>>> endsNothing $ pure (readMaybe "not an int" :: Maybe Int) -} endsNothing :: (Show a, Eq a) => IO (Maybe a) -> IO () endsNothing action = action >>= (`shouldBe` Nothing)  -{- |- @action \`endsJust_\` sets the expectation that @action@- returns @Just _@.+{- | @endsJust_ action@ sets the expectation that @action@ __returns__ @Just a@.++==== __Example__++>>> endsJust_ $ pure (readMaybe "1" :: Maybe Int) -} endsJust_ :: (Show a) => IO (Maybe a) -> IO () endsJust_ action = endsThen action isJust  -{- |- @action \`endsThen\` expected@ sets the expectation that @action@- returns @expected@.+{- | @action \`endsThen\` expected@ sets the expectation that the result of+ @action@ __satisfies__ the predicate @p@.++==== __Example__++>>> pure (readMaybe "1" :: Maybe Int) `endsThen` isJust+>>> pure (readMaybe "not a number" :: Maybe Int) `endsThen` isNothing -} endsThen :: (Show a) => IO a -> (a -> Bool) -> IO () endsThen action p = action >>= (`shouldSatisfy` p)