genvalidity-hspec-binary 0.2.0.4 → 1.0.0.0
raw patch · 7 files changed
+98/−86 lines, 7 filesdep ~genvaliditydep ~genvalidity-propertysetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: genvalidity, genvalidity-property
API changes (from Hackage documentation)
- Test.Validity.Binary: binarySpecOnValid :: forall a. (Show a, Eq a, Typeable a, GenValid a, Binary a) => Spec
- Test.Validity.Binary: binarySpec :: forall a. (Show a, Eq a, Typeable a, GenUnchecked a, Binary a) => Spec
+ Test.Validity.Binary: binarySpec :: forall a. (Show a, Eq a, Typeable a, GenValid a, Binary a) => Spec
Files
- CHANGELOG.md +24/−0
- LICENSE +1/−1
- README.md +0/−1
- Setup.hs +0/−3
- genvalidity-hspec-binary.cabal +8/−9
- src/Test/Validity/Binary.hs +59/−65
- test/Test/Validity/BinarySpec.hs +6/−7
+ CHANGELOG.md view
@@ -0,0 +1,24 @@+# Changelog++## [1.0.0.0] - 2021-11-20++* Compatibility with `genvalidity >= 1.0.0.0`+* Renamed every combinator that ends in `OnValid` (or similar) to not have that suffix anymore.++### Removed++* Every combinator that relates to unchecked or invalid values.++## [0.3.0.2] - 2020-02-10++### Changed++* Removed the doctests+* Improved the cabal file++## [0.3.0.1] - 2018-10-07++### Changed++* Fixed the order of the `shouldBe` in the roundtrip spec combinator+* Compatibility with validity >=0.9, genvalidity >=0.7 and genvalidity-property >=0.3
LICENSE view
@@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2020 Tom Sydney Kerckhove+Copyright (c) 2016-2021 Tom Sydney Kerckhove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
− README.md
@@ -1,1 +0,0 @@-This code will create genvalidity specs for the binary serialization library "Data.Binary", as found on https://hackage.haskell.org/package/binary.
− Setup.hs
@@ -1,3 +0,0 @@-import Distribution.Simple--main = defaultMain
genvalidity-hspec-binary.cabal view
@@ -1,13 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack------ hash: 6c71a2c9ae2760a717a53cfb165d8acbf1f0e64bf6e88d18b7fab841abeb6502 name: genvalidity-hspec-binary-version: 0.2.0.4+version: 1.0.0.0 synopsis: Standard spec's for binary-related Instances description: Standard spec's for cereal-related Instances, see https://hackage.haskell.org/package/binary. category: Testing@@ -15,12 +13,13 @@ bug-reports: https://github.com/NorfairKing/validity/issues author: Nick Van den Broeck maintainer: syd@cs-syd.eu-copyright: 2017-2020 Tom Sydney Kerckhove+copyright: Copyright: (c) 2016-2021 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple extra-source-files:- README.md+ LICENSE+ CHANGELOG.md source-repository head type: git@@ -39,7 +38,7 @@ , base >=4.9 && <=5 , binary , deepseq- , genvalidity >=0.5+ , genvalidity >=1.0 , genvalidity-hspec >=0.6 , hspec default-language: Haskell2010@@ -56,9 +55,9 @@ build-depends: base >=4.9 && <=5 , binary- , genvalidity >=0.7+ , genvalidity , genvalidity-hspec-binary- , genvalidity-property >=0.3+ , genvalidity-property , hspec , validity >=0.9 default-language: Haskell2010
src/Test/Validity/Binary.hs view
@@ -1,25 +1,24 @@+{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-}-{-# LANGUAGE AllowAmbiguousTypes #-} -- | Standard test `Spec`s and raw `Property`s for `Binary` instances. -- -- You will need @TypeApplications@ to use these. module Test.Validity.Binary- ( binarySpecOnValid- , binarySpec- , binarySpecOnArbitrary- , binarySpecOnGen- , neverFailsToEncodeOnGen- , encodeAndDecodeAreInversesOnGen- ) where--import Data.GenValidity+ ( binarySpec,+ binarySpecOnArbitrary,+ binarySpecOnGen,+ neverFailsToEncodeOnGen,+ encodeAndDecodeAreInversesOnGen,+ )+where import Control.DeepSeq (deepseq) import Control.Exception (evaluate)-import qualified Data.Binary as Binary import Data.Binary (Binary)+import qualified Data.Binary as Binary+import Data.GenValidity import Data.Typeable import Test.Hspec import Test.QuickCheck@@ -29,21 +28,12 @@ -- -- Example usage: ----- > BinarySpecOnValid @Rational-binarySpecOnValid ::- forall a. (Show a, Eq a, Typeable a, GenValid a, Binary a)- => Spec-binarySpecOnValid = binarySpecOnGen (genValid @a) "valid" shrinkValid---- | Standard test spec for properties of 'Binary'-related functions for unchecked values------ Example usage:--- -- > binarySpec @Int binarySpec ::- forall a. (Show a, Eq a, Typeable a, GenUnchecked a, Binary a)- => Spec-binarySpec = binarySpecOnGen (genUnchecked @a) "unchecked" shrinkUnchecked+ forall a.+ (Show a, Eq a, Typeable a, GenValid a, Binary a) =>+ Spec+binarySpec = binarySpecOnGen (genValid @a) "valid" shrinkValid -- | Standard test spec for properties of 'Binary'-related functions for arbitrary values --@@ -51,8 +41,9 @@ -- -- > binarySpecOnArbitrary @Int binarySpecOnArbitrary ::- forall a. (Show a, Eq a, Typeable a, Arbitrary a, Binary a)- => Spec+ forall a.+ (Show a, Eq a, Typeable a, Arbitrary a, Binary a) =>+ Spec binarySpecOnArbitrary = binarySpecOnGen (arbitrary @a) "arbitrary" shrink -- | Standard test spec for properties of 'Binary'-related functions for a given generator (and a name for that generator).@@ -61,61 +52,64 @@ -- -- > binarySpecOnGen (genListOf $ pure 'a') "sequence of 'a's" (const []) binarySpecOnGen ::- forall a. (Show a, Eq a, Typeable a, Binary a)- => Gen a- -> String- -> (a -> [a])- -> Spec+ forall a.+ (Show a, Eq a, Typeable a, Binary a) =>+ Gen a ->+ String ->+ (a -> [a]) ->+ Spec binarySpecOnGen gen genname s =- parallel $ do- let name = nameOf @a- describe ("Binary " ++ name ++ " (" ++ genname ++ ")") $ do- describe- ("encode :: " ++ name ++ " -> Data.ByteString.Lazy.ByteString") $- it- (unwords- [ "never fails to encode a"- , "\"" ++ genname- , name ++ "\""- ]) $- neverFailsToEncodeOnGen gen s- describe- ("decode :: " ++ name ++ " -> Data.ByteString.Lazy.ByteString") $- it- (unwords- [ "ensures that encode and decode are inverses for"- , "\"" ++ genname- , name ++ "\"" ++ "'s"- ]) $- encodeAndDecodeAreInversesOnGen gen s+ parallel $ do+ let name = nameOf @a+ describe ("Binary " ++ name ++ " (" ++ genname ++ ")") $ do+ describe+ ("encode :: " ++ name ++ " -> Data.ByteString.Lazy.ByteString")+ $ it+ ( unwords+ [ "never fails to encode a",+ "\"" ++ genname,+ name ++ "\""+ ]+ )+ $ neverFailsToEncodeOnGen gen s+ describe+ ("decode :: " ++ name ++ " -> Data.ByteString.Lazy.ByteString")+ $ it+ ( unwords+ [ "ensures that encode and decode are inverses for",+ "\"" ++ genname,+ name ++ "\"" ++ "'s"+ ]+ )+ $ encodeAndDecodeAreInversesOnGen gen s -- | -- -- prop> neverFailsToEncodeOnGen @Bool arbitrary shrink--- prop> neverFailsToEncodeOnGen @Bool genUnchecked shrinkUnchecked -- prop> neverFailsToEncodeOnGen @Bool genValid shrinkValid+-- prop> neverFailsToEncodeOnGen @Bool genValid shrinkValid -- prop> neverFailsToEncodeOnGen @Int arbitrary shrink--- prop> neverFailsToEncodeOnGen @Int genUnchecked shrinkUnchecked -- prop> neverFailsToEncodeOnGen @Int genValid shrinkValid+-- prop> neverFailsToEncodeOnGen @Int genValid shrinkValid neverFailsToEncodeOnGen :: (Show a, Binary a) => Gen a -> (a -> [a]) -> Property neverFailsToEncodeOnGen gen s =- forAllShrink gen s $ \(a :: a) ->- evaluate (deepseq (Binary.encode a) ()) `shouldReturn` ()+ forAllShrink gen s $ \(a :: a) ->+ evaluate (deepseq (Binary.encode a) ()) `shouldReturn` () -- | -- -- prop> encodeAndDecodeAreInversesOnGen @Bool arbitrary shrinkValid--- prop> encodeAndDecodeAreInversesOnGen @Bool genUnchecked shrinkUnchecked -- prop> encodeAndDecodeAreInversesOnGen @Bool genValid shrinkValid+-- prop> encodeAndDecodeAreInversesOnGen @Bool genValid shrinkValid -- prop> encodeAndDecodeAreInversesOnGen @Int arbitrary shrink--- prop> encodeAndDecodeAreInversesOnGen @Int genUnchecked shrinkUnchecked -- prop> encodeAndDecodeAreInversesOnGen @Int genValid shrinkValid+-- prop> encodeAndDecodeAreInversesOnGen @Int genValid shrinkValid encodeAndDecodeAreInversesOnGen ::- (Show a, Eq a, Binary a) => Gen a -> (a -> [a]) -> Property+ (Show a, Eq a, Binary a) => Gen a -> (a -> [a]) -> Property encodeAndDecodeAreInversesOnGen gen s =- forAllShrink gen s $ \(a :: a) ->- case Binary.decodeOrFail (Binary.encode a) of- Right (_, _, b) -> b `shouldBe` a- Left (_, _, s_) ->- expectationFailure $- unwords ["decode of encode is not identity:", s_]+ forAllShrink gen s $ \(a :: a) ->+ case Binary.decodeOrFail (Binary.encode a) of+ Right (_, _, b) -> b `shouldBe` a+ Left (_, _, s_) ->+ expectationFailure $+ unwords ["decode of encode is not identity:", s_]
test/Test/Validity/BinarySpec.hs view
@@ -2,15 +2,14 @@ module Test.Validity.BinarySpec where -import Test.Hspec- import Data.GenValidity+import Test.Hspec import Test.Validity.Binary spec :: Spec spec = do- binarySpecOnGen (genListOf $ pure 'a') "sequence of 'a's" (const [])- -- binarySpec @Double DOES NOT HOLD- binarySpecOnValid @Rational- binarySpec @Int- binarySpecOnArbitrary @Int+ binarySpecOnGen (genListOf $ pure 'a') "sequence of 'a's" (const [])+ -- binarySpec @Double DOES NOT HOLD+ binarySpec @Rational+ binarySpec @Int+ binarySpecOnArbitrary @Int