Skip to content

Commit

Permalink
Fix windows utf-8 issues (#256)
Browse files Browse the repository at this point in the history
* Fix windows utf-8 issues

This ensures we force the right codepages on windows to support utf8 characters in the Haskell source for the tests.
  • Loading branch information
angerman authored Jun 12, 2024
1 parent d17ff47 commit 80d696a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions command-line/cardano-addresses-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ test-suite unit
, temporary
, text
, with-utf8
if os(windows)
build-depends:
Win32
if flag(release)
ghc-options: -Werror
if !(impl(ghcjs) || os(ghcjs))
Expand Down
25 changes: 25 additions & 0 deletions command-line/test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
module Main where

import Prelude
Expand All @@ -11,7 +12,31 @@ import Test.Hspec.Runner

import qualified AutoDiscover

-- This is effectively from the now defunct foundation/basement from
-- https://github.com/haskell-foundation/foundation/blob/5e28e3ea1e2fe9a98c157df463bd32d3f92e7f80/basement/Basement/Terminal.hs#L14-L26
#ifdef mingw32_HOST_OS
import System.IO
( hPutStrLn, hSetEncoding, stderr, stdin, stdout, utf8 )
import System.Win32.Console
( getConsoleCP, getConsoleOutputCP, setConsoleCP, setConsoleOutputCP )
#endif

#ifdef mingw32_HOST_OS
initialize :: IO ()
initialize = do
query getConsoleOutputCP (\e -> setConsoleOutputCP e >> hSetEncoding stdout utf8 >> hSetEncoding stderr utf8) utf8Code
query getConsoleCP (\e -> setConsoleCP e >> hSetEncoding stdin utf8) utf8Code
where
utf8Code = 65001
query get set expected = do
v <- get
if v == expected then pure () else set expected
#endif

main :: IO ()
main = do
ghcjsBuildSupport
#ifdef mingw32_HOST_OS
initialize
#endif
withUtf8 $ hspecWith defaultConfig AutoDiscover.spec
1 change: 1 addition & 0 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ haskell-nix.cabalProject' (
};
crossPlatforms = p: with p;
lib.optional (system == "x86_64-linux" && builtins.elem config.compiler-nix-name ["ghc8107"]) ghcjs ++
lib.optional (system == "x86_64-linux") mingwW64 ++
lib.optional (system == "x86_64-linux") musl64;
};
shell = {
Expand Down

0 comments on commit 80d696a

Please sign in to comment.