-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,45 @@ | ||
{-# LANGUAGE CPP, OverloadedStrings #-} | ||
module RunnerSpec (main, spec) where | ||
module RunnerSpec (spec) where | ||
|
||
import Imports | ||
|
||
import Test.Hspec | ||
|
||
import Data.IORef | ||
import System.IO | ||
import System.IO.Silently (hCapture) | ||
import System.IO.Silently (hCapture_) | ||
import Control.Monad.Trans.State | ||
import Runner | ||
|
||
main :: IO () | ||
main = hspec spec | ||
|
||
capture :: Report a -> IO String | ||
capture = fmap fst . hCapture [stderr] . (`execStateT` ReportState True False mempty) | ||
|
||
-- like capture, but with interactivity set to False | ||
capture_ :: Report a -> IO String | ||
capture_ = fmap fst . hCapture [stderr] . (`execStateT` ReportState False False mempty) | ||
capture :: Interactive -> Report a -> IO String | ||
capture interactive action = do | ||
ref <- newIORef mempty | ||
hCapture_ [stderr] (evalStateT action (ReportState interactive NonVerbose ref)) | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "report" $ do | ||
context "when mode is interactive" $ do | ||
it "writes to stderr" $ do | ||
capture $ do | ||
capture Interactive $ do | ||
report "foobar" | ||
`shouldReturn` "foobar\n" | ||
|
||
context "when mode is non-interactive" $ do | ||
it "writes to stderr" $ do | ||
capture_ $ 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 $ do | ||
capture Interactive $ do | ||
reportTransient "foobar" | ||
`shouldReturn` "foobar\r \r" | ||
|
||
context "when mode is non-interactive" $ do | ||
it "is ignored" $ do | ||
capture_ $ do | ||
capture NonInteractive $ do | ||
reportTransient "foobar" | ||
`shouldReturn` "" |