[commit: ghc] master: Fix Pretty printer tests on Windows (d88efb7)

git at git.haskell.org git at git.haskell.org
Sat Dec 17 19:21:56 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d88efb7048160c3031eadb4f3b729e9fe406414d/ghc

>---------------------------------------------------------------

commit d88efb7048160c3031eadb4f3b729e9fe406414d
Author: Tamar Christina <tamar at zhox.com>
Date:   Sat Dec 17 16:40:11 2016 +0000

    Fix Pretty printer tests on Windows
    
    Summary:
    D2752 added some tests which escapes string literals. This means newlines are converted
    before they get normalized by the IO functions. So on Windows \r\n would be in the output
    while \n was expected.
    
    Test Plan: make test -C testsuite/tests/printer
    
    Reviewers: austin, bgamari, alanz
    
    Reviewed By: alanz
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2873
    
    GHC Trac Issues: #3384


>---------------------------------------------------------------

d88efb7048160c3031eadb4f3b729e9fe406414d
 utils/check-ppr/Main.hs | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/utils/check-ppr/Main.hs b/utils/check-ppr/Main.hs
index 8c93769..c9fac7d 100644
--- a/utils/check-ppr/Main.hs
+++ b/utils/check-ppr/Main.hs
@@ -132,10 +132,10 @@ showAstData n =
         space "" = ""
         space s  = ' ':s
         indent i = "\n" ++ replicate i ' '
-        string     = show :: String -> String
-        fastString = ("{FastString: "++) . (++"}") . show
+        string     = normalize_newlines . show :: String -> String
+        fastString = ("{FastString: "++) . (++"}") . normalize_newlines . show
                    :: FastString -> String
-        bytestring = show :: B.ByteString -> String
+        bytestring = normalize_newlines . show :: B.ByteString -> String
         list l     = indent n ++ "["
                               ++ intercalate "," (map (showAstData (n+1)) l)
                               ++ "]"
@@ -179,11 +179,16 @@ showAstData n =
                   ++ showAstData (n+1) a
                   ++ ")"
 
+normalize_newlines :: String -> String
+normalize_newlines ('\\':'r':'\\':'n':xs) = '\\':'n':normalize_newlines xs
+normalize_newlines (x:xs)                 = x:normalize_newlines xs
+normalize_newlines []                     = []
+
 showSDoc_ :: SDoc -> String
-showSDoc_ = showSDoc unsafeGlobalDynFlags
+showSDoc_ = normalize_newlines . showSDoc unsafeGlobalDynFlags
 
 showSDocDebug_ :: SDoc -> String
-showSDocDebug_ = showSDocDebug unsafeGlobalDynFlags
+showSDocDebug_ = normalize_newlines . showSDocDebug unsafeGlobalDynFlags
 
 -- ---------------------------------------------------------------------
 



More information about the ghc-commits mailing list