Skip to content

Commit

Permalink
Set stdout/err encoding to UTF-8 on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
moodmosaic committed Aug 20, 2018
1 parent 7516d04 commit 9dad81c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hedgehog/src/Hedgehog/Internal/Report.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS_HADDOCK not-home #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
Expand Down Expand Up @@ -63,6 +64,9 @@ import System.Console.ANSI (ColorIntensity(..), Color(..))
import System.Console.ANSI (ConsoleLayer(..), ConsoleIntensity(..))
import System.Console.ANSI (SGR(..), setSGRCode)
import System.Directory (makeRelativeToCurrentDirectory)
#if mingw32_HOST_OS
import System.IO (hSetEncoding, stdout, stderr, utf8)
#endif

import Text.PrettyPrint.Annotated.WL (Doc, (<+>))
import qualified Text.PrettyPrint.Annotated.WL as WL
Expand Down Expand Up @@ -781,7 +785,7 @@ ppSummary summary =
]

renderDoc :: MonadIO m => Maybe UseColor -> Doc Markup -> m String
renderDoc mcolor doc = do
renderDoc mcolor doc = liftIO $ do
let
dull =
SetColor Foreground Dull
Expand Down Expand Up @@ -885,6 +889,10 @@ renderDoc mcolor doc = do
DisableColor ->
WL.display

#if mingw32_HOST_OS
hSetEncoding stdout utf8
hSetEncoding stderr utf8
#endif
pure .
display .
WL.renderSmart 100 $
Expand Down
8 changes: 8 additions & 0 deletions hedgehog/src/Hedgehog/Internal/Runner.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# OPTIONS_HADDOCK not-home #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
Expand Down Expand Up @@ -45,6 +46,9 @@ import Hedgehog.Range (Size)

import Language.Haskell.TH.Lift (deriveLift)

#if mingw32_HOST_OS
import System.IO (hSetEncoding, stdout, stderr, utf8)
#endif

-- | Configuration for a property test run.
--
Expand Down Expand Up @@ -265,6 +269,10 @@ checkGroup config (Group group props) =
-- our tests will saturate all the capabilities they're given.
updateNumCapabilities (n + 2)

#if mingw32_HOST_OS
hSetEncoding stdout utf8
hSetEncoding stderr utf8
#endif
putStrLn $ "━━━ " ++ unGroupName group ++ " ━━━"

verbosity <- resolveVerbosity (runnerVerbosity config)
Expand Down

0 comments on commit 9dad81c

Please sign in to comment.