Make “sublibrary” standard terminology in docs
[cabal.git] / Cabal / src / Distribution / TestSuite.hs
blob5e6fa42dac26893b3b3d3509be20de51b531995b
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE RankNTypes #-}
4 -----------------------------------------------------------------------------
6 -- |
7 -- Module : Distribution.TestSuite
8 -- Copyright : Thomas Tuegel 2010
9 -- License : BSD3
11 -- Maintainer : cabal-devel@haskell.org
12 -- Portability : portable
14 -- This module defines the detailed test suite interface which makes it
15 -- possible to expose individual tests to Cabal or other test agents.
16 module Distribution.TestSuite
17 ( TestInstance (..)
18 , OptionDescr (..)
19 , OptionType (..)
20 , Test (..)
21 , Options
22 , Progress (..)
23 , Result (..)
24 , testGroup
25 ) where
27 import Distribution.Compat.Prelude
28 import Prelude ()
30 data TestInstance = TestInstance
31 { run :: IO Progress
32 -- ^ Perform the test.
33 , name :: String
34 -- ^ A name for the test, unique within a
35 -- test suite.
36 , tags :: [String]
37 -- ^ Users can select groups of tests by
38 -- their tags.
39 , options :: [OptionDescr]
40 -- ^ Descriptions of the options recognized
41 -- by this test.
42 , setOption :: String -> String -> Either String TestInstance
43 -- ^ Try to set the named option to the given value. Returns an error
44 -- message if the option is not supported or the value could not be
45 -- correctly parsed; otherwise, a 'TestInstance' with the option set to
46 -- the given value is returned.
49 data OptionDescr = OptionDescr
50 { optionName :: String
51 , optionDescription :: String
52 -- ^ A human-readable description of the
53 -- option to guide the user setting it.
54 , optionType :: OptionType
55 , optionDefault :: Maybe String
57 deriving (Eq, Read, Show)
59 data OptionType
60 = OptionFile
61 { optionFileMustExist :: Bool
62 , optionFileIsDir :: Bool
63 , optionFileExtensions :: [String]
65 | OptionString
66 { optionStringMultiline :: Bool
68 | OptionNumber
69 { optionNumberIsInt :: Bool
70 , optionNumberBounds :: (Maybe String, Maybe String)
72 | OptionBool
73 | OptionEnum [String]
74 | OptionSet [String]
75 | OptionRngSeed
76 deriving (Eq, Read, Show)
78 data Test
79 = Test TestInstance
80 | Group
81 { groupName :: String
82 , concurrently :: Bool
83 -- ^ If true, then children of this group may be run in parallel.
84 -- Note that this setting is not inherited by children. In
85 -- particular, consider a group F with "concurrently = False" that
86 -- has some children, including a group T with "concurrently =
87 -- True". The children of group T may be run concurrently with each
88 -- other, as long as none are run at the same time as any of the
89 -- direct children of group F.
90 , groupTests :: [Test]
92 | ExtraOptions [OptionDescr] Test
94 type Options = [(String, String)]
96 data Progress
97 = Finished Result
98 | Progress String (IO Progress)
100 data Result
101 = Pass
102 | Fail String
103 | Error String
104 deriving (Eq, Read, Show)
106 -- | Create a named group of tests, which are assumed to be safe to run in
107 -- parallel.
108 testGroup :: String -> [Test] -> Test
109 testGroup n ts = Group{groupName = n, concurrently = True, groupTests = ts}