Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit aefe106

Browse files
author
Abigail Magalhães
committed
Set encoding for handles at compile time
1 parent 2658df8 commit aefe106

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

bin/Amc/Explain/TH.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
{-# LANGUAGE TemplateHaskell #-}
22
module Amc.Explain.TH where
33

4+
import Control.Exception
5+
46
import Language.Haskell.TH.Syntax
57
import Language.Haskell.TH
68

79
import System.FilePath
10+
import System.IO
811

912
qReadFile :: FilePath -> Q String
1013
qReadFile path = do
1114
qAddDependentFile path
12-
str <- qRunIO (readFile path)
13-
length str `seq` pure str
15+
qRunIO $
16+
withFile path ReadMode $ \handle -> do
17+
hSetEncoding handle utf8
18+
s <- hGetContents handle
19+
_ <- evaluate (length s)
20+
pure s
1421

1522
qReadFilesList :: FilePath -> Q [FilePath]
1623
qReadFilesList path = do
1724
qAddDependentFile path
18-
contents <- qRunIO (readFile path)
25+
contents <- qRunIO $
26+
withFile path ReadMode $ \handle -> do
27+
hSetEncoding handle utf8
28+
s <- hGetContents handle
29+
_ <- evaluate (length s)
30+
pure s
1931
let files = lines contents
2032
fileP = map (head . words) files
2133
pure fileP

tests/driver/Main.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import qualified Test.Types.Check as TypesC
1818
import qualified Test.Core.Backend as Backend
1919
import qualified Test.Lua.Parser as LParser
2020
import qualified Test.Frontend.Amc as Amc
21-
import qualified Test.Lsp as Lsp
21+
mport qualified Test.Lsp as Lsp
22+
23+
import GHC.IO.Encoding
2224

2325
tests :: IO TestTree
2426
tests = testGroup "Tests" <$> sequence
@@ -40,7 +42,9 @@ tests = testGroup "Tests" <$> sequence
4042
]
4143

4244
main :: IO ()
43-
main = tests >>= defaultMainWithIngredients ingredients where
45+
main = locale *> test where
46+
locale = setLocaleEncoding utf8
47+
test = tests >>= defaultMainWithIngredients ingredients
4448
ingredients =
4549
[ rerunning
4650
[ listingTests

0 commit comments

Comments
 (0)