Merge pull request #10634 from cabalism/hlint/unused-lang-pragma
[cabal.git] / Cabal-syntax / src / Distribution / Types / TestSuite.hs
blob6b3107cae7191c68c09985aec050cd3c21cce1a8
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution.Types.TestSuite
5 ( TestSuite (..)
6 , emptyTestSuite
7 , testType
8 , testModules
9 , testModulesAutogen
10 ) where
12 import Distribution.Compat.Prelude
13 import Prelude ()
15 import Distribution.Types.BuildInfo
16 import Distribution.Types.TestSuiteInterface
17 import Distribution.Types.TestType
18 import Distribution.Types.UnqualComponentName
20 import Distribution.ModuleName
22 import qualified Distribution.Types.BuildInfo.Lens as L
24 -- | A \"test-suite\" stanza in a cabal file.
25 data TestSuite = TestSuite
26 { testName :: UnqualComponentName
27 , testInterface :: TestSuiteInterface
28 , testBuildInfo :: BuildInfo
29 , testCodeGenerators :: [String]
31 deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
33 instance L.HasBuildInfo TestSuite where
34 buildInfo f l = (\x -> l{testBuildInfo = x}) <$> f (testBuildInfo l)
36 instance Binary TestSuite
37 instance Structured TestSuite
39 instance NFData TestSuite where rnf = genericRnf
41 instance Monoid TestSuite where
42 mempty =
43 TestSuite
44 { testName = mempty
45 , testInterface = mempty
46 , testBuildInfo = mempty
47 , testCodeGenerators = mempty
49 mappend = (<>)
51 instance Semigroup TestSuite where
52 a <> b =
53 TestSuite
54 { testName = combineNames a b testName "test"
55 , testInterface = combine testInterface
56 , testBuildInfo = combine testBuildInfo
57 , testCodeGenerators = combine testCodeGenerators
59 where
60 combine field = field a `mappend` field b
62 emptyTestSuite :: TestSuite
63 emptyTestSuite = mempty
65 testType :: TestSuite -> TestType
66 testType test = case testInterface test of
67 TestSuiteExeV10 ver _ -> TestTypeExe ver
68 TestSuiteLibV09 ver _ -> TestTypeLib ver
69 TestSuiteUnsupported testtype -> testtype
71 -- | Get all the module names from a test suite.
72 testModules :: TestSuite -> [ModuleName]
73 testModules test =
74 ( case testInterface test of
75 TestSuiteLibV09 _ m -> [m]
76 _ -> []
78 ++ otherModules (testBuildInfo test)
80 -- | Get all the auto generated module names from a test suite.
81 -- This are a subset of 'testModules'.
82 testModulesAutogen :: TestSuite -> [ModuleName]
83 testModulesAutogen test = autogenModules (testBuildInfo test)