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 authored and erikd committed Feb 29, 2020
1 parent a8c14e4 commit f1ba3b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 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 @@ -885,6 +889,11 @@ renderDoc mcolor doc = do
DisableColor ->
WL.display

#if mingw32_HOST_OS
liftIO $ do
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 f1ba3b8

Please sign in to comment.