Skip to content

Commit

Permalink
Tests: Remove quickcheck-instances dependency
Browse files Browse the repository at this point in the history
Include Arbitrary NonEmpty instance
  • Loading branch information
spl committed Jan 19, 2018
1 parent 706a441 commit 4f92012
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
13 changes: 4 additions & 9 deletions dlist.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ test-suite test
build-depends: dlist,
base,
Cabal,
QuickCheck < 2.12
-- Semigroup and NonEmpty were introduced in base-4.9 (ghc-8).
-- QuickCheck-2.9 included support. QuickCheck-2.10 dropped support.
-- quickcheck-instances-0.3.15 has the Arbitrary NonEmpty instance.
if impl(ghc > 8)
build-depends: QuickCheck >= 2.9,
quickcheck-instances >= 0.3.15 && < 0.4
else
build-depends: QuickCheck >= 2.7
-- QuickCheck-2.10 is the first version supporting
-- base-4.9 (ghc-8) without the Arbitrary NonEmpty
-- instance, which we include ourselves.
QuickCheck >= 2.10 && < 2.12
33 changes: 24 additions & 9 deletions tests/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{-# OPTIONS_GHC -Wall #-}
#if MIN_VERSION_base(4,9,0)
{-# OPTIONS_GHC -fno-warn-orphans #-}
#endif

{-# LANGUAGE CPP #-}
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE OverloadedLists #-} -- For the IsList test
Expand All @@ -15,25 +19,21 @@ module Main (main) where
--------------------------------------------------------------------------------

import Prelude hiding (concat, foldr, head, map, replicate, tail)

import qualified Data.List as List
import Text.Show.Functions ()
import Test.QuickCheck
import Text.Show.Functions ()

import Data.DList

import OverloadedStrings (testOverloadedStrings)

#if MIN_VERSION_base(4,9,0)
-- base-4.9 introduced Semigroup and NonEmpty.
import Control.Applicative (liftA2) -- Arbitrary1 NonEmpty instance
import Data.Maybe (mapMaybe) -- Arbitrary1 NonEmpty instance
import Data.List.NonEmpty (NonEmpty(..), nonEmpty)
import Data.Semigroup (Semigroup(..))
import Data.List.NonEmpty (NonEmpty(..))

-- QuickCheck-2.10 dropped the Arbitrary NonEmpty instance, so we import it from
-- quickcheck-instances.
#if MIN_VERSION_QuickCheck(2,10,0)
import Test.QuickCheck.Instances ()
#endif

#endif

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -122,6 +122,21 @@ prop_patterns xs = case fromList xs of
prop_Semigroup_append :: [Int] -> [Int] -> Bool
prop_Semigroup_append xs ys = xs <> ys == toList (fromList xs <> fromList ys)

-- We include the instances for NonEmpty because QuickCheck (>= 2.10) does not.
-- We could alternatively depend on quickcheck-instances (>= 0.3.15), but
-- quickcheck-instances has sometimes lagged behind newer GHC/base versions. By
-- including the instances here, we do not need to track the
-- quickcheck-instances version, thus simplifying dlist.cabal and reducing the
-- maintenance effort.

instance Arbitrary1 NonEmpty where
liftArbitrary arb = liftA2 (:|) arb (liftArbitrary arb)
liftShrink shr (x :| xs) = mapMaybe nonEmpty . liftShrink shr $ x : xs

instance Arbitrary a => Arbitrary (NonEmpty a) where
arbitrary = arbitrary1
shrink = shrink1

prop_Semigroup_sconcat :: NonEmpty [Int] -> Bool
prop_Semigroup_sconcat xs = sconcat xs == toList (sconcat (fmap fromList xs))

Expand Down

0 comments on commit 4f92012

Please sign in to comment.