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

Commit ff37191

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

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import qualified Test.Lua.Parser as LParser
2020
import qualified Test.Frontend.Amc as Amc
2121
import qualified Test.Lsp as Lsp
2222

23+
import GHC.IO.Encoding
24+
2325
tests :: IO TestTree
2426
tests = testGroup "Tests" <$> sequence
2527
-- These two will timeout if you run 10000 of them.
@@ -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)