1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
{-# LANGUAGE CPP, OverloadedStrings #-}
module RunnerSpec (spec) where
import Imports
import Test.Hspec
import Data.IORef
import System.IO
import System.IO.Silently (hCapture_)
import Runner
capture :: Interactive -> Report () -> IO String
capture interactive action = do
ref <- newIORef mempty
hCapture_ [stderr] (runReport (ReportState interactive NoFailFast NonVerbose ref) action)
spec :: Spec
spec = do
describe "report" $ do
context "when mode is interactive" $ do
it "writes to stderr" $ do
capture Interactive $ do
report "foobar"
`shouldReturn` "foobar\n"
context "when mode is non-interactive" $ do
it "writes to stderr" $ do
capture NonInteractive $ do
report "foobar"
`shouldReturn` "foobar\n"
describe "report_" $ do
context "when mode is interactive" $ do
it "writes transient output to stderr" $ do
capture Interactive $ do
reportTransient "foobar"
`shouldReturn` "foobar\r \r"
context "when mode is non-interactive" $ do
it "is ignored" $ do
capture NonInteractive $ do
reportTransient "foobar"
`shouldReturn` ""
|