From b3d41067607abde9a7d085fe33ee4a3637449a13 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 17 Mar 2021 22:12:59 -0400 Subject: [PATCH] Make test deps optional in the library Fix #3 --- Data/Ranged/Boundaries.hs | 7 +++++++ Data/Ranged/RangedSet.hs | 11 +++++++++++ Data/Ranged/Ranges.hs | 13 +++++++++++-- Ranged-sets.cabal | 12 ++++++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Data/Ranged/Boundaries.hs b/Data/Ranged/Boundaries.hs index 67eb696..6cf2dce 100644 --- a/Data/Ranged/Boundaries.hs +++ b/Data/Ranged/Boundaries.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + ----------------------------------------------------------------------------- -- | -- Module : Data.Ranged.Boundaries @@ -20,7 +22,10 @@ module Data.Ranged.Boundaries ( ) where import Data.Ratio + +#ifdef WITH_TESTS import Test.QuickCheck +#endif infix 4 />/ @@ -210,6 +215,7 @@ instance (DiscreteOrdered a) => Ord (Boundary a) where BoundaryBelowAll -> EQ _ -> LT +#ifdef WITH_TESTS -- QuickCheck Generator instance Arbitrary a => Arbitrary (Boundary a) where @@ -227,3 +233,4 @@ instance CoArbitrary a => CoArbitrary (Boundary a) where coarbitrary (BoundaryBelow v) = variant (2 :: Int) . coarbitrary v coarbitrary (BoundaryAbove v) = variant (3 :: Int) . coarbitrary v +#endif diff --git a/Data/Ranged/RangedSet.hs b/Data/Ranged/RangedSet.hs index 922b1d6..3ea6a96 100644 --- a/Data/Ranged/RangedSet.hs +++ b/Data/Ranged/RangedSet.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + module Data.Ranged.RangedSet ( -- ** Ranged Set Type RSet, @@ -23,6 +25,8 @@ module Data.Ranged.RangedSet ( -- ** Useful Sets rSetEmpty, rSetFull, + +#ifdef WITH_TESTS -- ** QuickCheck Properties -- *** Construction prop_validNormalised, @@ -54,13 +58,17 @@ module Data.Ranged.RangedSet ( prop_union_associates, prop_de_morgan_intersection, prop_de_morgan_union, +#endif ) where import Data.Ranged.Boundaries import Data.Ranged.Ranges import Data.List + +#ifdef WITH_TESTS import Test.QuickCheck +#endif infixl 7 -/\- infixl 6 -\/-, -!- @@ -246,6 +254,7 @@ rSetUnfold bound upperFunc succFunc = RSet $ normalise $ ranges1 bound Nothing -> [] +#ifdef WITH_TESTS -- QuickCheck Generators instance (Arbitrary v, DiscreteOrdered v, Show v) => @@ -485,3 +494,5 @@ prop_de_morgan_intersection rs1 rs2 = prop_de_morgan_union :: (DiscreteOrdered a) => RSet a -> RSet a -> Bool prop_de_morgan_union rs1 rs2 = rSetNegation (rs1 -\/- rs2) == (rSetNegation rs1 -/\- rSetNegation rs2) + +#endif diff --git a/Data/Ranged/Ranges.hs b/Data/Ranged/Ranges.hs index 98430ba..913fb0c 100644 --- a/Data/Ranged/Ranges.hs +++ b/Data/Ranged/Ranges.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + ----------------------------------------------------------------------------- -- -- Module : Data.Ranged.Ranges @@ -29,6 +31,8 @@ module Data.Ranged.Ranges ( rangeIntersection, rangeUnion, rangeDifference, + +#ifdef WITH_TESTS -- ** QuickCheck properties prop_unionRange, prop_unionRangeLength, @@ -42,13 +46,17 @@ module Data.Ranged.Ranges ( prop_emptyNonSingleton, prop_fullNonSingleton, prop_nonSingleton, - prop_intSingleton + prop_intSingleton, +#endif ) where import Control.Monad import Data.Ranged.Boundaries import Data.Maybe + +#ifdef WITH_TESTS import Test.QuickCheck +#endif -- | A Range has upper and lower boundaries. data Ord v => Range v = Range {rangeLower, rangeUpper :: Boundary v} @@ -213,6 +221,7 @@ rangeDifference r1@(Range lower1 upper1) (Range lower2 upper2) = intersects = (max lower1 lower2) < (min upper1 upper2) +#ifdef WITH_TESTS -- QuickCheck generators instance (Arbitrary v, DiscreteOrdered v, Show v) => @@ -356,4 +365,4 @@ prop_intSingleton x y = forAll (rangeAround x y) $ \r -> rangeAround v1 v2 = return Range `ap` genBound v1 `ap` genBound v2 genBound v = elements [BoundaryAbove v, BoundaryBelow v] - +#endif diff --git a/Ranged-sets.cabal b/Ranged-sets.cabal index 21ba6cb..6b78039 100644 --- a/Ranged-sets.cabal +++ b/Ranged-sets.cabal @@ -22,8 +22,16 @@ category: Data author: Paul Johnson extra-source-files: CHANGES.txt README.txt +flag with-tests + description: Include unit tests / extra instances. + default: True + manual: False + library - build-depends: HUnit -any, QuickCheck >=2, base >=4.11 && <5 + build-depends: base >=4.11 && <5 + if flag(with-tests) + ghc-options: -DWITH_TESTS + build-depends: QuickCheck >=2 exposed-modules: Data.Ranged Data.Ranged.Ranges Data.Ranged.RangedSet Data.Ranged.Boundaries exposed: True @@ -36,10 +44,10 @@ Test-suite properties default-language: Haskell2010 main-is: Main.hs hs-source-dirs: tests . + cpp-options: -DWITH_TESTS other-modules: Data.Ranged Data.Ranged.Ranges Data.Ranged.RangedSet Data.Ranged.Boundaries build-depends: base >= 4 && < 5, HUnit, QuickCheck -