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

module Distribution.Types.TestType (
    TestType(..),
    knownTestTypes,
) where

import Distribution.Compat.Prelude
import Distribution.Version
import Prelude ()

import Distribution.Parsec
import Distribution.Pretty
import Text.PrettyPrint    (char, text)

-- | The \"test-type\" field in the test suite stanza.
--
data TestType = TestTypeExe Version     -- ^ \"type: exitcode-stdio-x.y\"
              | TestTypeLib Version     -- ^ \"type: detailed-x.y\"
              | TestTypeUnknown String Version -- ^ Some unknown test type e.g. \"type: foo\"
    deriving ((forall x. TestType -> Rep TestType x)
-> (forall x. Rep TestType x -> TestType) -> Generic TestType
forall x. Rep TestType x -> TestType
forall x. TestType -> Rep TestType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TestType -> Rep TestType x
from :: forall x. TestType -> Rep TestType x
$cto :: forall x. Rep TestType x -> TestType
to :: forall x. Rep TestType x -> TestType
Generic, Int -> TestType -> ShowS
[TestType] -> ShowS
TestType -> String
(Int -> TestType -> ShowS)
-> (TestType -> String) -> ([TestType] -> ShowS) -> Show TestType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestType -> ShowS
showsPrec :: Int -> TestType -> ShowS
$cshow :: TestType -> String
show :: TestType -> String
$cshowList :: [TestType] -> ShowS
showList :: [TestType] -> ShowS
Show, ReadPrec [TestType]
ReadPrec TestType
Int -> ReadS TestType
ReadS [TestType]
(Int -> ReadS TestType)
-> ReadS [TestType]
-> ReadPrec TestType
-> ReadPrec [TestType]
-> Read TestType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TestType
readsPrec :: Int -> ReadS TestType
$creadList :: ReadS [TestType]
readList :: ReadS [TestType]
$creadPrec :: ReadPrec TestType
readPrec :: ReadPrec TestType
$creadListPrec :: ReadPrec [TestType]
readListPrec :: ReadPrec [TestType]
Read, TestType -> TestType -> Bool
(TestType -> TestType -> Bool)
-> (TestType -> TestType -> Bool) -> Eq TestType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestType -> TestType -> Bool
== :: TestType -> TestType -> Bool
$c/= :: TestType -> TestType -> Bool
/= :: TestType -> TestType -> Bool
Eq, Typeable, Typeable TestType
Typeable TestType
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> TestType -> c TestType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c TestType)
-> (TestType -> Constr)
-> (TestType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c TestType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestType))
-> ((forall b. Data b => b -> b) -> TestType -> TestType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> TestType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> TestType -> r)
-> (forall u. (forall d. Data d => d -> u) -> TestType -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> TestType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> TestType -> m TestType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TestType -> m TestType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TestType -> m TestType)
-> Data TestType
TestType -> Constr
TestType -> DataType
(forall b. Data b => b -> b) -> TestType -> TestType
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) -> TestType -> u
forall u. (forall d. Data d => d -> u) -> TestType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TestType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestType -> c TestType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestType)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestType -> c TestType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TestType -> c TestType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestType
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TestType
$ctoConstr :: TestType -> Constr
toConstr :: TestType -> Constr
$cdataTypeOf :: TestType -> DataType
dataTypeOf :: TestType -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TestType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestType)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TestType)
$cgmapT :: (forall b. Data b => b -> b) -> TestType -> TestType
gmapT :: (forall b. Data b => b -> b) -> TestType -> TestType
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TestType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TestType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TestType -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TestType -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> TestType -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TestType -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TestType -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TestType -> m TestType
Data)

instance Binary TestType
instance Structured TestType

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

knownTestTypes :: [TestType]
knownTestTypes :: [TestType]
knownTestTypes = [ Version -> TestType
TestTypeExe ([Int] -> Version
mkVersion [Int
1,Int
0])
                 , Version -> TestType
TestTypeLib ([Int] -> Version
mkVersion [Int
0,Int
9]) ]

instance Pretty TestType where
  pretty :: TestType -> Doc
pretty (TestTypeExe Version
ver)          = String -> Doc
text String
"exitcode-stdio-" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
ver
  pretty (TestTypeLib Version
ver)          = String -> Doc
text String
"detailed-"       Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
ver
  pretty (TestTypeUnknown String
name Version
ver) = String -> Doc
text String
name Doc -> Doc -> Doc
<<>> Char -> Doc
char Char
'-' Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
ver

instance Parsec TestType where
  parsec :: forall (m :: * -> *). CabalParsing m => m TestType
parsec = (Version -> String -> TestType) -> m TestType
forall (m :: * -> *) ver a.
(CabalParsing m, Parsec ver) =>
(ver -> String -> a) -> m a
parsecStandard ((Version -> String -> TestType) -> m TestType)
-> (Version -> String -> TestType) -> m TestType
forall a b. (a -> b) -> a -> b
$ \Version
ver String
name -> case String
name of
      String
"exitcode-stdio" -> Version -> TestType
TestTypeExe Version
ver
      String
"detailed"       -> Version -> TestType
TestTypeLib Version
ver
      String
_                -> String -> Version -> TestType
TestTypeUnknown String
name Version
ver