@@ -27,7 +27,7 @@ import Control.Applicative (Alternative ((<|>)))
27
27
import Control.Arrow (second , (>>>) )
28
28
import Control.Exception (try )
29
29
import qualified Control.Exception as E
30
- import Control.Lens (_1 , _3 , (%~) , (<&>) , (^.) )
30
+ import Control.Lens (_1 , _3 , ix , (%~) , (<&>) , (^.) )
31
31
import Control.Monad (guard , join , void , when )
32
32
import Control.Monad.IO.Class (MonadIO (liftIO ))
33
33
import Control.Monad.Trans (lift )
@@ -344,7 +344,7 @@ runTests :: Bool -> TEnv -> [(Section, Test)] -> Ghc [TextEdit]
344
344
runTests diff e@ (_st, _) tests = do
345
345
df <- getInteractiveDynFlags
346
346
evalSetup
347
- when (hasQuickCheck df && needsQuickCheck tests) $ void $ evals e df propSetup
347
+ when (hasQuickCheck df && needsQuickCheck tests) $ void $ evals True e df propSetup
348
348
349
349
mapM (processTest e df) tests
350
350
where
@@ -368,7 +368,7 @@ runTests diff e@(_st, _) tests = do
368
368
return $
369
369
singleLine
370
370
" Add QuickCheck to your cabal dependencies to run this test."
371
- runTest e df test = evals e df (asStatements test)
371
+ runTest e df test = evals (isProperty test) e df (asStatements test)
372
372
373
373
asEdit :: Format -> Test -> [Text ] -> TextEdit
374
374
asEdit (MultiLine commRange) test resultLines
@@ -440,8 +440,8 @@ Or for a value that does not have a Show instance and can therefore not be displ
440
440
>>> V
441
441
No instance for (Show V)
442
442
-}
443
- evals :: TEnv -> DynFlags -> [Statement ] -> Ghc [Text ]
444
- evals (st, fp) df stmts = do
443
+ evals :: Bool -> TEnv -> DynFlags -> [Statement ] -> Ghc [Text ]
444
+ evals property (st, fp) df stmts = do
445
445
er <- gStrictTry $ mapM eval stmts
446
446
return $ case er of
447
447
Left err -> errorLines err
@@ -488,9 +488,9 @@ evals (st, fp) df stmts = do
488
488
do
489
489
dbg " {STMT " stmt
490
490
res <- exec stmt l
491
- r <- case res of
492
- Left err -> return . Just . errorLines $ err
493
- Right x -> return $ singleLine <$> x
491
+ let r = case res of
492
+ Left err -> Just . ( if property then errorLines else exceptionLines) $ err
493
+ Right x -> singleLine <$> x
494
494
dbg " STMT} -> " r
495
495
return r
496
496
| -- An import
@@ -556,6 +556,15 @@ errorLines =
556
556
. T. lines
557
557
. T. pack
558
558
559
+ {- |
560
+ Convert exception messages to a list of text lines
561
+ Remove unnecessary information and mark it as exception.
562
+ We use '*** Exception:' to make it identical to doctest
563
+ output, see #2353.
564
+ -}
565
+ exceptionLines :: String -> [Text ]
566
+ exceptionLines = (ix 0 %~ (" *** Exception: " <> )) . errorLines
567
+
559
568
{- |
560
569
>>> map (pad_ (T.pack "--")) (map T.pack ["2+2",""])
561
570
["--2+2","--<BLANKLINE>"]
0 commit comments