File: RunnerSpec.hs

package info (click to toggle)
haskell-doctest 0.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 708 kB
  • sloc: haskell: 3,428; ansic: 3; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download
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` ""