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

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

import Prelude ()
import Distribution.Compat.Prelude

import Distribution.Types.BuildInfo
import Distribution.Types.TestType
import Distribution.Types.TestSuiteInterface
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. 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
$cto :: forall x. Rep TestSuite x -> TestSuite
$cfrom :: forall x. TestSuite -> Rep TestSuite x
Generic, Int -> TestSuite -> ShowS
[TestSuite] -> ShowS
TestSuite -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TestSuite] -> ShowS
$cshowList :: [TestSuite] -> ShowS
show :: TestSuite -> String
$cshow :: TestSuite -> String
showsPrec :: Int -> TestSuite -> ShowS
$cshowsPrec :: Int -> TestSuite -> ShowS
Show, ReadPrec [TestSuite]
ReadPrec TestSuite
Int -> ReadS TestSuite
ReadS [TestSuite]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TestSuite]
$creadListPrec :: ReadPrec [TestSuite]
readPrec :: ReadPrec TestSuite
$creadPrec :: ReadPrec TestSuite
readList :: ReadS [TestSuite]
$creadList :: ReadS [TestSuite]
readsPrec :: Int -> ReadS TestSuite
$creadsPrec :: Int -> ReadS TestSuite
Read, TestSuite -> TestSuite -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TestSuite -> TestSuite -> Bool
$c/= :: TestSuite -> TestSuite -> Bool
== :: TestSuite -> TestSuite -> Bool
$c== :: TestSuite -> TestSuite -> Bool
Eq, Eq 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
min :: TestSuite -> TestSuite -> TestSuite
$cmin :: TestSuite -> TestSuite -> TestSuite
max :: TestSuite -> TestSuite -> TestSuite
$cmax :: TestSuite -> TestSuite -> TestSuite
>= :: TestSuite -> TestSuite -> Bool
$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
compare :: TestSuite -> TestSuite -> Ordering
$ccompare :: TestSuite -> TestSuite -> Ordering
Ord, Typeable, Typeable TestSuite
TestSuite -> DataType
TestSuite -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestSuite -> m TestSuite
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TestSuite -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TestSuite -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> TestSuite -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TestSuite -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestSuite -> r
gmapT :: (forall b. Data b => b -> b) -> TestSuite -> TestSuite
$cgmapT :: (forall b. Data b => b -> b) -> TestSuite -> TestSuite
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestSuite)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestSuite)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestSuite)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestSuite)
dataTypeOf :: TestSuite -> DataType
$cdataTypeOf :: TestSuite -> DataType
toConstr :: TestSuite -> Constr
$ctoConstr :: TestSuite -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestSuite
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestSuite
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestSuite -> c TestSuite
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestSuite -> c TestSuite
Data)

instance L.HasBuildInfo TestSuite where
    buildInfo :: Lens' TestSuite BuildInfo
buildInfo BuildInfo -> f BuildInfo
f TestSuite
l = (\BuildInfo
x -> TestSuite
l { testBuildInfo :: BuildInfo
testBuildInfo = BuildInfo
x }) 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 = forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

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

instance Semigroup TestSuite where
    TestSuite
a <> :: TestSuite -> TestSuite -> TestSuite
<> TestSuite
b = TestSuite {
        testName :: UnqualComponentName
testName      = (TestSuite -> UnqualComponentName) -> UnqualComponentName
combine' TestSuite -> UnqualComponentName
testName,
        testInterface :: TestSuiteInterface
testInterface = forall {a}. Monoid a => (TestSuite -> a) -> a
combine  TestSuite -> TestSuiteInterface
testInterface,
        testBuildInfo :: BuildInfo
testBuildInfo = forall {a}. Monoid a => (TestSuite -> a) -> a
combine  TestSuite -> BuildInfo
testBuildInfo,
        testCodeGenerators :: [String]
testCodeGenerators = 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 forall a. Monoid a => a -> a -> a
`mappend` TestSuite -> a
field TestSuite
b
              combine' :: (TestSuite -> UnqualComponentName) -> UnqualComponentName
combine' TestSuite -> UnqualComponentName
field = case ( UnqualComponentName -> String
unUnqualComponentName forall a b. (a -> b) -> a -> b
$ TestSuite -> UnqualComponentName
field TestSuite
a
                                    , UnqualComponentName -> String
unUnqualComponentName forall a b. (a -> b) -> a -> b
$ TestSuite -> UnqualComponentName
field TestSuite
b) of
                        (String
"", String
_) -> TestSuite -> UnqualComponentName
field TestSuite
b
                        (String
_, String
"") -> TestSuite -> UnqualComponentName
field TestSuite
a
                        (String
x, String
y) -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"Ambiguous values for test field: '"
                            forall a. [a] -> [a] -> [a]
++ String
x forall a. [a] -> [a] -> [a]
++ String
"' and '" forall a. [a] -> [a] -> [a]
++ String
y forall a. [a] -> [a] -> [a]
++ String
"'"

emptyTestSuite :: TestSuite
emptyTestSuite :: TestSuite
emptyTestSuite = 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
_                   -> [])
                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)