{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}

module Distribution.Types.TestSuite
  ( TestSuite (..)
  , emptyTestSuite
  , testType
  , testModules
  , testModulesAutogen
  ) where

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Types.BuildInfo
import Distribution.Types.TestSuiteInterface
import Distribution.Types.TestType
import Distribution.Types.UnqualComponentName

import Distribution.ModuleName

import qualified Distribution.Types.BuildInfo.Lens as L

-- | A \"test-suite\" stanza in a cabal file.
data TestSuite = TestSuite
  { TestSuite -> UnqualComponentName
testName :: UnqualComponentName
  , TestSuite -> TestSuiteInterface
testInterface :: TestSuiteInterface
  , TestSuite -> BuildInfo
testBuildInfo :: BuildInfo
  , TestSuite -> [String]
testCodeGenerators :: [String]
  }
  deriving ((forall x. TestSuite -> Rep TestSuite x)
-> (forall x. Rep TestSuite x -> TestSuite) -> Generic TestSuite
forall x. Rep TestSuite x -> TestSuite
forall x. TestSuite -> Rep TestSuite x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TestSuite -> Rep TestSuite x
from :: forall x. TestSuite -> Rep TestSuite x
$cto :: forall x. Rep TestSuite x -> TestSuite
to :: forall x. Rep TestSuite x -> TestSuite
Generic, Int -> TestSuite -> ShowS
[TestSuite] -> ShowS
TestSuite -> String
(Int -> TestSuite -> ShowS)
-> (TestSuite -> String)
-> ([TestSuite] -> ShowS)
-> Show TestSuite
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestSuite -> ShowS
showsPrec :: Int -> TestSuite -> ShowS
$cshow :: TestSuite -> String
show :: TestSuite -> String
$cshowList :: [TestSuite] -> ShowS
showList :: [TestSuite] -> ShowS
Show, ReadPrec [TestSuite]
ReadPrec TestSuite
Int -> ReadS TestSuite
ReadS [TestSuite]
(Int -> ReadS TestSuite)
-> ReadS [TestSuite]
-> ReadPrec TestSuite
-> ReadPrec [TestSuite]
-> Read TestSuite
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TestSuite
readsPrec :: Int -> ReadS TestSuite
$creadList :: ReadS [TestSuite]
readList :: ReadS [TestSuite]
$creadPrec :: ReadPrec TestSuite
readPrec :: ReadPrec TestSuite
$creadListPrec :: ReadPrec [TestSuite]
readListPrec :: ReadPrec [TestSuite]
Read, TestSuite -> TestSuite -> Bool
(TestSuite -> TestSuite -> Bool)
-> (TestSuite -> TestSuite -> Bool) -> Eq TestSuite
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestSuite -> TestSuite -> Bool
== :: TestSuite -> TestSuite -> Bool
$c/= :: TestSuite -> TestSuite -> Bool
/= :: TestSuite -> TestSuite -> Bool
Eq, Eq TestSuite
Eq TestSuite =>
(TestSuite -> TestSuite -> Ordering)
-> (TestSuite -> TestSuite -> Bool)
-> (TestSuite -> TestSuite -> Bool)
-> (TestSuite -> TestSuite -> Bool)
-> (TestSuite -> TestSuite -> Bool)
-> (TestSuite -> TestSuite -> TestSuite)
-> (TestSuite -> TestSuite -> TestSuite)
-> Ord TestSuite
TestSuite -> TestSuite -> Bool
TestSuite -> TestSuite -> Ordering
TestSuite -> TestSuite -> TestSuite
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TestSuite -> TestSuite -> Ordering
compare :: TestSuite -> TestSuite -> Ordering
$c< :: TestSuite -> TestSuite -> Bool
< :: TestSuite -> TestSuite -> Bool
$c<= :: TestSuite -> TestSuite -> Bool
<= :: TestSuite -> TestSuite -> Bool
$c> :: TestSuite -> TestSuite -> Bool
> :: TestSuite -> TestSuite -> Bool
$c>= :: TestSuite -> TestSuite -> Bool
>= :: TestSuite -> TestSuite -> Bool
$cmax :: TestSuite -> TestSuite -> TestSuite
max :: TestSuite -> TestSuite -> TestSuite
$cmin :: TestSuite -> TestSuite -> TestSuite
min :: TestSuite -> TestSuite -> TestSuite
Ord, Typeable, Typeable TestSuite
Typeable TestSuite =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> TestSuite -> c TestSuite)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c TestSuite)
-> (TestSuite -> Constr)
-> (TestSuite -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c TestSuite))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestSuite))
-> ((forall b. Data b => b -> b) -> TestSuite -> TestSuite)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> TestSuite -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> TestSuite -> r)
-> (forall u. (forall d. Data d => d -> u) -> TestSuite -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> TestSuite -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> TestSuite -> m TestSuite)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TestSuite -> m TestSuite)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TestSuite -> m TestSuite)
-> Data TestSuite
TestSuite -> Constr
TestSuite -> DataType
(forall b. Data b => b -> b) -> TestSuite -> TestSuite
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TestSuite -> u
forall u. (forall d. Data d => d -> u) -> TestSuite -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestSuite
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestSuite -> c TestSuite
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestSuite)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestSuite)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestSuite -> c TestSuite
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestSuite -> c TestSuite
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestSuite
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestSuite
$ctoConstr :: TestSuite -> Constr
toConstr :: TestSuite -> Constr
$cdataTypeOf :: TestSuite -> DataType
dataTypeOf :: TestSuite -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestSuite)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestSuite)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestSuite)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestSuite)
$cgmapT :: (forall b. Data b => b -> b) -> TestSuite -> TestSuite
gmapT :: (forall b. Data b => b -> b) -> TestSuite -> TestSuite
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TestSuite -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> TestSuite -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TestSuite -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TestSuite -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
Data)

instance L.HasBuildInfo TestSuite where
  buildInfo :: Lens' TestSuite BuildInfo
buildInfo BuildInfo -> f BuildInfo
f TestSuite
l = (\BuildInfo
x -> TestSuite
l{testBuildInfo = x}) (BuildInfo -> TestSuite) -> f BuildInfo -> f TestSuite
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BuildInfo -> f BuildInfo
f (TestSuite -> BuildInfo
testBuildInfo TestSuite
l)

instance Binary TestSuite
instance Structured TestSuite

instance NFData TestSuite where rnf :: TestSuite -> ()
rnf = TestSuite -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

instance Monoid TestSuite where
  mempty :: TestSuite
mempty =
    TestSuite
      { testName :: UnqualComponentName
testName = UnqualComponentName
forall a. Monoid a => a
mempty
      , testInterface :: TestSuiteInterface
testInterface = TestSuiteInterface
forall a. Monoid a => a
mempty
      , testBuildInfo :: BuildInfo
testBuildInfo = BuildInfo
forall a. Monoid a => a
mempty
      , testCodeGenerators :: [String]
testCodeGenerators = [String]
forall a. Monoid a => a
mempty
      }
  mappend :: TestSuite -> TestSuite -> TestSuite
mappend = TestSuite -> TestSuite -> TestSuite
forall a. Semigroup a => a -> a -> a
(<>)

instance Semigroup TestSuite where
  TestSuite
a <> :: TestSuite -> TestSuite -> TestSuite
<> TestSuite
b =
    TestSuite
      { testName :: UnqualComponentName
testName = TestSuite
-> TestSuite
-> (TestSuite -> UnqualComponentName)
-> String
-> UnqualComponentName
forall b a.
(Monoid b, Eq b, Show b) =>
a -> a -> (a -> b) -> String -> b
combineNames TestSuite
a TestSuite
b TestSuite -> UnqualComponentName
testName String
"test"
      , testInterface :: TestSuiteInterface
testInterface = (TestSuite -> TestSuiteInterface) -> TestSuiteInterface
forall {a}. Monoid a => (TestSuite -> a) -> a
combine TestSuite -> TestSuiteInterface
testInterface
      , testBuildInfo :: BuildInfo
testBuildInfo = (TestSuite -> BuildInfo) -> BuildInfo
forall {a}. Monoid a => (TestSuite -> a) -> a
combine TestSuite -> BuildInfo
testBuildInfo
      , testCodeGenerators :: [String]
testCodeGenerators = (TestSuite -> [String]) -> [String]
forall {a}. Monoid a => (TestSuite -> a) -> a
combine TestSuite -> [String]
testCodeGenerators
      }
    where
      combine :: (TestSuite -> a) -> a
combine TestSuite -> a
field = TestSuite -> a
field TestSuite
a a -> a -> a
forall a. Monoid a => a -> a -> a
`mappend` TestSuite -> a
field TestSuite
b

emptyTestSuite :: TestSuite
emptyTestSuite :: TestSuite
emptyTestSuite = TestSuite
forall a. Monoid a => a
mempty

testType :: TestSuite -> TestType
testType :: TestSuite -> TestType
testType TestSuite
test = case TestSuite -> TestSuiteInterface
testInterface TestSuite
test of
  TestSuiteExeV10 Version
ver String
_ -> Version -> TestType
TestTypeExe Version
ver
  TestSuiteLibV09 Version
ver ModuleName
_ -> Version -> TestType
TestTypeLib Version
ver
  TestSuiteUnsupported TestType
testtype -> TestType
testtype

-- | Get all the module names from a test suite.
testModules :: TestSuite -> [ModuleName]
testModules :: TestSuite -> [ModuleName]
testModules TestSuite
test =
  ( case TestSuite -> TestSuiteInterface
testInterface TestSuite
test of
      TestSuiteLibV09 Version
_ ModuleName
m -> [ModuleName
m]
      TestSuiteInterface
_ -> []
  )
    [ModuleName] -> [ModuleName] -> [ModuleName]
forall a. [a] -> [a] -> [a]
++ BuildInfo -> [ModuleName]
otherModules (TestSuite -> BuildInfo
testBuildInfo TestSuite
test)

-- | Get all the auto generated module names from a test suite.
-- This are a subset of 'testModules'.
testModulesAutogen :: TestSuite -> [ModuleName]
testModulesAutogen :: TestSuite -> [ModuleName]
testModulesAutogen TestSuite
test = BuildInfo -> [ModuleName]
autogenModules (TestSuite -> BuildInfo
testBuildInfo TestSuite
test)