From 05e42831f9d50044c5c2249d72848447e4890893 Mon Sep 17 00:00:00 2001 From: Alfredo Di Napoli <alfredo@well-typed.com> Date: Mon, 29 May 2023 10:15:25 +0200 Subject: [PATCH] Move tests under a single umbrella (tasty) --- gargantext.cabal | 49 ++++--------------- package.yaml | 35 +++++-------- src-test/Core/Text/Corpus/Query.hs | 5 +- src-test/Core/Utils.hs | 4 +- src-test/Graph/Clustering.hs | 4 +- src-test/Main.hs | 28 ++++++++--- src-test/Ngrams/NLP.hs | 4 +- src-test/Ngrams/Query.hs | 5 +- src-test/Parsers/Date.hs | 4 +- src-test/Utils/Crypto.hs | 5 +- tests/queue/Main.hs => src-test/Utils/Jobs.hs | 19 ++----- 11 files changed, 56 insertions(+), 106 deletions(-) rename tests/queue/Main.hs => src-test/Utils/Jobs.hs (96%) diff --git a/gargantext.cabal b/gargantext.cabal index 96946901..6869773b 100644 --- a/gargantext.cabal +++ b/gargantext.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: gargantext -version: 0.0.6.9.9.6.2 +version: 0.0.6.9.9.6.2 synopsis: Search, map, share description: Please see README.md category: Data @@ -866,6 +866,7 @@ test-suite garg-test Parsers.Types Parsers.WOS Utils.Crypto + Utils.Jobs Paths_gargantext hs-source-dirs: src-test @@ -896,6 +897,7 @@ test-suite garg-test build-depends: QuickCheck , aeson + , async , base , boolexpr , bytestring @@ -905,11 +907,17 @@ test-suite garg-test , gargantext , gargantext-prelude , hspec + , http-client + , http-client-tls + , mtl , parsec , patches-class , patches-map , quickcheck-instances + , servant-job + , stm , tasty + , tasty-hspec , tasty-hunit , tasty-quickcheck , text @@ -917,42 +925,3 @@ test-suite garg-test , unordered-containers , validity default-language: Haskell2010 - -test-suite jobqueue-test - type: exitcode-stdio-1.0 - main-is: Main.hs - other-modules: - Paths_gargantext - hs-source-dirs: - tests/queue - default-extensions: - DataKinds - DeriveGeneric - FlexibleContexts - FlexibleInstances - GADTs - GeneralizedNewtypeDeriving - MultiParamTypeClasses - NamedFieldPuns - NoImplicitPrelude - OverloadedStrings - RankNTypes - RecordWildCards - StrictData - ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N - build-depends: - aeson - , async - , base - , containers - , extra - , gargantext - , hspec - , http-client - , http-client-tls - , mtl - , servant-job - , stm - , text - , time - default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 1f16c8c5..865a8536 100644 --- a/package.yaml +++ b/package.yaml @@ -494,7 +494,6 @@ executables: - aeson - serialise - tests: garg-test: main: Main.hs @@ -514,47 +513,35 @@ tests: - -rtsopts - -with-rtsopts=-N dependencies: + - QuickCheck - aeson + - async - base - boolexpr - bytestring - containers + - duckling - gargantext - gargantext-prelude - hspec - - QuickCheck - - quickcheck-instances - - time + - http-client + - http-client-tls + - mtl - parsec - patches-class - patches-map - duckling + - quickcheck-instances + - servant-job + - stm - tasty + - tasty-hspec - tasty-hunit - tasty-quickcheck - text + - time - unordered-containers - validity - jobqueue-test: - main: Main.hs - source-dirs: tests/queue - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - aeson - - async - - base - - containers - - gargantext - - mtl - - hspec - - http-client - - http-client-tls - - servant-job - - stm - - time # garg-doctest: # main: Main.hs # source-dirs: src-doctest diff --git a/src-test/Core/Text/Corpus/Query.hs b/src-test/Core/Text/Corpus/Query.hs index 891a50a1..4288b95b 100644 --- a/src-test/Core/Text/Corpus/Query.hs +++ b/src-test/Core/Text/Corpus/Query.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -module Core.Text.Corpus.Query where +module Core.Text.Corpus.Query (tests) where import Data.BoolExpr import Gargantext.Core.Text.Corpus.Query @@ -8,9 +8,6 @@ import Prelude import Test.Tasty import Test.Tasty.QuickCheck hiding (Positive) -main :: IO () -main = defaultMain tests - tests :: TestTree tests = testGroup "Boolean Query Engine" [ testProperty "Parses 'A OR B'" testParse01 diff --git a/src-test/Core/Utils.hs b/src-test/Core/Utils.hs index 434e6a97..e0f5cae6 100644 --- a/src-test/Core/Utils.hs +++ b/src-test/Core/Utils.hs @@ -18,8 +18,8 @@ import Gargantext.Prelude import Gargantext.Core.Utils -- | Core.Utils tests -test :: IO () -test = hspec $ do +test :: Spec +test = do describe "check if groupWithCounts works" $ do it "simple integer array" $ do (groupWithCounts [1, 2, 3, 1, 2, 3]) `shouldBe` [(1, 2), (2, 2), (3, 2)] diff --git a/src-test/Graph/Clustering.hs b/src-test/Graph/Clustering.hs index a59b62f1..cd212358 100644 --- a/src-test/Graph/Clustering.hs +++ b/src-test/Graph/Clustering.hs @@ -30,8 +30,8 @@ myCooc = HashMap.fromList [((NgramsTerm {unNgramsTerm = "gev au"},NgramsTerm {un -test :: IO () -test = hspec $ do +test :: Spec +test = do describe "Cross" $ do let (distanceMap,_,_) = doSimilarityMap Conditional 0 Weak myCooc diff --git a/src-test/Main.hs b/src-test/Main.hs index 6cc4887d..ad01ff8e 100644 --- a/src-test/Main.hs +++ b/src-test/Main.hs @@ -21,18 +21,32 @@ import qualified Parsers.Date as PD -- import qualified Graph.Distance as GD import qualified Graph.Clustering as Graph import qualified Utils.Crypto as Crypto +import qualified Utils.Jobs as Jobs + +import Test.Tasty +import Test.Tasty.Hspec main :: IO () main = do - Utils.test + utilSpec <- testSpec "Utils" Utils.test + clusteringSpec <- testSpec "Graph Clustering" Graph.test + dateParserSpec <- testSpec "Date Parsing" PD.testFromRFC3339 + cryptoSpec <- testSpec "Crypto" Crypto.test + nlpSpec <- testSpec "NLP" NLP.test + jobsSpec <- testSpec "Jobs" Jobs.test + + defaultMain $ testGroup "Gargantext" + [ utilSpec + , clusteringSpec + , dateParserSpec + , cryptoSpec + , nlpSpec + , jobsSpec + , NgramsQuery.tests + , CorpusQuery.tests + ] -- Occ.parsersTest -- Lang.ngramsExtractionTest FR -- Lang.ngramsExtractionTest EN -- Metrics.main - Graph.test - PD.testFromRFC3339 -- GD.test - Crypto.test - NLP.main - NgramsQuery.main - CorpusQuery.main diff --git a/src-test/Ngrams/NLP.hs b/src-test/Ngrams/NLP.hs index 921ac159..27b269f2 100644 --- a/src-test/Ngrams/NLP.hs +++ b/src-test/Ngrams/NLP.hs @@ -19,8 +19,8 @@ import Gargantext.Prelude import Gargantext.Core.Text.Terms.Multi -main :: IO () -main = hspec $ do +test :: Spec +test = do describe "Text that should be cleaned before sending it to NLP tools as micro-services." $ do let text = "This is a url http://cnrs.gargantext.org to be remove and another one www.gargantext.org and digits 343242-2332 to be remove and some to keep: 232 231 33." :: Text let result = "This is a url to be remove and another one and digits to be remove and some to keep: 232 231 33." diff --git a/src-test/Ngrams/Query.hs b/src-test/Ngrams/Query.hs index 47a3971a..626f23b4 100644 --- a/src-test/Ngrams/Query.hs +++ b/src-test/Ngrams/Query.hs @@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} -module Ngrams.Query where +module Ngrams.Query (tests) where import Control.Monad import Data.Coerce @@ -21,9 +21,6 @@ import Test.Tasty import Test.Tasty.HUnit -main :: IO () -main = defaultMain tests - tests :: TestTree tests = testGroup "Ngrams" [unitTests] diff --git a/src-test/Parsers/Date.hs b/src-test/Parsers/Date.hs index 6f6411be..85baa615 100644 --- a/src-test/Parsers/Date.hs +++ b/src-test/Parsers/Date.hs @@ -36,8 +36,8 @@ fromRFC3339Inv :: Either ParseError ZonedTime -> Text fromRFC3339Inv (Right z) = toRFC3339 z fromRFC3339Inv (Left pe) = panic . pack $ show pe -testFromRFC3339 :: IO () -testFromRFC3339 = hspec $ do +testFromRFC3339 :: Spec +testFromRFC3339 = do describe "Test fromRFC3339: " $ do it "is the inverse of Duckling's toRFC3339" $ property $ ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision diff --git a/src-test/Utils/Crypto.hs b/src-test/Utils/Crypto.hs index 13d9de4b..952bba13 100644 --- a/src-test/Utils/Crypto.hs +++ b/src-test/Utils/Crypto.hs @@ -16,11 +16,10 @@ import Test.Hspec import Gargantext.Prelude import Gargantext.Prelude.Crypto.Hash -import Gargantext.Prelude.Utils -- | Crypto Hash tests -test :: IO () -test = hspec $ do +test :: Spec +test = do describe "Hash String with frontend works" $ do let text = "To hash with backend" :: Text let hashed = "8a69a94d164279af2b7d1443ce08da6184b3d7e815406076e148159c284b53c3" :: Hash diff --git a/tests/queue/Main.hs b/src-test/Utils/Jobs.hs similarity index 96% rename from tests/queue/Main.hs rename to src-test/Utils/Jobs.hs index 87e0974e..d2ee585a 100644 --- a/tests/queue/Main.hs +++ b/src-test/Utils/Jobs.hs @@ -3,7 +3,7 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NumericUnderscores #-} -module Main where +module Utils.Jobs (test) where import Control.Concurrent import qualified Control.Concurrent.Async as Async @@ -54,16 +54,6 @@ addJobToSchedule jobt mvar = do data Counts = Counts { countAs :: Int, countBs :: Int } deriving (Eq, Show) -inc, dec :: JobT -> Counts -> Counts -inc A cs = cs { countAs = countAs cs + 1 } -inc B cs = cs { countBs = countBs cs + 1 } -inc C cs = cs -inc D cs = cs -dec A cs = cs { countAs = countAs cs - 1 } -dec B cs = cs { countBs = countBs cs - 1 } -dec C cs = cs -dec D cs = cs - jobDuration, initialDelay :: Int jobDuration = 100000 initialDelay = 20000 @@ -194,9 +184,6 @@ testTlsManager :: Manager testTlsManager = unsafePerformIO newTlsManager {-# NOINLINE testTlsManager #-} -shouldBeE :: (MonadIO m, HasCallStack, Show a, Eq a) => a -> a -> m () -shouldBeE a b = liftIO (shouldBe a b) - withJob :: Env -> (JobHandle MyDummyMonad -> () -> MyDummyMonad ()) -> IO (SJ.JobStatus 'SJ.Safe JobLog) @@ -362,8 +349,8 @@ testMarkProgress = do ] } -main :: IO () -main = hspec $ do +test :: Spec +test = do describe "job queue" $ do it "respects max runners limit" $ testMaxRunners -- 2.21.0