packages feed

genvalidity-hspec 0.6.1.1 → 0.6.2.0

raw patch · 6 files changed

+252/−36 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Test.Validity: showReadSpec :: forall a. (Show a, Eq a, Read a, Typeable a, GenUnchecked a) => Spec
+ Test.Validity: showReadSpecOnArbitrary :: forall a. (Show a, Eq a, Read a, Typeable a, Arbitrary a) => Spec
+ Test.Validity: showReadSpecOnGen :: forall a. (Show a, Eq a, Read a, Typeable a) => Gen a -> String -> (a -> [a]) -> Spec
+ Test.Validity: showReadSpecOnValid :: forall a. (Show a, Eq a, Read a, Typeable a, GenValid a) => Spec
+ Test.Validity.Show: showReadRoundTrip :: forall a. (Show a, Eq a, Read a, GenUnchecked a) => Property
+ Test.Validity.Show: showReadRoundTripOnArbitrary :: forall a. (Show a, Eq a, Read a, Arbitrary a) => Property
+ Test.Validity.Show: showReadRoundTripOnGen :: (Show a, Eq a, Read a) => Gen a -> (a -> [a]) -> Property
+ Test.Validity.Show: showReadRoundTripOnValid :: forall a. (Show a, Eq a, Read a, GenValid a) => Property
+ Test.Validity.Show: showReadSpec :: forall a. (Show a, Eq a, Read a, Typeable a, GenUnchecked a) => Spec
+ Test.Validity.Show: showReadSpecOnArbitrary :: forall a. (Show a, Eq a, Read a, Typeable a, Arbitrary a) => Spec
+ Test.Validity.Show: showReadSpecOnGen :: forall a. (Show a, Eq a, Read a, Typeable a) => Gen a -> String -> (a -> [a]) -> Spec
+ Test.Validity.Show: showReadSpecOnValid :: forall a. (Show a, Eq a, Read a, Typeable a, GenValid a) => Spec
+ Test.Validity.Shrinking: shrinkInvalidDoesNotShrinkToItself :: forall a. (Show a, Eq a, GenInvalid a) => Property
+ Test.Validity.Shrinking: shrinkInvalidDoesNotShrinkToItselfWithLimit :: forall a. (Show a, Eq a, GenInvalid a) => Int -> Property
+ Test.Validity.Shrinking: shrinkUncheckedDoesNotShrinkToItself :: forall a. (Show a, Eq a, GenUnchecked a) => Property
+ Test.Validity.Shrinking: shrinkUncheckedDoesNotShrinkToItselfWithLimit :: forall a. (Show a, Eq a, GenUnchecked a) => Int -> Property
+ Test.Validity.Shrinking: shrinkValidDoesNotShrinkToItself :: forall a. (Show a, Eq a, GenValid a) => Property
+ Test.Validity.Shrinking: shrinkValidDoesNotShrinkToItselfWithLimit :: forall a. (Show a, Eq a, GenValid a) => Int -> Property
+ Test.Validity.Shrinking: shrinkValidPreservesValidOnGenValidWithLimit :: forall a. (Show a, GenValid a) => Int -> Property
- Test.Validity: shrinkValidSpec :: forall a. (Show a, Typeable a, GenValid a) => Spec
+ Test.Validity: shrinkValidSpec :: forall a. (Show a, Eq a, Typeable a, GenValid a) => Spec
- Test.Validity: shrinkValidSpecWithLimit :: forall a. (Show a, Typeable a, GenValid a) => Int -> Spec
+ Test.Validity: shrinkValidSpecWithLimit :: forall a. (Show a, Eq a, Typeable a, GenValid a) => Int -> Spec
- Test.Validity: shrinkValiditySpec :: forall a. (Show a, Typeable a, GenValid a, GenInvalid a) => Spec
+ Test.Validity: shrinkValiditySpec :: forall a. (Show a, Eq a, Typeable a, GenValid a, GenInvalid a) => Spec
- Test.Validity.Shrinking: shrinkValidSpec :: forall a. (Show a, Typeable a, GenValid a) => Spec
+ Test.Validity.Shrinking: shrinkValidSpec :: forall a. (Show a, Eq a, Typeable a, GenValid a) => Spec
- Test.Validity.Shrinking: shrinkValidSpecWithLimit :: forall a. (Show a, Typeable a, GenValid a) => Int -> Spec
+ Test.Validity.Shrinking: shrinkValidSpecWithLimit :: forall a. (Show a, Eq a, Typeable a, GenValid a) => Int -> Spec
- Test.Validity.Shrinking: shrinkValiditySpec :: forall a. (Show a, Typeable a, GenValid a, GenInvalid a) => Spec
+ Test.Validity.Shrinking: shrinkValiditySpec :: forall a. (Show a, Eq a, Typeable a, GenValid a, GenInvalid a) => Spec

Files

genvalidity-hspec.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 6fe4772b4a007d5e358a91f2500b29b0161e709fcfceb3e14c58240fffa9d8e7+-- hash: 472617010c38a3b4d88beddec1088f24b2a05528a43ad5e2ab1cc0901f21dff5  name:           genvalidity-hspec-version:        0.6.1.1+version:        0.6.2.0 synopsis:       Standard spec's for GenValidity instances description:    Note: There are companion packages for this library:                 .@@ -33,17 +33,6 @@   location: https://github.com/NorfairKing/validity  library-  hs-source-dirs:-      src-  build-depends:-      QuickCheck-    , base >=4.9 && <5-    , genvalidity >=0.5-    , genvalidity-property >=0.2-    , hspec-    , hspec-core-    , transformers-    , validity >=0.5   exposed-modules:       Test.Validity       Test.Validity.Applicative@@ -56,15 +45,29 @@       Test.Validity.Monoid       Test.Validity.Ord       Test.Validity.RelativeValidity+      Test.Validity.Show       Test.Validity.Shrinking       Test.Validity.Utils   other-modules:       Paths_genvalidity_hspec+  hs-source-dirs:+      src+  build-depends:+      QuickCheck+    , base >=4.9 && <5+    , genvalidity >=0.5+    , genvalidity-property >=0.2+    , hspec+    , hspec-core+    , transformers+    , validity >=0.5   default-language: Haskell2010  test-suite genvalidity-hspec-doctests   type: exitcode-stdio-1.0   main-is: DocTest.hs+  other-modules:+      Paths_genvalidity_hspec   hs-source-dirs:       doctests   ghc-options: -threaded@@ -74,23 +77,11 @@     , doctest     , genvalidity-hspec     , hspec-core-  other-modules:-      Paths_genvalidity_hspec   default-language: Haskell2010  test-suite genvalidity-hspec-test   type: exitcode-stdio-1.0   main-is: Spec.hs-  hs-source-dirs:-      test/-  ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall-  build-depends:-      QuickCheck-    , base-    , genvalidity-    , genvalidity-hspec-    , hspec-    , hspec-core   other-modules:       Test.Validity.ApplicativeSpec       Test.Validity.ArbitrarySpec@@ -102,6 +93,17 @@       Test.Validity.MonoidSpec       Test.Validity.OrdSpec       Test.Validity.RelativeValiditySpec+      Test.Validity.ShowSpec       Test.Validity.ShrinkingSpec       Paths_genvalidity_hspec+  hs-source-dirs:+      test/+  ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+  build-depends:+      QuickCheck+    , base+    , genvalidity+    , genvalidity-hspec+    , hspec+    , hspec-core   default-language: Haskell2010
src/Test/Validity.hs view
@@ -216,6 +216,11 @@     , commutativeOnValids     , commutative     , commutativeOnArbitrary+      -- * Show and Read properties+    , showReadSpecOnValid+    , showReadSpec+    , showReadSpecOnArbitrary+    , showReadSpecOnGen       -- * Eq properties     , eqSpecOnValid     , eqSpecOnInvalid@@ -265,5 +270,6 @@ import Test.Validity.Ord import Test.Validity.Property import Test.Validity.RelativeValidity+import Test.Validity.Show import Test.Validity.Shrinking import Test.Validity.Utils
+ src/Test/Validity/Show.hs view
@@ -0,0 +1,109 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}++-- | 'Show' and 'Read' properties+module Test.Validity.Show+    ( showReadSpecOnValid+    , showReadSpec+    , showReadSpecOnArbitrary+    , showReadSpecOnGen+    , showReadRoundTripOnValid+    , showReadRoundTrip+    , showReadRoundTripOnArbitrary+    , showReadRoundTripOnGen+    ) where++import Data.GenValidity++import Data.Data++import Text.Read++import Test.Hspec+import Test.QuickCheck++import Test.Validity.Utils++-- | Standard test spec for properties of Show and Read instances for valid values+--+-- Example usage:+--+-- > showReadSpecOnValid @Double+showReadSpecOnValid ::+       forall a. (Show a, Eq a, Read a, Typeable a, GenValid a)+    => Spec+showReadSpecOnValid = showReadSpecOnGen @a genValid "valid" shrinkValid++-- | Standard test spec for properties of Show and Read instances for unchecked values+--+-- Example usage:+--+-- > showReadSpec @Int+showReadSpec ::+       forall a. (Show a, Eq a, Read a, Typeable a, GenUnchecked a)+    => Spec+showReadSpec = showReadSpecOnGen @a genUnchecked "unchecked" shrinkUnchecked+++-- | Standard test spec for properties of Show and Read instances for arbitrary values+--+-- Example usage:+--+-- > showReadSpecOnArbitrary @Double+showReadSpecOnArbitrary ::+       forall a. (Show a, Eq a, Read a, Typeable a, Arbitrary a)+    => Spec+showReadSpecOnArbitrary = showReadSpecOnGen @a arbitrary "arbitrary" shrink++-- | Standard test spec for properties of Show and Read instances for values generated by a custom generator+--+-- Example usage:+--+-- > showReadSpecOnGen ((* 2) <$> genValid @Int) "even" (const [])+showReadSpecOnGen ::+       forall a. (Show a, Eq a, Read a, Typeable a)+    => Gen a+    -> String+    -> (a -> [a])+    -> Spec+showReadSpecOnGen gen n s =+    describe (unwords ["Show", nameOf @a, "and Read", nameOf @a]) $+    it (unwords ["are implemented such that read . show == id for", n, "values"]) $+    showReadRoundTripOnGen gen s++-- |+--+-- prop> showReadRoundTripOnValid @Double+showReadRoundTripOnValid ::+       forall a. (Show a, Eq a, Read a, GenValid a)+    => Property+showReadRoundTripOnValid =+    showReadRoundTripOnGen (genValid :: Gen a) shrinkValid++-- |+--+-- prop> showReadRoundTrip @Int+showReadRoundTrip ::+       forall a. (Show a, Eq a, Read a, GenUnchecked a)+    => Property+showReadRoundTrip =+    showReadRoundTripOnGen (genUnchecked :: Gen a) shrinkUnchecked++-- |+--+-- prop> showReadRoundTripOnArbitrary @Double+showReadRoundTripOnArbitrary ::+       forall a. (Show a, Eq a, Read a, Arbitrary a)+    => Property+showReadRoundTripOnArbitrary =+    showReadRoundTripOnGen (arbitrary :: Gen a) shrink++-- |+--+-- prop> showReadRoundTripOnGen (abs <$> genUnchecked :: Gen Int) (const [])+showReadRoundTripOnGen ::+       (Show a, Eq a, Read a) => Gen a -> (a -> [a]) -> Property+showReadRoundTripOnGen gen s =+    forAllShrink gen s $ \v -> readMaybe (show v) `shouldBe` Just v
src/Test/Validity/Shrinking.hs view
@@ -12,6 +12,7 @@     , shrinkValidSpecWithLimit     , shrinkInvalidSpec     , shrinkValidPreservesValidOnGenValid+    , shrinkValidPreservesValidOnGenValidWithLimit     , shrinkInvalidPreservesInvalidOnGenInvalid     , shrinkPreservesValidOnGenValid     , shrinkPreservesInvalidOnGenInvalid@@ -20,12 +21,20 @@     , shrinkingStaysValid     , shrinkingStaysInvalid     , shrinkingPreserves+    , shrinkUncheckedDoesNotShrinkToItself+    , shrinkUncheckedDoesNotShrinkToItselfWithLimit+    , shrinkValidDoesNotShrinkToItself+    , shrinkValidDoesNotShrinkToItselfWithLimit+    , shrinkInvalidDoesNotShrinkToItself+    , shrinkInvalidDoesNotShrinkToItselfWithLimit     ) where  import Data.Data  import Data.GenValidity +import Control.Monad+ import Test.Hspec import Test.QuickCheck @@ -33,34 +42,46 @@ import Test.Validity.Utils  shrinkValiditySpec ::-       forall a. (Show a, Typeable a, GenValid a, GenInvalid a)+       forall a. (Show a, Eq a, Typeable a, GenValid a, GenInvalid a)     => Spec shrinkValiditySpec = do     shrinkValidSpec @a     shrinkInvalidSpec @a  shrinkValidSpec ::-       forall a. (Show a, Typeable a, GenValid a)+       forall a. (Show a, Eq a, Typeable a, GenValid a)     => Spec shrinkValidSpec =-    describe ("shrinkValid :: " ++ nameOf @(a -> [a])) $-    it "preserves validity" $ shrinkValidPreservesValidOnGenValid @a+    describe ("shrinkValid :: " ++ nameOf @(a -> [a])) $ do+        it "preserves validity" $+            forAll (genValid @a) $ \a -> forM_ (shrinkValid a) shouldBeValid+        it "never shrinks to itself for valid values" $+            shrinkValidDoesNotShrinkToItself @a  shrinkValidSpecWithLimit ::-       forall a. (Show a, Typeable a, GenValid a)+       forall a. (Show a, Eq a, Typeable a, GenValid a)     => Int     -> Spec shrinkValidSpecWithLimit l =-    describe ("shrinkValid :: " ++ nameOf @(a -> [a])) $-    it (unwords ["preserves validity for the first", show l, "elements"]) $-    shrinkValidPreservesValidOnGenValidWithLimit @a l+    describe ("shrinkValid :: " ++ nameOf @(a -> [a])) $ do+        it (unwords ["preserves validity for the first", show l, "elements"]) $+            forAll (genValid @a) $ \a -> forM_ (take l $ shrinkValid a) shouldBeValid+        it+            (unwords+                 [ "never shrinks to itself for valid values for the first"+                 , show l+                 , "elements"+                 ]) $+            shrinkValidDoesNotShrinkToItselfWithLimit @a l  shrinkInvalidSpec ::        forall a. (Show a, Typeable a, GenInvalid a)     => Spec shrinkInvalidSpec =-    describe ("shrinkInvalid :: " ++ nameOf @(a -> [a])) $-    it "preserves invalidity" $ shrinkInvalidPreservesInvalidOnGenInvalid @a+    describe ("shrinkInvalid :: " ++ nameOf @(a -> [a])) $ do+        it "preserves invalidity" $+            forAll (genInvalid @a) $ \a ->+                forM_ (shrinkInvalid a) shouldBeInvalid  shrinkValidPreservesValidOnGenValid ::        forall a. (Show a, GenValid a)@@ -80,3 +101,41 @@     => Property shrinkInvalidPreservesInvalidOnGenInvalid =     shrinkingStaysInvalid @a genInvalid shrinkInvalid++shrinkUncheckedDoesNotShrinkToItself ::+       forall a. (Show a, Eq a, GenUnchecked a)+    => Property+shrinkUncheckedDoesNotShrinkToItself =+    shrinkDoesNotShrinkToItself @a shrinkUnchecked++shrinkValidDoesNotShrinkToItself ::+       forall a. (Show a, Eq a, GenValid a)+    => Property+shrinkValidDoesNotShrinkToItself = shrinkDoesNotShrinkToItself @a shrinkValid++shrinkInvalidDoesNotShrinkToItself ::+       forall a. (Show a, Eq a, GenInvalid a)+    => Property+shrinkInvalidDoesNotShrinkToItself =+    shrinkDoesNotShrinkToItself @a shrinkInvalid++shrinkInvalidDoesNotShrinkToItselfWithLimit ::+       forall a. (Show a, Eq a, GenInvalid a)+    => Int+    -> Property+shrinkInvalidDoesNotShrinkToItselfWithLimit =+    shrinkDoesNotShrinkToItselfWithLimit @a shrinkInvalid++shrinkValidDoesNotShrinkToItselfWithLimit ::+       forall a. (Show a, Eq a, GenValid a)+    => Int+    -> Property+shrinkValidDoesNotShrinkToItselfWithLimit =+    shrinkDoesNotShrinkToItselfWithLimit @a shrinkValid++shrinkUncheckedDoesNotShrinkToItselfWithLimit ::+       forall a. (Show a, Eq a, GenUnchecked a)+    => Int+    -> Property+shrinkUncheckedDoesNotShrinkToItselfWithLimit =+    shrinkDoesNotShrinkToItselfWithLimit @a shrinkUnchecked
+ test/Test/Validity/ShowSpec.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE TypeApplications #-}++-- | Standard 'Spec's for 'Show' and 'Read' instances.+--+-- You will need @TypeApplications@ to use these.+module Test.Validity.ShowSpec where++import Test.Hspec++import Data.GenValidity+import Test.Validity.Show+import Test.Validity.Utils++spec :: Spec+spec = do+    showReadSpecOnValid @Double+    showReadSpec @Int+    showReadSpecOnArbitrary @Double+    showReadSpecOnGen ((* 2) <$> genValid @Int) "even" (const [])+    failsBecause "show and read don't have the correct semantics" $+        showReadSpec @ShowFuncMismatch++data ShowFuncMismatch =+    ShowFuncMismatch+    deriving (Eq, Read)++instance Show ShowFuncMismatch where+    show ShowFuncMismatch = "wrong"++instance GenUnchecked ShowFuncMismatch where+    genUnchecked = pure ShowFuncMismatch+    shrinkUnchecked _ = []
test/Test/Validity/ShrinkingSpec.hs view
@@ -11,10 +11,18 @@     shrinkValiditySpec @Double     shrinkValidSpec @Int     shrinkInvalidSpec @Double+    describe "shrinkUncheckedPreservesValidOnGenValid" $ do+        it "Double" $ shrinkValidPreservesValidOnGenValid @Double+        it "[Double]" $ shrinkValidPreservesValidOnGenValid @[Double]     describe "shrinkValidPreservesValidOnGenValid" $ do-        it "Int" $ shrinkValidPreservesValidOnGenValid @Int         it "Double" $ shrinkValidPreservesValidOnGenValid @Double         it "[Double]" $ shrinkValidPreservesValidOnGenValid @[Double]     describe "shrinkInvalidPreservesInvalidOnGenInvalid" $ do         it "Double" $ shrinkInvalidPreservesInvalidOnGenInvalid @Double         it "[Double]" $ shrinkInvalidPreservesInvalidOnGenInvalid @[Double]+    describe "shrinkUncheckedDoesNotShrinkToItself" $ do+        it "Int" $ shrinkUncheckedDoesNotShrinkToItself @Int+        it "[Int]" $ shrinkUncheckedDoesNotShrinkToItself @[Int]+    describe "shrinkValidDoesNotShrinkToItself" $ do+        it "Double" $ shrinkValidDoesNotShrinkToItself @Double+        it "[Double]" $ shrinkValidDoesNotShrinkToItself @[Double]