From 973027a3d04c98f680bfc3410b950627916fe91b Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Thu, 17 Feb 2022 11:15:06 +0100 Subject: [PATCH] Merge testsuites into one This should improve dev ergonomics and speed up building and running the tests. Context: #284 --- tests/Main.hs | 14 +++ tests/Properties.hs | 16 +++ .../HashMapLazy.hs} | 22 ++-- tests/Properties/HashMapStrict.hs | 5 + .../HashSet.hs} | 12 +- tests/{ => Properties}/List.hs | 7 +- tests/Regressions.hs | 10 +- tests/Strictness.hs | 12 +- unordered-containers.cabal | 103 ++---------------- 9 files changed, 69 insertions(+), 132 deletions(-) create mode 100644 tests/Main.hs create mode 100644 tests/Properties.hs rename tests/{HashMapProperties.hs => Properties/HashMapLazy.hs} (98%) create mode 100644 tests/Properties/HashMapStrict.hs rename tests/{HashSetProperties.hs => Properties/HashSet.hs} (96%) rename tests/{ => Properties}/List.hs (94%) diff --git a/tests/Main.hs b/tests/Main.hs new file mode 100644 index 00000000..c18ae77d --- /dev/null +++ b/tests/Main.hs @@ -0,0 +1,14 @@ +module Main (main) where + +import Test.Tasty (defaultMain, testGroup) + +import qualified Regressions +import qualified Properties +import qualified Strictness + +main :: IO () +main = defaultMain $ testGroup "All" + [ Properties.tests + , Regressions.tests + , Strictness.tests + ] diff --git a/tests/Properties.hs b/tests/Properties.hs new file mode 100644 index 00000000..01acc420 --- /dev/null +++ b/tests/Properties.hs @@ -0,0 +1,16 @@ +module Properties (tests) where + +import Test.Tasty (TestTree, testGroup) + +import qualified Properties.HashMapLazy +import qualified Properties.HashMapStrict +import qualified Properties.HashSet +import qualified Properties.List + +tests :: TestTree +tests = testGroup "Properties" + [ Properties.HashMapLazy.tests + , Properties.HashMapStrict.tests + , Properties.HashSet.tests + , Properties.List.tests + ] diff --git a/tests/HashMapProperties.hs b/tests/Properties/HashMapLazy.hs similarity index 98% rename from tests/HashMapProperties.hs rename to tests/Properties/HashMapLazy.hs index 480eb327..e1d582bd 100644 --- a/tests/HashMapProperties.hs +++ b/tests/Properties/HashMapLazy.hs @@ -4,7 +4,11 @@ -- | Tests for the 'Data.HashMap.Lazy' module. We test functions by -- comparing them to @Map@ from @containers@. -module Main (main) where +#if defined(STRICT) +module Properties.HashMapStrict (tests) where +#else +module Properties.HashMapLazy (tests) where +#endif import Control.Monad ( guard ) import qualified Data.Foldable as Foldable @@ -25,7 +29,7 @@ import qualified Data.HashMap.Lazy as HM import qualified Data.Map.Lazy as M #endif import Test.QuickCheck (Arbitrary(..), Property, (==>), (===), forAll, elements) -import Test.Tasty (TestTree, defaultMain, testGroup) +import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) import Data.Functor.Identity (Identity (..)) import Control.Applicative (Const (..)) @@ -441,7 +445,13 @@ pKeys = (L.sort . M.keys) `eq` (L.sort . HM.keys) -- * Test list tests :: TestTree -tests = testGroup "HashMap properties" +tests = + testGroup +#if defined(STRICT) + "Data.HashMap.Strict" +#else + "Data.HashMap.Lazy" +#endif [ -- Instances testGroup "instances" @@ -571,12 +581,6 @@ eq_ f g = (M.toAscList . f) `eq` (toAscList . g) infix 4 `eq_` ------------------------------------------------------------------------- --- * Test harness - -main :: IO () -main = defaultMain tests - ------------------------------------------------------------------------ -- * Helpers diff --git a/tests/Properties/HashMapStrict.hs b/tests/Properties/HashMapStrict.hs new file mode 100644 index 00000000..238348df --- /dev/null +++ b/tests/Properties/HashMapStrict.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE CPP #-} + +#define STRICT + +#include "HashMapLazy.hs" diff --git a/tests/HashSetProperties.hs b/tests/Properties/HashSet.hs similarity index 96% rename from tests/HashSetProperties.hs rename to tests/Properties/HashSet.hs index 1891d957..5564057b 100644 --- a/tests/HashSetProperties.hs +++ b/tests/Properties/HashSet.hs @@ -3,7 +3,7 @@ -- | Tests for the 'Data.HashSet' module. We test functions by -- comparing them to @Set@ from @containers@. -module Main (main) where +module Properties.HashSet (tests) where import qualified Data.Foldable as Foldable import Data.Hashable (Hashable(hashWithSalt)) @@ -12,7 +12,7 @@ import qualified Data.HashSet as S import qualified Data.Set as Set import Data.Ord (comparing) import Test.QuickCheck (Arbitrary, Property, (==>), (===)) -import Test.Tasty (TestTree, defaultMain, testGroup) +import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) -- Key type that generates more hash collisions. @@ -160,7 +160,7 @@ pToList = Set.toAscList `eq` toAscList -- * Test list tests :: TestTree -tests = testGroup "HashSet properties" +tests = testGroup "Data.HashSet" [ -- Instances testGroup "instances" @@ -227,12 +227,6 @@ eq_ :: (Eq a, Hashable a, Ord a) -- equivalent eq_ f g = (Set.toAscList . f) `eq` (toAscList . g) ------------------------------------------------------------------------- --- * Test harness - -main :: IO () -main = defaultMain tests - ------------------------------------------------------------------------ -- * Helpers diff --git a/tests/List.hs b/tests/Properties/List.hs similarity index 94% rename from tests/List.hs rename to tests/Properties/List.hs index 8df8e6a3..1e3f87ba 100644 --- a/tests/List.hs +++ b/tests/Properties/List.hs @@ -1,10 +1,10 @@ -module Main (main) where +module Properties.List (tests) where import Data.HashMap.Internal.List import Data.List (nub, sort, sortBy) import Data.Ord (comparing) -import Test.Tasty (TestTree, defaultMain, testGroup) +import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) import Test.QuickCheck ((==>), (===), property, Property) @@ -63,6 +63,3 @@ modelUnorderedCompareTrans xs ys zs = pUnorderedCompare :: [Int] -> [Int] -> Property pUnorderedCompare xs ys = unorderedCompare compare xs ys === modelUnorderedCompare xs ys - -main :: IO () -main = defaultMain tests diff --git a/tests/Regressions.hs b/tests/Regressions.hs index 70a54015..51d72ad9 100644 --- a/tests/Regressions.hs +++ b/tests/Regressions.hs @@ -1,7 +1,7 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} -module Main where +module Regressions (tests) where import Control.Exception (evaluate) import Control.Monad (replicateM) @@ -16,7 +16,7 @@ import System.Mem (performGC) import System.Mem.Weak (mkWeakPtr, deRefWeak) import System.Random (randomIO) import Test.HUnit (Assertion, assert) -import Test.Tasty (TestTree, defaultMain, testGroup) +import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (testCase) import Test.Tasty.QuickCheck (testProperty) import Test.QuickCheck @@ -135,9 +135,3 @@ tests = testGroup "Regression tests" , testCase "issue254 lazy" issue254Lazy , testCase "issue254 strict" issue254Strict ] - ------------------------------------------------------------------------- --- * Test harness - -main :: IO () -main = defaultMain tests diff --git a/tests/Strictness.hs b/tests/Strictness.hs index ee54233c..f80e1bb6 100644 --- a/tests/Strictness.hs +++ b/tests/Strictness.hs @@ -1,11 +1,11 @@ {-# LANGUAGE CPP, FlexibleInstances, GeneralizedNewtypeDeriving #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -module Main (main) where +module Strictness (tests) where import Data.Hashable (Hashable(hashWithSalt)) import Test.ChasingBottoms.IsBottom -import Test.Tasty (TestTree, defaultMain, testGroup) +import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) import Test.QuickCheck (Arbitrary(arbitrary), Property, (===), (.&&.)) import Test.QuickCheck.Function @@ -150,7 +150,7 @@ pFromListWithValueResultStrict lst comb_lazy calc_good_raw -- * Test list tests :: TestTree -tests = testGroup "Strictness tests" +tests = testGroup "Strictness" [ -- Basic interface testGroup "HashMap.Strict" @@ -175,12 +175,6 @@ tests = testGroup "Strictness tests" ] ] ------------------------------------------------------------------------- --- * Test harness - -main :: IO () -main = defaultMain tests - ------------------------------------------------------------------------ -- * Utilities diff --git a/unordered-containers.cabal b/unordered-containers.cabal index 9b021a33..1dc086ac 100644 --- a/unordered-containers.cabal +++ b/unordered-containers.cabal @@ -78,85 +78,23 @@ library if flag(debug) cpp-options: -DASSERTS -test-suite hashmap-lazy-properties +test-suite unordered-containers-tests hs-source-dirs: tests - main-is: HashMapProperties.hs + main-is: Main.hs type: exitcode-stdio-1.0 - - build-depends: - base, - containers >= 0.5.8, - hashable >= 1.0.1.1, - QuickCheck >= 2.4.0.1, - tasty >= 1.4.0.3, - tasty-quickcheck >= 0.10.1.2, - unordered-containers - - default-language: Haskell2010 - ghc-options: -Wall - cpp-options: -DASSERTS - -test-suite hashmap-strict-properties - hs-source-dirs: tests - main-is: HashMapProperties.hs - type: exitcode-stdio-1.0 - - build-depends: - base, - containers >= 0.5.8, - hashable >= 1.0.1.1, - QuickCheck >= 2.4.0.1, - tasty >= 1.4.0.3, - tasty-quickcheck >= 0.10.1.2, - unordered-containers - - default-language: Haskell2010 - ghc-options: -Wall - cpp-options: -DASSERTS -DSTRICT - -test-suite hashset-properties - hs-source-dirs: tests - main-is: HashSetProperties.hs - type: exitcode-stdio-1.0 - - build-depends: - base, - containers >= 0.4.2.0, - hashable >= 1.0.1.1, - QuickCheck >= 2.4.0.1, - tasty >= 1.4.0.3, - tasty-quickcheck >= 0.10.1.2, - unordered-containers - - default-language: Haskell2010 - ghc-options: -Wall - cpp-options: -DASSERTS - -test-suite list-tests - hs-source-dirs: tests . - main-is: List.hs other-modules: - Data.HashMap.Internal.List - type: exitcode-stdio-1.0 - - build-depends: - base, - containers >= 0.4, - QuickCheck >= 2.4.0.1, - tasty >= 1.4.0.3, - tasty-quickcheck >= 0.10.1.2 - - default-language: Haskell2010 - ghc-options: -Wall - cpp-options: -DASSERTS - -test-suite regressions - hs-source-dirs: tests - main-is: Regressions.hs - type: exitcode-stdio-1.0 + Regressions + Properties + Properties.HashMapLazy + Properties.HashMapStrict + Properties.HashSet + Properties.List + Strictness build-depends: base, + ChasingBottoms, + containers >= 0.5.8, hashable >= 1.0.1.1, HUnit, QuickCheck >= 2.4.0.1, @@ -170,25 +108,6 @@ test-suite regressions ghc-options: -Wall cpp-options: -DASSERTS -test-suite strictness-properties - hs-source-dirs: tests - main-is: Strictness.hs - type: exitcode-stdio-1.0 - - build-depends: - base, - ChasingBottoms, - containers >= 0.4.2, - hashable >= 1.0.1.1, - QuickCheck >= 2.4.0.1, - tasty >= 1.4.0.3, - tasty-quickcheck >= 0.10.1.2, - unordered-containers - - default-language: Haskell2010 - ghc-options: -Wall - cpp-options: -DASSERTS - benchmark benchmarks hs-source-dirs: benchmarks main-is: Benchmarks.hs