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

Commit

Permalink
Set encoding for handles at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
Abigail Magalhães committed May 1, 2020
1 parent 2658df8 commit aefe106
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 15 additions & 3 deletions bin/Amc/Explain/TH.hs
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
{-# LANGUAGE TemplateHaskell #-}
module Amc.Explain.TH where

import Control.Exception

import Language.Haskell.TH.Syntax
import Language.Haskell.TH

import System.FilePath
import System.IO

qReadFile :: FilePath -> Q String
qReadFile path = do
qAddDependentFile path
str <- qRunIO (readFile path)
length str `seq` pure str
qRunIO $
withFile path ReadMode $ \handle -> do
hSetEncoding handle utf8
s <- hGetContents handle
_ <- evaluate (length s)
pure s

qReadFilesList :: FilePath -> Q [FilePath]
qReadFilesList path = do
qAddDependentFile path
contents <- qRunIO (readFile path)
contents <- qRunIO $
withFile path ReadMode $ \handle -> do
hSetEncoding handle utf8
s <- hGetContents handle
_ <- evaluate (length s)
pure s
let files = lines contents
fileP = map (head . words) files
pure fileP
Expand Down
8 changes: 6 additions & 2 deletions tests/driver/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import qualified Test.Types.Check as TypesC
import qualified Test.Core.Backend as Backend
import qualified Test.Lua.Parser as LParser
import qualified Test.Frontend.Amc as Amc
import qualified Test.Lsp as Lsp
mport qualified Test.Lsp as Lsp

import GHC.IO.Encoding

tests :: IO TestTree
tests = testGroup "Tests" <$> sequence
Expand All @@ -40,7 +42,9 @@ tests = testGroup "Tests" <$> sequence
]

main :: IO ()
main = tests >>= defaultMainWithIngredients ingredients where
main = locale *> test where
locale = setLocaleEncoding utf8
test = tests >>= defaultMainWithIngredients ingredients
ingredients =
[ rerunning
[ listingTests
Expand Down

0 comments on commit aefe106

Please sign in to comment.