Skip to content

Commit

Permalink
Fix windows utf-8 issues
Browse files Browse the repository at this point in the history
This ensure we force the rigth codepages on windows to support utf8 caracters in the haskell source for the tests.
  • Loading branch information
angerman committed Jun 12, 2024
1 parent ea4fb83 commit 4d7b8bd
Show file tree
Hide file tree
Showing 3 changed files with 27 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
23 changes: 23 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,29 @@ 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 (hSetEncoding, utf8, hPutStrLn, stderr, stdin, stdout)
import System.Win32.Console (setConsoleCP, setConsoleOutputCP, getConsoleCP, getConsoleOutputCP)
#endif

initialize :: IO ()
initialize = do
#ifdef mingw32_HOST_OS
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
#else
pure ()
#endif

main :: IO ()
main = do
ghcjsBuildSupport
initialize
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 4d7b8bd

Please sign in to comment.