module Test.Hspec.FailureReport (
FailureReport (..)
, writeFailureReport
, readFailureReport
) where
#ifndef __GHCJS__
import System.SetEnv
import Test.Hspec.Core.Util (safeTry)
#endif
import System.IO
import Test.Hspec.Compat
import Test.Hspec.Core.Util (Path)
data FailureReport = FailureReport {
failureReportSeed :: Integer
, failureReportMaxSuccess :: Int
, failureReportMaxSize :: Int
, failureReportMaxDiscardRatio :: Int
, failureReportPaths :: [Path]
} deriving (Eq, Show, Read)
writeFailureReport :: FailureReport -> IO ()
#ifdef __GHCJS__
writeFailureReport _ = return ()
#else
writeFailureReport x = do
safeTry (setEnv "HSPEC_FAILURES" $ show x) >>= either onError return
where
onError err = do
hPutStrLn stderr ("WARNING: Could not write environment variable HSPEC_FAILURES (" ++ show err ++ ")")
#endif
readFailureReport :: IO (Maybe FailureReport)
readFailureReport = do
mx <- lookupEnv "HSPEC_FAILURES"
case mx >>= readMaybe of
Nothing -> do
hPutStrLn stderr "WARNING: Could not read environment variable HSPEC_FAILURES; `--rerun' is ignored!"
return Nothing
x -> return x