2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE DerivingStrategies #-}
4 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
6 -- | Exception type like 'ExitCode' but with more information
8 module Test
.Cabal
.TestCode
(
16 isTestCodeUnexpectedSuccess
,
19 import Control
.Exception
(Exception
(..))
20 import Data
.Typeable
(Typeable
)
22 -------------------------------------------------------------------------------
24 -------------------------------------------------------------------------------
29 | TestCodeKnownFail IssueID
30 | TestCodeUnexpectedOk IssueID
32 | TestCodeFlakyFailed IssueID
33 | TestCodeFlakyPassed IssueID
34 deriving (Eq
, Show, Read, Typeable
)
36 instance Exception TestCode
38 displayException
= displayTestCode
40 displayTestCode
:: TestCode
-> String
41 displayTestCode TestCodeOk
= "OK"
42 displayTestCode
(TestCodeSkip msg
) = "SKIP " ++ msg
43 displayTestCode
(TestCodeKnownFail t
) = "OK (known failure, see #" <> show t
<> ")"
44 displayTestCode
(TestCodeUnexpectedOk t
) = "FAIL (unexpected success, see #" <> show t
<> ")"
45 displayTestCode TestCodeFail
= "FAIL"
46 displayTestCode
(TestCodeFlakyFailed t
) = "FLAKY (FAIL, see #" <> show t
<> ")"
47 displayTestCode
(TestCodeFlakyPassed t
) = "FLAKY (OK, see #" <> show t
<> ")"
49 isTestCodeSkip
:: TestCode
-> Bool
50 isTestCodeSkip
(TestCodeSkip _
) = True
51 isTestCodeSkip _
= False
53 type TestPassed
= Bool
55 newtype IssueID
= IssueID
Int
56 deriving newtype (Eq
, Typeable
, Num
, Show, Read)
60 | Flaky TestPassed IssueID
62 isTestCodeFlaky
:: TestCode
-> FlakyStatus
63 isTestCodeFlaky
(TestCodeFlakyPassed t
) = Flaky
True t
64 isTestCodeFlaky
(TestCodeFlakyFailed t
) = Flaky
False t
65 isTestCodeFlaky _
= NotFlaky
67 isTestCodeUnexpectedSuccess
:: TestCode
-> Maybe IssueID
68 isTestCodeUnexpectedSuccess
(TestCodeUnexpectedOk t
) = Just t
69 isTestCodeUnexpectedSuccess _
= Nothing