summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/check-exact/Main.hs14
-rw-r--r--utils/check-ppr/Main.hs13
2 files changed, 19 insertions, 8 deletions
diff --git a/utils/check-exact/Main.hs b/utils/check-exact/Main.hs
index 80c1908ce0..d5583c6f23 100644
--- a/utils/check-exact/Main.hs
+++ b/utils/check-exact/Main.hs
@@ -13,6 +13,7 @@ import GHC.Hs.Dump
import System.Environment( getArgs )
import System.Exit
import System.FilePath
+import System.IO
import ExactPrint
-- exactPrint = undefined
-- showPprUnsafe = undefined
@@ -61,7 +62,7 @@ _tt = testOneFile "/home/alanz/mysrc/git.haskell.org/worktree/exactprint/_build/
-- "../../testsuite/tests/printer/Ppr033.hs"
-- "../../testsuite/tests/printer/Ppr034.hs"
-- "../../testsuite/tests/printer/Ppr035.hs"
- -- "../../testsuite/tests/printer/Ppr036.hs"
+ "../../testsuite/tests/printer/Ppr036.hs"
-- "../../testsuite/tests/printer/Ppr037.hs"
-- "../../testsuite/tests/printer/Ppr038.hs"
-- "../../testsuite/tests/printer/Ppr039.hs"
@@ -126,7 +127,7 @@ _tt = testOneFile "/home/alanz/mysrc/git.haskell.org/worktree/exactprint/_build/
-- "../../testsuite/tests/printer/PprRecordDotSyntax2.hs"
-- "../../testsuite/tests/printer/PprRecordDotSyntax3.hs"
-- "../../testsuite/tests/printer/PprRecordDotSyntax4.hs"
- "../../testsuite/tests/printer/PprRecordDotSyntaxA.hs"
+ -- "../../testsuite/tests/printer/PprRecordDotSyntaxA.hs"
-- "./cases/Windows.hs"
-- exact = ppr
@@ -148,6 +149,9 @@ main = do
[libdir,fileName] -> testOneFile libdir fileName
_ -> putStrLn usage
+writeBinFile :: FilePath -> String -> IO()
+writeBinFile fpath x = withBinaryFile fpath WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h x)
+
testOneFile :: FilePath -> String -> IO ()
testOneFile libdir fileName = do
p <- parseOneFile libdir fileName
@@ -166,9 +170,9 @@ testOneFile libdir fileName = do
newAstFile = fileName <.> "ast.new"
-- putStrLn $ "\n\nabout to writeFile"
- writeFile astFile origAst
+ writeBinFile astFile origAst
-- putStrLn $ "\n\nabout to pp"
- writeFile newFile pped
+ writeBinFile newFile pped
-- putStrLn $ "anns':" ++ showPprUnsafe (apiAnnRogueComments anns')
@@ -178,7 +182,7 @@ testOneFile libdir fileName = do
newAstStr = showSDocUnsafe
$ showAstData BlankSrcSpanFile NoBlankApiAnnotations
(pm_parsed_source p')
- writeFile newAstFile newAstStr
+ writeBinFile newAstFile newAstStr
-- putStrLn $ "\n\nanns':" ++ showPprUnsafe (apiAnnRogueComments anns')
diff --git a/utils/check-ppr/Main.hs b/utils/check-ppr/Main.hs
index 0559e20f10..f537a0085c 100644
--- a/utils/check-ppr/Main.hs
+++ b/utils/check-ppr/Main.hs
@@ -14,6 +14,7 @@ import GHC.Utils.Outputable hiding (space)
import System.Environment( getArgs )
import System.Exit
import System.FilePath
+import System.IO
usage :: String
usage = unlines
@@ -30,6 +31,12 @@ main = do
[libdir,fileName] -> testOneFile libdir fileName
_ -> putStrLn usage
+-- | N.B. It's important that we write our output as binary lest Windows will
+-- change our LF line endings to CRLF, which will show up in the AST when we
+-- re-parse.
+writeBinFile :: FilePath -> String -> IO()
+writeBinFile fpath x = withBinaryFile fpath WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h x)
+
testOneFile :: FilePath -> String -> IO ()
testOneFile libdir fileName = do
p <- parseOneFile libdir fileName
@@ -45,8 +52,8 @@ testOneFile libdir fileName = do
astFile = fileName <.> "ast"
newAstFile = fileName <.> "ast.new"
- writeFile astFile origAst
- writeFile newFile pped
+ writeBinFile astFile origAst
+ writeBinFile newFile pped
p' <- parseOneFile libdir newFile
@@ -54,7 +61,7 @@ testOneFile libdir fileName = do
newAstStr = showPprUnsafe
$ showAstData BlankSrcSpan BlankApiAnnotations
$ eraseLayoutInfo (pm_parsed_source p')
- writeFile newAstFile newAstStr
+ writeBinFile newAstFile newAstStr
if origAst == newAstStr
then do