module Test.Framework.TestTypes (
TestID, Assertion, Test(..), TestSuite(..), TestSort(..),
TestPath(..), GenFlatTest(..), FlatTest, TestFilter,
testPathToList, flatName,
TR, TestState(..), initTestState, TestConfig(..), TestOutput(..),
ReportAllTests, ReportGlobalStart, ReportTestStart, ReportTestResult, ReportGlobalResults,
TestReporter(..),
TestResult(..), FlatTestResult, Milliseconds, RunResult(..)
) where
import Test.Framework.Location
import Control.Monad.RWS
import System.IO
import Data.Maybe
import qualified Data.List as List
type Assertion = IO ()
type TestID = String
data TestSort = UnitTest | QuickCheckTest | BlackBoxTest
deriving (Eq,Show,Read)
data Test = BaseTest TestSort TestID (Maybe Location) Assertion
| CompoundTest TestSuite
data TestSuite = TestSuite TestID [Test]
| AnonTestSuite [Test]
data TestPath = TestPathBase TestID
| TestPathCompound (Maybe TestID) TestPath
testPathToList :: TestPath -> [Maybe TestID]
testPathToList (TestPathBase i) = [Just i]
testPathToList (TestPathCompound mi p) =
mi : testPathToList p
flatName :: TestPath -> String
flatName p =
List.intercalate ":" (map (fromMaybe "") (testPathToList p))
data GenFlatTest a
= FlatTest
{ ft_sort :: TestSort
, ft_path :: TestPath
, ft_location :: Maybe Location
, ft_payload :: a
}
type FlatTest = GenFlatTest Assertion
type TestFilter = FlatTest -> Bool
data TestResult = Pass | Pending | Fail | Error
deriving (Show, Read, Eq)
type Milliseconds = Int
data RunResult
= RunResult
{ rr_result :: TestResult
, rr_location :: Maybe Location
, rr_callers :: [(Maybe String, Location)]
, rr_message :: String
, rr_wallTimeMs :: Milliseconds
}
type FlatTestResult = GenFlatTest RunResult
data TestState = TestState { ts_results :: [FlatTestResult]
, ts_index :: Int
}
initTestState :: TestState
initTestState = TestState [] 0
type TR = RWST TestConfig () TestState IO
data TestOutput = TestOutputHandle Handle Bool
| TestOutputSplitted FilePath
deriving (Show, Eq)
data TestConfig
= TestConfig
{ tc_quiet :: Bool
, tc_output :: TestOutput
, tc_filter :: TestFilter
, tc_reporters :: [TestReporter]
}
instance Show TestConfig where
showsPrec prec tc =
showParen (prec > 0) $
showString "TestConfig { " .
showString "tc_quiet=" . showsPrec 1 (tc_quiet tc) .
showString ", tc_output=" . showsPrec 1 (tc_output tc) .
showString ", tc_filter=<filter>" .
showString ", tc_reporters=" . showsPrec 1 (tc_reporters tc) .
showString " }"
data TestReporter
= TestReporter
{ tr_id :: String
, tr_reportAllTests :: ReportAllTests
, tr_reportGlobalStart :: ReportGlobalStart
, tr_reportTestStart :: ReportTestStart
, tr_reportTestResult :: ReportTestResult
, tr_reportGlobalResults :: ReportGlobalResults
}
instance Show TestReporter where
showsPrec _ x = showString (tr_id x)
instance Eq TestReporter where
x == y = (tr_id x) == (tr_id y)
type ReportAllTests = [FlatTest] -> TR ()
type ReportGlobalStart = [FlatTest] -> TR ()
type ReportTestStart = FlatTest -> TR ()
type ReportTestResult = FlatTestResult -> TR ()
type ReportGlobalResults = Milliseconds
-> [FlatTestResult]
-> [FlatTestResult]
-> [FlatTestResult]
-> [FlatTestResult]
-> TR ()