{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
module Test.HUnit.DejaFu
(
testAuto
, testDejafu
, testDejafus
, testAutoWay
, testDejafuWay
, testDejafusWay
, testAutoWithSettings
, testDejafuWithSettings
, testDejafusWithSettings
, Condition
, Predicate
, ProPredicate(..)
, module Test.DejaFu.Settings
, Program
, Basic
, ConcT
, ConcIO
, WithSetup
, WithSetupAndTeardown
, withSetup
, withTeardown
, withSetupAndTeardown
, Invariant
, registerInvariant
, inspectIORef
, inspectMVar
, inspectTVar
, testProperty
, testPropertyFor
, R.Sig(..)
, R.RefinementProperty
, R.Testable(..)
, R.Listable(..)
, R.expectFailure
, R.refines, (R.=>=)
, R.strictlyRefines, (R.->-)
, R.equivalentTo, (R.===)
) where
import Control.Monad.Catch (try)
import qualified Data.Foldable as F
import Data.List (intercalate, intersperse)
import Test.DejaFu hiding (Testable(..))
import qualified Test.DejaFu.Conc as Conc
import qualified Test.DejaFu.Refinement as R
import qualified Test.DejaFu.SCT as SCT
import qualified Test.DejaFu.Settings
import qualified Test.DejaFu.Types as D
import Test.HUnit (Assertable(..), Test(..), Testable(..),
assertFailure, assertString)
import Test.HUnit.Lang (HUnitFailure(..))
instance Testable (Conc.ConcIO ()) where
test :: HasCallStack => ConcIO () -> Test
test ConcIO ()
conc = Assertion -> Test
TestCase (ConcIO () -> Assertion
forall t. (Assertable t, HasCallStack) => t -> Assertion
assert ConcIO ()
conc)
instance Assertable (Conc.ConcIO ()) where
assert :: HasCallStack => ConcIO () -> Assertion
assert ConcIO ()
conc = do
[(Either Condition (Either HUnitFailure ()), Trace)]
traces <- Settings IO (Either HUnitFailure ())
-> Program Basic IO (Either HUnitFailure ())
-> IO [(Either Condition (Either HUnitFailure ()), Trace)]
forall (n :: * -> *) a pty.
MonadDejaFu n =>
Settings n a -> Program pty n a -> n [(Either Condition a, Trace)]
SCT.runSCTWithSettings (Lens'
(Settings IO (Either HUnitFailure ()))
(Maybe
(Either Condition (Either HUnitFailure ()) -> Maybe Discard))
-> Maybe
(Either Condition (Either HUnitFailure ()) -> Maybe Discard)
-> Settings IO (Either HUnitFailure ())
-> Settings IO (Either HUnitFailure ())
forall s a. Lens' s a -> a -> s -> s
set (Maybe (Either Condition (Either HUnitFailure ()) -> Maybe Discard)
-> f (Maybe
(Either Condition (Either HUnitFailure ()) -> Maybe Discard)))
-> Settings IO (Either HUnitFailure ())
-> f (Settings IO (Either HUnitFailure ()))
Lens'
(Settings IO (Either HUnitFailure ()))
(Maybe
(Either Condition (Either HUnitFailure ()) -> Maybe Discard))
forall (n :: * -> *) a (f :: * -> *).
Functor f =>
(Maybe (Either Condition a -> Maybe Discard)
-> f (Maybe (Either Condition a -> Maybe Discard)))
-> Settings n a -> f (Settings n a)
ldiscard ((Either Condition (Either HUnitFailure ()) -> Maybe Discard)
-> Maybe
(Either Condition (Either HUnitFailure ()) -> Maybe Discard)
forall a. a -> Maybe a
Just (ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ())
-> Either Condition (Either HUnitFailure ()) -> Maybe Discard
forall a b. ProPredicate a b -> Either Condition a -> Maybe Discard
pdiscard ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ())
assertableP)) Settings IO (Either HUnitFailure ())
forall (n :: * -> *) a. Applicative n => Settings n a
defaultSettings) (ConcIO () -> Program Basic IO (Either HUnitFailure ())
forall (m :: * -> *) e a.
(HasCallStack, MonadCatch m, Exception e) =>
m a -> m (Either e a)
try ConcIO ()
conc)
HasCallStack => String -> Assertion
String -> Assertion
assertString (String -> Assertion)
-> (Result (Either HUnitFailure ()) -> String)
-> Result (Either HUnitFailure ())
-> Assertion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Result (Either HUnitFailure ()) -> String
forall a. Show a => Result a -> String
showErr (Result (Either HUnitFailure ()) -> Assertion)
-> Result (Either HUnitFailure ()) -> Assertion
forall a b. (a -> b) -> a -> b
$ ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ())
-> [(Either Condition (Either HUnitFailure ()), Trace)]
-> Result (Either HUnitFailure ())
forall a b.
ProPredicate a b -> [(Either Condition a, Trace)] -> Result b
peval ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ())
assertableP [(Either Condition (Either HUnitFailure ()), Trace)]
traces
assertableP :: Predicate (Either HUnitFailure ())
assertableP :: ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ())
assertableP = (Either Condition (Either HUnitFailure ()) -> Bool)
-> ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ())
forall a. (Either Condition a -> Bool) -> Predicate a
alwaysTrue ((Either Condition (Either HUnitFailure ()) -> Bool)
-> ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ()))
-> (Either Condition (Either HUnitFailure ()) -> Bool)
-> ProPredicate (Either HUnitFailure ()) (Either HUnitFailure ())
forall a b. (a -> b) -> a -> b
$ \case
Right (Left HUnitFailure {}) -> Bool
False
Either Condition (Either HUnitFailure ())
_ -> Bool
True
testAuto :: (Eq a, Show a)
=> Program pty IO a
-> Test
testAuto :: forall a pty. (Eq a, Show a) => Program pty IO a -> Test
testAuto = Settings IO a -> Program pty IO a -> Test
forall a pty.
(Eq a, Show a) =>
Settings IO a -> Program pty IO a -> Test
testAutoWithSettings Settings IO a
forall (n :: * -> *) a. Applicative n => Settings n a
defaultSettings
testAutoWay :: (Eq a, Show a)
=> Way
-> MemType
-> Program pty IO a
-> Test
testAutoWay :: forall a pty.
(Eq a, Show a) =>
Way -> MemType -> Program pty IO a -> Test
testAutoWay Way
way = Settings IO a -> Program pty IO a -> Test
forall a pty.
(Eq a, Show a) =>
Settings IO a -> Program pty IO a -> Test
testAutoWithSettings (Settings IO a -> Program pty IO a -> Test)
-> (MemType -> Settings IO a)
-> MemType
-> Program pty IO a
-> Test
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Way -> MemType -> Settings IO a
forall (n :: * -> *) a.
Applicative n =>
Way -> MemType -> Settings n a
fromWayAndMemType Way
way
testAutoWithSettings :: (Eq a, Show a)
=> Settings IO a
-> Program pty IO a
-> Test
testAutoWithSettings :: forall a pty.
(Eq a, Show a) =>
Settings IO a -> Program pty IO a -> Test
testAutoWithSettings Settings IO a
settings = Settings IO a
-> [(String, ProPredicate a a)] -> Program pty IO a -> Test
forall b a pty.
Show b =>
Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
testDejafusWithSettings Settings IO a
settings
[(String
"Never Deadlocks", ProPredicate a a -> ProPredicate a a
forall b a. Eq b => ProPredicate a b -> ProPredicate a b
representative ProPredicate a a
forall a. Predicate a
deadlocksNever)
, (String
"No Exceptions", ProPredicate a a -> ProPredicate a a
forall b a. Eq b => ProPredicate a b -> ProPredicate a b
representative ProPredicate a a
forall a. Predicate a
exceptionsNever)
, (String
"Consistent Result", ProPredicate a a
forall a. Eq a => Predicate a
alwaysSame)
]
testDejafu :: Show b
=> String
-> ProPredicate a b
-> Program pty IO a
-> Test
testDejafu :: forall b a pty.
Show b =>
String -> ProPredicate a b -> Program pty IO a -> Test
testDejafu = Settings IO a
-> String -> ProPredicate a b -> Program pty IO a -> Test
forall b a p.
Show b =>
Settings IO a
-> String -> ProPredicate a b -> Program p IO a -> Test
testDejafuWithSettings Settings IO a
forall (n :: * -> *) a. Applicative n => Settings n a
defaultSettings
testDejafuWay :: Show b
=> Way
-> MemType
-> String
-> ProPredicate a b
-> Program pty IO a
-> Test
testDejafuWay :: forall b a pty.
Show b =>
Way
-> MemType
-> String
-> ProPredicate a b
-> Program pty IO a
-> Test
testDejafuWay Way
way = Settings IO a
-> String -> ProPredicate a b -> Program pty IO a -> Test
forall b a p.
Show b =>
Settings IO a
-> String -> ProPredicate a b -> Program p IO a -> Test
testDejafuWithSettings (Settings IO a
-> String -> ProPredicate a b -> Program pty IO a -> Test)
-> (MemType -> Settings IO a)
-> MemType
-> String
-> ProPredicate a b
-> Program pty IO a
-> Test
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Way -> MemType -> Settings IO a
forall (n :: * -> *) a.
Applicative n =>
Way -> MemType -> Settings n a
fromWayAndMemType Way
way
testDejafuWithSettings :: Show b
=> Settings IO a
-> String
-> ProPredicate a b
-> Program p IO a
-> Test
testDejafuWithSettings :: forall b a p.
Show b =>
Settings IO a
-> String -> ProPredicate a b -> Program p IO a -> Test
testDejafuWithSettings Settings IO a
settings String
name ProPredicate a b
p = Settings IO a
-> [(String, ProPredicate a b)] -> Program p IO a -> Test
forall b a pty.
Show b =>
Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
testDejafusWithSettings Settings IO a
settings [(String
name, ProPredicate a b
p)]
testDejafus :: Show b
=> [(String, ProPredicate a b)]
-> Program pty IO a
-> Test
testDejafus :: forall b a pty.
Show b =>
[(String, ProPredicate a b)] -> Program pty IO a -> Test
testDejafus = Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
forall b a pty.
Show b =>
Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
testDejafusWithSettings Settings IO a
forall (n :: * -> *) a. Applicative n => Settings n a
defaultSettings
testDejafusWay :: Show b
=> Way
-> MemType
-> [(String, ProPredicate a b)]
-> Program pty IO a
-> Test
testDejafusWay :: forall b a pty.
Show b =>
Way
-> MemType
-> [(String, ProPredicate a b)]
-> Program pty IO a
-> Test
testDejafusWay Way
way = Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
forall b a pty.
Show b =>
Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
testDejafusWithSettings (Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test)
-> (MemType -> Settings IO a)
-> MemType
-> [(String, ProPredicate a b)]
-> Program pty IO a
-> Test
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Way -> MemType -> Settings IO a
forall (n :: * -> *) a.
Applicative n =>
Way -> MemType -> Settings n a
fromWayAndMemType Way
way
testDejafusWithSettings :: Show b
=> Settings IO a
-> [(String, ProPredicate a b)]
-> Program pty IO a
-> Test
testDejafusWithSettings :: forall b a pty.
Show b =>
Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
testDejafusWithSettings = Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
forall b a pty.
Show b =>
Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
testconc
testProperty :: (R.Testable p, R.Listable (R.X p), Eq (R.X p), Show (R.X p), Show (R.O p))
=> String
-> p
-> Test
testProperty :: forall p.
(Testable p, Listable (X p), Eq (X p), Show (X p), Show (O p)) =>
String -> p -> Test
testProperty = Int -> Int -> String -> p -> Test
forall p.
(Testable p, Listable (X p), Eq (X p), Show (X p), Show (O p)) =>
Int -> Int -> String -> p -> Test
testPropertyFor Int
10 Int
100
testPropertyFor :: (R.Testable p, R.Listable (R.X p), Eq (R.X p), Show (R.X p), Show (R.O p))
=> Int
-> Int
-> String
-> p
-> Test
testPropertyFor :: forall p.
(Testable p, Listable (X p), Eq (X p), Show (X p), Show (O p)) =>
Int -> Int -> String -> p -> Test
testPropertyFor = Int -> Int -> String -> p -> Test
forall p.
(Testable p, Listable (X p), Eq (X p), Show (X p), Show (O p)) =>
Int -> Int -> String -> p -> Test
testprop
testconc :: Show b
=> Settings IO a
-> [(String, ProPredicate a b)]
-> Program pty IO a
-> Test
testconc :: forall b a pty.
Show b =>
Settings IO a
-> [(String, ProPredicate a b)] -> Program pty IO a -> Test
testconc Settings IO a
settings [(String, ProPredicate a b)]
tests Program pty IO a
concio = case ((String, ProPredicate a b) -> Test)
-> [(String, ProPredicate a b)] -> [Test]
forall a b. (a -> b) -> [a] -> [b]
map (String, ProPredicate a b) -> Test
forall {a}. Show a => (String, ProPredicate a a) -> Test
toTest [(String, ProPredicate a b)]
tests of
[Test
t] -> Test
t
[Test]
ts -> [Test] -> Test
TestList [Test]
ts
where
toTest :: (String, ProPredicate a a) -> Test
toTest (String
name, ProPredicate a a
p) = String -> Test -> Test
TestLabel String
name (Test -> Test) -> (Assertion -> Test) -> Assertion -> Test
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Assertion -> Test
TestCase (Assertion -> Test) -> Assertion -> Test
forall a b. (a -> b) -> a -> b
$ do
let discarder :: Either Condition a -> Maybe Discard
discarder = ((Either Condition a -> Maybe Discard)
-> Either Condition a -> Maybe Discard)
-> ((Either Condition a -> Maybe Discard)
-> (Either Condition a -> Maybe Discard)
-> Either Condition a
-> Maybe Discard)
-> Maybe (Either Condition a -> Maybe Discard)
-> (Either Condition a -> Maybe Discard)
-> Either Condition a
-> Maybe Discard
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Either Condition a -> Maybe Discard)
-> Either Condition a -> Maybe Discard
forall a. a -> a
id (Either Condition a -> Maybe Discard)
-> (Either Condition a -> Maybe Discard)
-> Either Condition a
-> Maybe Discard
forall a.
(Either Condition a -> Maybe Discard)
-> (Either Condition a -> Maybe Discard)
-> Either Condition a
-> Maybe Discard
D.strengthenDiscard (Lens' (Settings IO a) (Maybe (Either Condition a -> Maybe Discard))
-> Settings IO a -> Maybe (Either Condition a -> Maybe Discard)
forall s a. Lens' s a -> s -> a
get (Maybe (Either Condition a -> Maybe Discard)
-> f (Maybe (Either Condition a -> Maybe Discard)))
-> Settings IO a -> f (Settings IO a)
Lens' (Settings IO a) (Maybe (Either Condition a -> Maybe Discard))
forall (n :: * -> *) a (f :: * -> *).
Functor f =>
(Maybe (Either Condition a -> Maybe Discard)
-> f (Maybe (Either Condition a -> Maybe Discard)))
-> Settings n a -> f (Settings n a)
ldiscard Settings IO a
settings) (ProPredicate a a -> Either Condition a -> Maybe Discard
forall a b. ProPredicate a b -> Either Condition a -> Maybe Discard
pdiscard ProPredicate a a
p)
[(Either Condition a, Trace)]
traces <- Settings IO a
-> Program pty IO a -> IO [(Either Condition a, Trace)]
forall (n :: * -> *) a pty.
MonadDejaFu n =>
Settings n a -> Program pty n a -> n [(Either Condition a, Trace)]
SCT.runSCTWithSettings (Lens' (Settings IO a) (Maybe (Either Condition a -> Maybe Discard))
-> Maybe (Either Condition a -> Maybe Discard)
-> Settings IO a
-> Settings IO a
forall s a. Lens' s a -> a -> s -> s
set (Maybe (Either Condition a -> Maybe Discard)
-> f (Maybe (Either Condition a -> Maybe Discard)))
-> Settings IO a -> f (Settings IO a)
Lens' (Settings IO a) (Maybe (Either Condition a -> Maybe Discard))
forall (n :: * -> *) a (f :: * -> *).
Functor f =>
(Maybe (Either Condition a -> Maybe Discard)
-> f (Maybe (Either Condition a -> Maybe Discard)))
-> Settings n a -> f (Settings n a)
ldiscard ((Either Condition a -> Maybe Discard)
-> Maybe (Either Condition a -> Maybe Discard)
forall a. a -> Maybe a
Just Either Condition a -> Maybe Discard
discarder) Settings IO a
settings) Program pty IO a
concio
HasCallStack => String -> Assertion
String -> Assertion
assertString (String -> Assertion)
-> (Result a -> String) -> Result a -> Assertion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Result a -> String
forall a. Show a => Result a -> String
showErr (Result a -> Assertion) -> Result a -> Assertion
forall a b. (a -> b) -> a -> b
$ ProPredicate a a -> [(Either Condition a, Trace)] -> Result a
forall a b.
ProPredicate a b -> [(Either Condition a, Trace)] -> Result b
peval ProPredicate a a
p [(Either Condition a, Trace)]
traces
testprop :: (R.Testable p, R.Listable (R.X p), Eq (R.X p), Show (R.X p), Show (R.O p))
=> Int -> Int -> String -> p -> Test
testprop :: forall p.
(Testable p, Listable (X p), Eq (X p), Show (X p), Show (O p)) =>
Int -> Int -> String -> p -> Test
testprop Int
sn Int
vn String
name p
p = String -> Test -> Test
TestLabel String
name (Test -> Test) -> (Assertion -> Test) -> Assertion -> Test
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Assertion -> Test
TestCase (Assertion -> Test) -> Assertion -> Test
forall a b. (a -> b) -> a -> b
$ do
Maybe (FailedProperty (O p) (X p))
ce <- Int -> Int -> p -> IO (Maybe (FailedProperty (O p) (X p)))
forall p.
(Testable p, Listable (X p)) =>
Int -> Int -> p -> IO (Maybe (FailedProperty (O p) (X p)))
R.checkFor Int
sn Int
vn p
p
case Maybe (FailedProperty (O p) (X p))
ce of
Just FailedProperty (O p) (X p)
c -> String -> Assertion
forall a. HasCallStack => String -> IO a
assertFailure (String -> Assertion) -> (String -> String) -> String -> Assertion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. HasCallStack => [a] -> [a]
init (String -> Assertion) -> String -> Assertion
forall a b. (a -> b) -> a -> b
$ [String] -> String
unlines
[ String
"*** Failure: " String -> String -> String
forall a. [a] -> [a] -> [a]
++
(if [String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (FailedProperty (O p) (X p) -> [String]
forall o x. FailedProperty o x -> [String]
R.failingArgs FailedProperty (O p) (X p)
c) then String
"" else [String] -> String
unwords (FailedProperty (O p) (X p) -> [String]
forall o x. FailedProperty o x -> [String]
R.failingArgs FailedProperty (O p) (X p)
c) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" ") String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"(seed " String -> String -> String
forall a. [a] -> [a] -> [a]
++ X p -> String
forall a. Show a => a -> String
show (FailedProperty (O p) (X p) -> X p
forall o x. FailedProperty o x -> x
R.failingSeed FailedProperty (O p) (X p)
c) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")"
, String
" left: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [(Maybe Condition, O p)] -> String
forall a. Show a => a -> String
show (Set (Maybe Condition, O p) -> [(Maybe Condition, O p)]
forall a. Set a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList (Set (Maybe Condition, O p) -> [(Maybe Condition, O p)])
-> Set (Maybe Condition, O p) -> [(Maybe Condition, O p)]
forall a b. (a -> b) -> a -> b
$ FailedProperty (O p) (X p) -> Set (Maybe Condition, O p)
forall o x. FailedProperty o x -> Set (Maybe Condition, o)
R.leftResults FailedProperty (O p) (X p)
c)
, String
" right: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [(Maybe Condition, O p)] -> String
forall a. Show a => a -> String
show (Set (Maybe Condition, O p) -> [(Maybe Condition, O p)]
forall a. Set a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList (Set (Maybe Condition, O p) -> [(Maybe Condition, O p)])
-> Set (Maybe Condition, O p) -> [(Maybe Condition, O p)]
forall a b. (a -> b) -> a -> b
$ FailedProperty (O p) (X p) -> Set (Maybe Condition, O p)
forall o x. FailedProperty o x -> Set (Maybe Condition, o)
R.rightResults FailedProperty (O p) (X p)
c)
]
Maybe (FailedProperty (O p) (X p))
Nothing -> () -> Assertion
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
showErr :: Show a => Result a -> String
showErr :: forall a. Show a => Result a -> String
showErr Result a
res
| Result a -> Bool
forall a. Result a -> Bool
_pass Result a
res = String
""
| Bool
otherwise = String
"Failed:\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
msg String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
unlines [String]
failures String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
rest where
msg :: String
msg = if String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Result a -> String
forall a. Result a -> String
_failureMsg Result a
res) then String
"" else Result a -> String
forall a. Result a -> String
_failureMsg Result a
res String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"
failures :: [String]
failures = String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
"" ([String] -> [String])
-> ([(Either Condition a, Trace)] -> [String])
-> [(Either Condition a, Trace)]
-> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Either Condition a, Trace) -> String)
-> [(Either Condition a, Trace)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String -> String
indent (String -> String)
-> ((Either Condition a, Trace) -> String)
-> (Either Condition a, Trace)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either Condition a, Trace) -> String
forall {b}. Show b => (Either Condition b, Trace) -> String
showres) ([(Either Condition a, Trace)] -> [String])
-> ([(Either Condition a, Trace)] -> [(Either Condition a, Trace)])
-> [(Either Condition a, Trace)]
-> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> [(Either Condition a, Trace)] -> [(Either Condition a, Trace)]
forall a. Int -> [a] -> [a]
take Int
5 ([(Either Condition a, Trace)] -> [String])
-> [(Either Condition a, Trace)] -> [String]
forall a b. (a -> b) -> a -> b
$ Result a -> [(Either Condition a, Trace)]
forall a. Result a -> [(Either Condition a, Trace)]
_failures Result a
res
showres :: (Either Condition b, Trace) -> String
showres (Either Condition b
r, Trace
t) = (Condition -> String)
-> (b -> String) -> Either Condition b -> String
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Condition -> String
Conc.showCondition b -> String
forall a. Show a => a -> String
show Either Condition b
r String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Trace -> String
Conc.showTrace Trace
t
rest :: String
rest = if [(Either Condition a, Trace)] -> Int -> Bool
forall a. [a] -> Int -> Bool
moreThan (Result a -> [(Either Condition a, Trace)]
forall a. Result a -> [(Either Condition a, Trace)]
_failures Result a
res) Int
5 then String
"\n\t..." else String
""
moreThan :: [a] -> Int -> Bool
moreThan :: forall a. [a] -> Int -> Bool
moreThan [] Int
n = Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0
moreThan [a]
_ Int
0 = Bool
True
moreThan (a
_:[a]
xs) Int
n = [a] -> Int -> Bool
forall a. [a] -> Int -> Bool
moreThan [a]
xs (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
indent :: String -> String
indent :: String -> String
indent = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n" ([String] -> String) -> (String -> [String]) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Char
'\t'Char -> String -> String
forall a. a -> [a] -> [a]
:) ([String] -> [String])
-> (String -> [String]) -> String -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines