diff -Nru haskell-genvalidity-0.4.0.4/debian/changelog haskell-genvalidity-0.5.1.0/debian/changelog --- haskell-genvalidity-0.4.0.4/debian/changelog 2018-07-04 13:26:33.000000000 +0000 +++ haskell-genvalidity-0.5.1.0/debian/changelog 2018-09-29 12:04:18.000000000 +0000 @@ -1,8 +1,13 @@ -haskell-genvalidity (0.4.0.4-2build1) cosmic; urgency=medium +haskell-genvalidity (0.5.1.0-1) unstable; urgency=medium - * Rebuild against new GHC ABI. + [ Clint Adams ] + * Set Rules-Requires-Root to no. - -- Gianfranco Costamagna Wed, 04 Jul 2018 15:26:33 +0200 + [ Ilias Tsitsimpis ] + * Bump debhelper compat level to 10 + * New upstream release + + -- Ilias Tsitsimpis Sat, 29 Sep 2018 15:04:18 +0300 haskell-genvalidity (0.4.0.4-2) unstable; urgency=medium diff -Nru haskell-genvalidity-0.4.0.4/debian/compat haskell-genvalidity-0.5.1.0/debian/compat --- haskell-genvalidity-0.4.0.4/debian/compat 2018-04-17 19:03:39.000000000 +0000 +++ haskell-genvalidity-0.5.1.0/debian/compat 2018-09-29 12:04:17.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru haskell-genvalidity-0.4.0.4/debian/control haskell-genvalidity-0.5.1.0/debian/control --- haskell-genvalidity-0.4.0.4/debian/control 2018-04-17 19:03:39.000000000 +0000 +++ haskell-genvalidity-0.5.1.0/debian/control 2018-09-29 12:04:18.000000000 +0000 @@ -3,19 +3,16 @@ Uploaders: Clint Adams Priority: optional Section: haskell -Build-Depends: debhelper (>= 9), +Rules-Requires-Root: no +Build-Depends: debhelper (>= 10), haskell-devscripts (>= 0.8), cdbs, ghc, ghc-prof, libghc-quickcheck2-dev (>= 2.7), - libghc-quickcheck2-dev (<< 2.12), - libghc-quickcheck2-prof (>= 2.7), - libghc-quickcheck2-prof (<< 2.12), - libghc-validity-dev (>= 0.4.0.3), - libghc-validity-dev (<< 0.5), - libghc-validity-prof (>= 0.4.0.3), - libghc-validity-prof (<< 0.5), + libghc-quickcheck2-prof, + libghc-validity-dev (>= 0.5), + libghc-validity-prof, libghc-quickcheck2-dev, libghc-hspec-dev, Build-Depends-Indep: ghc-doc, diff -Nru haskell-genvalidity-0.4.0.4/debian/patches/no--N haskell-genvalidity-0.5.1.0/debian/patches/no--N --- haskell-genvalidity-0.4.0.4/debian/patches/no--N 2018-04-27 12:58:48.000000000 +0000 +++ haskell-genvalidity-0.5.1.0/debian/patches/no--N 2018-09-29 12:04:18.000000000 +0000 @@ -1,7 +1,9 @@ +Index: b/genvalidity.cabal +=================================================================== --- a/genvalidity.cabal +++ b/genvalidity.cabal -@@ -59,12 +59,19 @@ - Paths_genvalidity +@@ -60,6 +60,10 @@ library + ghc-options: -Wno-redundant-constraints default-language: Haskell2010 +flag smp @@ -11,6 +13,8 @@ test-suite genvalidity-test type: exitcode-stdio-1.0 main-is: Spec.hs +@@ -69,7 +73,10 @@ test-suite genvalidity-test + Paths_genvalidity hs-source-dirs: test - ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -fno-warn-name-shadowing diff -Nru haskell-genvalidity-0.4.0.4/genvalidity.cabal haskell-genvalidity-0.5.1.0/genvalidity.cabal --- haskell-genvalidity-0.4.0.4/genvalidity.cabal 2018-01-16 12:50:42.000000000 +0000 +++ haskell-genvalidity-0.5.1.0/genvalidity.cabal 2018-06-30 09:02:34.000000000 +0000 @@ -1,11 +1,11 @@ --- This file has been generated from package.yaml by hpack version 0.20.0. +-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack -- --- hash: 840d6c35489d2fd27bd375fb91b3e78ad68bc9ce90eb12e72b74816a81a8b8f5 +-- hash: 75f45c202b686df17dfa4b7d2a4c2d401bb0c8e9a9437f40d008cef1de3ef380 name: genvalidity -version: 0.4.0.4 +version: 0.5.1.0 synopsis: Testing utilities for the validity library description: Note: There are companion instance packages for this library: . @@ -32,8 +32,9 @@ homepage: https://github.com/NorfairKing/validity#readme bug-reports: https://github.com/NorfairKing/validity/issues author: Tom Sydney Kerckhove -maintainer: syd.kerckhove@gmail.com -copyright: Copyright: (c) 2016 Tom Sydney Kerckhove +maintainer: syd.kerckhove@gmail.com, + nick.van.den.broeck666@gmail.com +copyright: Copyright: (c) 2016-2018 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple @@ -44,24 +45,28 @@ location: https://github.com/NorfairKing/validity library + exposed-modules: + Data.GenValidity + Data.GenRelativeValidity + other-modules: + Paths_genvalidity hs-source-dirs: src build-depends: - QuickCheck >=2.7 && <2.12 + QuickCheck >=2.7 , base >=4.7 && <5 - , validity >=0.4.0.3 && <0.5 + , validity >=0.5 if impl(ghc >=8.0.0) ghc-options: -Wno-redundant-constraints - exposed-modules: - Data.GenValidity - Data.GenRelativeValidity - other-modules: - Paths_genvalidity default-language: Haskell2010 test-suite genvalidity-test type: exitcode-stdio-1.0 main-is: Spec.hs + other-modules: + Data.GenValiditySpec + Data.InstanceSpec + Paths_genvalidity hs-source-dirs: test ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -fno-warn-name-shadowing @@ -70,7 +75,4 @@ , base , genvalidity , hspec - other-modules: - Data.GenValiditySpec - Paths_genvalidity default-language: Haskell2010 diff -Nru haskell-genvalidity-0.4.0.4/src/Data/GenValidity.hs haskell-genvalidity-0.5.1.0/src/Data/GenValidity.hs --- haskell-genvalidity-0.4.0.4/src/Data/GenValidity.hs 2018-01-15 20:27:49.000000000 +0000 +++ haskell-genvalidity-0.5.1.0/src/Data/GenValidity.hs 2018-06-30 05:24:20.000000000 +0000 @@ -54,6 +54,9 @@ {-# LANGUAGE OverlappingInstances #-} #define OVERLAPPING_ #endif +#if MIN_VERSION_base(4,9,0) +{-# OPTIONS_GHC -fno-warn-redundant-constraints #-} +#endif module Data.GenValidity ( module Data.Validity @@ -66,14 +69,25 @@ #if MIN_VERSION_base(4,9,0) import Data.List.NonEmpty (NonEmpty((:|))) #endif +#if MIN_VERSION_base(4,8,0) +import Data.Word (Word8, Word16, Word32, Word64) +#else import Data.Word (Word, Word8, Word16, Word32, Word64) +#endif +import Data.Int (Int8, Int16, Int32, Int64) +import Data.Ratio ((%)) import GHC.Generics import GHC.Real (Ratio(..)) import Test.QuickCheck hiding (Fixed) +#if MIN_VERSION_base(4,8,0) +import GHC.Natural +import Control.Monad (forM) +#else import Control.Applicative ((<*>), (<$>), pure) import Control.Monad (forM) +#endif {-# ANN module "HLint: ignore Reduce duplication" #-} @@ -278,6 +292,69 @@ return (a, b, c, d) ] +instance (GenUnchecked a, GenUnchecked b, GenUnchecked c, GenUnchecked d, GenUnchecked e) => + GenUnchecked (a, b, c, d, e) where + genUnchecked = + sized $ \n -> do + (r, s, t, u, v) <- genSplit5 n + a <- resize r genUnchecked + b <- resize s genUnchecked + c <- resize t genUnchecked + d <- resize u genUnchecked + e <- resize v genUnchecked + return (a, b, c, d, e) + +instance (GenValid a, GenValid b, GenValid c, GenValid d, GenValid e) => + GenValid (a, b, c, d, e) where + genValid = + sized $ \n -> do + (r, s, t, u, v) <- genSplit5 n + a <- resize r genValid + b <- resize s genValid + c <- resize t genValid + d <- resize u genValid + e <- resize v genValid + return (a, b, c, d, e) + +-- | This instance ensures that the generated triple contains at least one invalid element. The other two are unchecked. +instance (GenInvalid a, GenInvalid b, GenInvalid c, GenInvalid d, GenInvalid e) => + GenInvalid (a, b, c, d, e) where + genInvalid = + sized $ \n -> do + (r, s, t, u, v) <- genSplit5 n + oneof + [ do a <- resize r genInvalid + b <- resize s genUnchecked + c <- resize t genUnchecked + d <- resize u genUnchecked + e <- resize v genUnchecked + return (a, b, c, d, e) + , do a <- resize r genUnchecked + b <- resize s genInvalid + c <- resize t genUnchecked + d <- resize u genUnchecked + e <- resize v genUnchecked + return (a, b, c, d, e) + , do a <- resize r genUnchecked + b <- resize s genUnchecked + c <- resize t genInvalid + d <- resize u genUnchecked + e <- resize v genUnchecked + return (a, b, c, d, e) + , do a <- resize r genUnchecked + b <- resize s genUnchecked + c <- resize t genUnchecked + d <- resize u genInvalid + e <- resize v genUnchecked + return (a, b, c, d, e) + , do a <- resize r genUnchecked + b <- resize s genUnchecked + c <- resize t genUnchecked + d <- resize u genUnchecked + e <- resize v genInvalid + return (a, b, c, d, e) + ] + instance GenUnchecked a => GenUnchecked (Maybe a) where genUnchecked = oneof [pure Nothing, Just <$> genUnchecked] @@ -353,6 +430,31 @@ shrinkUnchecked = shrink instance GenValid Int +instance GenUnchecked Int8 where + genUnchecked = arbitrary + shrinkUnchecked = shrink + +instance GenValid Int8 + +instance GenUnchecked Int16 where + genUnchecked = arbitrary + shrinkUnchecked = shrink + +instance GenValid Int16 + +instance GenUnchecked Int32 where + genUnchecked = arbitrary + shrinkUnchecked = shrink + +instance GenValid Int32 + +instance GenUnchecked Int64 where + genUnchecked = arbitrary + shrinkUnchecked = shrink + +instance GenValid Int64 where + genValid = arbitrary + shrinkValid = shrink instance GenUnchecked Word where genUnchecked = arbitrary @@ -386,24 +488,32 @@ instance GenUnchecked Float where genUnchecked = arbitrary +#if MIN_VERSION_QuickCheck(2,9,2) shrinkUnchecked = shrink +#else + shrinkUnchecked _ = [] +#endif instance GenValid Float where genValid = arbitrary -- | Either 'NaN' or 'Infinity'. instance GenInvalid Float where - genInvalid = elements [read "NaN", read "Infinity"] + genInvalid = elements [read "NaN", read "Infinity", read "-Infinity", read "-0"] instance GenUnchecked Double where genUnchecked = arbitrary +#if MIN_VERSION_QuickCheck(2,9,2) shrinkUnchecked = shrink +#else + shrinkUnchecked _ = [] +#endif instance GenValid Double -- | Either 'NaN' or 'Infinity'. instance GenInvalid Double where - genInvalid = elements [read "NaN", read "Infinity"] + genInvalid = elements [read "NaN", read "Infinity", read "-Infinity", read "-0"] instance GenUnchecked Integer where genUnchecked = arbitrary @@ -411,6 +521,16 @@ instance GenValid Integer +#if MIN_VERSION_base(4,8,0) +instance GenUnchecked Natural where + genUnchecked = fromInteger . abs <$> genUnchecked + shrinkUnchecked 0 = [] + shrinkUnchecked n = [0 .. n-1] + +instance GenValid Natural where + genValid = fromInteger . abs <$> genValid +#endif + instance (Integral a, GenUnchecked a) => GenUnchecked (Ratio a) where genUnchecked = do n <- genUnchecked @@ -418,11 +538,18 @@ pure $ n :% d shrinkUnchecked (n :% d) = [n' :% d' | (n', d') <- shrinkUnchecked (n, d)] -instance (Integral a, Num a, Ord a, GenValid a) => GenValid (Ratio a) +instance (Integral a, Num a, Ord a, GenValid a) => GenValid (Ratio a) where + genValid = do + n <- genValid + d <- genValid `suchThat` (> 0) + pure $ n % d + shrinkValid (n :% d) = [n' % d' | (n', d') <- shrinkValid (n, d), d' > 0] + +instance (Integral a, Num a, Ord a, GenValid a) => GenInvalid (Ratio a) instance HasResolution a => GenUnchecked (Fixed a) where genUnchecked = MkFixed <$> genUnchecked - shrinkUnchecked = shrink + shrinkUnchecked (MkFixed i) = MkFixed <$> shrinkUnchecked i instance HasResolution a => GenValid (Fixed a) @@ -441,7 +568,7 @@ upTo :: Int -> Gen Int upTo n | n <= 0 = pure 0 - | otherwise = elements [0 .. n] + | otherwise = choose (0, n) -- | 'genSplit a' generates a tuple '(b, c)' such that 'b + c' equals 'a'. genSplit :: Int -> Gen (Int, Int) @@ -471,12 +598,22 @@ (c, d) <- genSplit z return (a, b, c, d) +-- | 'genSplit5 a' generates a quadruple '(b, c, d, e, f)' such that 'b + c + d + e + f' equals 'a'. +genSplit5 :: Int -> Gen (Int, Int, Int, Int, Int) +genSplit5 n + | n < 0 = pure (0, 0, 0, 0, 0) + | otherwise = do + (y, z) <- genSplit n + (a, b, c) <- genSplit3 y + (d, e) <- genSplit z + return (a, b, c, d, e) + -- | 'arbPartition n' generates a list 'ls' such that 'sum ls' equals 'n'. arbPartition :: Int -> Gen [Int] arbPartition k | k <= 0 = pure [] | otherwise = do - first <- elements [1 .. k] + first <- choose (1, k) rest <- arbPartition $ k - first return $ first : rest @@ -524,8 +661,7 @@ instance (GUncheckedRecursivelyShrink f, GUncheckedRecursivelyShrink g) => GUncheckedRecursivelyShrink (f :*: g) where gUncheckedRecursivelyShrink (x :*: y) = - [x' :*: y | x' <- gUncheckedRecursivelyShrink x] ++ - [x :*: y' | y' <- gUncheckedRecursivelyShrink y] + [x' :*: y' | x' <- gUncheckedRecursivelyShrink x, y' <- gUncheckedRecursivelyShrink y] instance (GUncheckedRecursivelyShrink f, GUncheckedRecursivelyShrink g) => GUncheckedRecursivelyShrink (f :+: g) where gUncheckedRecursivelyShrink (L1 x) = map L1 (gUncheckedRecursivelyShrink x) diff -Nru haskell-genvalidity-0.4.0.4/test/Data/InstanceSpec.hs haskell-genvalidity-0.5.1.0/test/Data/InstanceSpec.hs --- haskell-genvalidity-0.4.0.4/test/Data/InstanceSpec.hs 1970-01-01 00:00:00.000000000 +0000 +++ haskell-genvalidity-0.5.1.0/test/Data/InstanceSpec.hs 2018-06-30 05:24:20.000000000 +0000 @@ -0,0 +1,234 @@ +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} + +module Data.InstanceSpec + ( spec + ) where +#if !MIN_VERSION_base(4,8,0) +import Control.Applicative ((<*>), pure) +import Data.Functor ((<$>)) +#endif +import Data.Data +import Data.Int +#if MIN_VERSION_base(4,9,0) +import Data.List.NonEmpty (NonEmpty) +#endif +import Data.Fixed +import Data.Ratio +import Data.Word + +import Control.Monad + +import Test.Hspec +import Test.QuickCheck +#if MIN_VERSION_base(4,8,0) +import GHC.Natural +#endif +import Data.GenValidity + +spec :: Spec +spec = do + twoTests (Proxy :: Proxy ()) + twoTests (Proxy :: Proxy Bool) + twoTests (Proxy :: Proxy Ordering) + twoTests (Proxy :: Proxy Char) + twoTests (Proxy :: Proxy Word) + twoTests (Proxy :: Proxy Word8) + twoTests (Proxy :: Proxy Word16) + twoTests (Proxy :: Proxy Word32) + twoTests (Proxy :: Proxy Word64) + twoTests (Proxy :: Proxy Int) + twoTests (Proxy :: Proxy Int8) + twoTests (Proxy :: Proxy Int16) + twoTests (Proxy :: Proxy Int32) + twoTests (Proxy :: Proxy Int64) + twoTests (Proxy :: Proxy Integer) + threeTests (Proxy :: Proxy Float) + threeTupleTests (Proxy :: Proxy Float) + threeTests (Proxy :: Proxy Double) + threeTupleTests (Proxy :: Proxy Double) + threeTests (Proxy :: Proxy Rational) + threeTupleTests (Proxy :: Proxy Rational) + threeTests (Proxy :: Proxy (Either Double Double)) + threeTests (Proxy :: Proxy (Maybe Double)) + threeTests (Proxy :: Proxy (Maybe (Maybe Double))) + threeTests (Proxy :: Proxy [Double]) + threeTests (Proxy :: Proxy (Ratio Integer)) + threeTests (Proxy :: Proxy (Ratio Integer)) + threeTupleTests (Proxy :: Proxy (Ratio Integer)) + threeTests (Proxy :: Proxy (Ratio Int)) + threeTupleTests (Proxy :: Proxy (Ratio Int)) + twoTests (Proxy :: Proxy Uni) + twoTupleTests (Proxy :: Proxy Uni) + twoTests (Proxy :: Proxy Deci) + twoTupleTests (Proxy :: Proxy Deci) + twoTests (Proxy :: Proxy Centi) + twoTupleTests (Proxy :: Proxy Centi) + twoTests (Proxy :: Proxy Milli) + twoTupleTests (Proxy :: Proxy Milli) + twoTests (Proxy :: Proxy Micro) + twoTupleTests (Proxy :: Proxy Micro) + twoTests (Proxy :: Proxy Nano) + twoTupleTests (Proxy :: Proxy Nano) + twoTests (Proxy :: Proxy Pico) + twoTupleTests (Proxy :: Proxy Pico) +#if MIN_VERSION_base(4,8,0) + twoTests (Proxy :: Proxy Natural) + + twoTupleTests (Proxy :: Proxy Natural) + + twoTests (Proxy :: Proxy (Ratio Integer)) + + twoTupleTests (Proxy :: Proxy (Ratio Int)) +#endif +#if MIN_VERSION_base(4,9,0) + threeTests (Proxy :: Proxy (NonEmpty Double)) +#endif +twoTupleTests :: + forall a. (Show a, Typeable a, GenValid a) + => Proxy a + -> Spec +twoTupleTests proxy = do + twoTests $ (,) <$> proxy <*> proxy + twoTests $ (,,) <$> proxy <*> proxy <*> proxy + twoTests $ (,,,) <$> proxy <*> proxy <*> proxy <*> proxy + twoTests $ (,,,,) <$> proxy <*> proxy <*> proxy <*> proxy <*> proxy + +threeTupleTests :: + forall a. (Show a, Typeable a, GenValid a, GenInvalid a) + => Proxy a + -> Spec +threeTupleTests proxy = do + threeTests $ (,) <$> proxy <*> proxy + threeTests $ (,,) <$> proxy <*> proxy <*> proxy + threeTests $ (,,,) <$> proxy <*> proxy <*> proxy <*> proxy + threeTests $ (,,,,) <$> proxy <*> proxy <*> proxy <*> proxy <*> proxy + +twoTests :: + forall a. (Show a, Typeable a, GenValid a) + => Proxy a + -> Spec +twoTests proxy = + describe (nameOf proxy) $ do + genUncheckedTest proxy + genValidTest proxy + +threeTests :: + forall a. (Show a, Typeable a, GenValid a, GenInvalid a) + => Proxy a + -> Spec +threeTests proxy = + describe (nameOf proxy) $ do + genUncheckedTest proxy + genValidTest proxy + genInvalidTest proxy + +genUncheckedTest :: + forall a. (Show a, Typeable a, GenValid a) + => Proxy a + -> Spec +genUncheckedTest proxy = do + it (unwords + ["genUnchecked of", nameOf proxy, "does not crash while validating"]) $ + forAll genUnchecked $ \a -> + case prettyValidation (a :: a) of + Right v -> seq v True + Left err -> seq err True + it (unwords + [ "shrinkUnchecked of" + , nameOf proxy + , "only produces values that do not crash while validating" + ]) $ + forAll genUnchecked $ \a -> + forM_ (shrinkUnchecked a) $ \v -> + case prettyValidation (v :: a) of + Right v_ -> seq v_ $ pure () :: IO () + Left err -> seq err $ pure () + +genValidTest :: + forall a. (Show a, Typeable a, GenValid a) + => Proxy a + -> Spec +genValidTest proxy = do + it (unwords ["genValid of", nameOf proxy, "generates only valid values"]) $ + forAll genValid $ \a -> + case prettyValidation (a :: a) of + Right v -> seq v $ pure () + Left err -> + expectationFailure $ + unlines + [ "'validate' reported this value to be invalid:" + , show a + , err + , "" + ] + it (unwords ["shrinkValid of", nameOf proxy, "shrinks to only valid values"]) $ + forAll genValid $ \a -> + forM_ (shrinkValid a) $ \v -> + case prettyValidation (v :: a) of + Right v_ -> seq v_ $ pure () + Left err -> + expectationFailure $ + unlines + [ "'validate' reported this value to be invalid:" + , show v + , err + , "" + ] + it (unwords + [ "shrinkValid of" + , nameOf proxy + , "only produces values that do not crash while validating" + ]) $ + forAll genValid $ \a -> + forM_ (shrinkValid a) $ \v -> + case prettyValidation (v :: a) of + Right v_ -> seq v_ $ pure () :: IO () + Left err -> seq err $ pure () + +genInvalidTest :: + forall a. (Show a, Typeable a, GenInvalid a) + => Proxy a + -> Spec +genInvalidTest proxy = do + it (unwords ["genInvalid of", nameOf proxy, "generates only invalid values"]) $ + forAll genInvalid $ \a -> + case prettyValidation (a :: a) of + Right _ -> + expectationFailure $ + unlines + ["'validate' reported this value to be valid: ", show a] + Left e -> seq e $ pure () + it (unwords + ["shrinkInvalid of", nameOf proxy, "shrinks to only invalid values"]) $ + forAll genInvalid $ \a -> + forM_ (shrinkInvalid a) $ \v -> + case prettyValidation (v :: a) of + Right _ -> + expectationFailure $ + unlines + [ "'validate' reported this value to be valid: " + , show v + ] + Left e -> seq e $ pure () + it (unwords + [ "shrinkInvalid of" + , nameOf proxy + , "only produces values that do not crash while validating" + ]) $ + forAll genInvalid $ \a -> + forM_ (shrinkInvalid a) $ \v -> + case prettyValidation (v :: a) of + Right _ -> + expectationFailure $ + unlines + [ "'validate' reported this value to be valid: " + , show v + ] + Left e -> seq e $ pure () + +nameOf :: + forall a. Typeable a + => Proxy a + -> String +nameOf = show . typeRep