[commit: ghc] ghc-7.10: Make enum01/enum02/enum03 tests clang-compatible (c6f8d11)

git at git.haskell.org git at git.haskell.org
Fri Jun 26 19:25:45 UTC 2015


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

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/c6f8d11bc12e69ff71e0a33ac72a6578085c0faa/ghc

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

commit c6f8d11bc12e69ff71e0a33ac72a6578085c0faa
Author: Reid Barton <rwbarton at gmail.com>
Date:   Tue Jun 16 16:39:15 2015 -0500

    Make enum01/enum02/enum03 tests clang-compatible
    
    ... by entirely replacing the use of CPP by a custom preprocessor;
    clang -E -traditional has no stringification mechanism at all.
    
    Reviewed By: thomie, austin
    
    Differential Revision: https://phabricator.haskell.org/D957
    
    GHC Trac Issues: #9399
    
    (cherry picked from commit b98ca17e12c7efdc906f4901f25e6263a5399be1)


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

c6f8d11bc12e69ff71e0a33ac72a6578085c0faa
 libraries/base/tests/all.T             |  6 +++---
 libraries/base/tests/enum01.hs         |  7 +++++--
 libraries/base/tests/enum02.hs         |  7 +++++--
 libraries/base/tests/enum03.hs         |  7 +++++--
 libraries/base/tests/enum_processor.py | 24 ++++++++++++++++++++++++
 5 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T
index 1154a53..1c90d14 100644
--- a/libraries/base/tests/all.T
+++ b/libraries/base/tests/all.T
@@ -77,9 +77,9 @@ test('dynamic002',      normal, compile_and_run, [''])
 test('dynamic003',      extra_run_opts('+RTS -K32m -RTS'), compile_and_run, [''])
 test('dynamic004',      omit_ways(['normal', 'threaded1', 'ghci']), compile_and_run, [''])
 test('dynamic005',      normal, compile_and_run, [''])
-test('enum01',          when(fast(), skip), compile_and_run, ['-cpp'])
-test('enum02', 		when(fast(), skip), compile_and_run, ['-cpp'])
-test('enum03', 		when(fast(), skip), compile_and_run, ['-cpp'])
+test('enum01',          when(fast(), skip), compile_and_run, [''])
+test('enum02',          when(fast(), skip), compile_and_run, [''])
+test('enum03',          when(fast(), skip), compile_and_run, [''])
 test('enum04', 		normal, compile_and_run, [''])
 test('exceptionsrun001', 	normal, compile_and_run, [''])
 test('exceptionsrun002', 	normal, compile_and_run, [''])
diff --git a/libraries/base/tests/enum01.hs b/libraries/base/tests/enum01.hs
index 0f26173..0ae39b1 100644
--- a/libraries/base/tests/enum01.hs
+++ b/libraries/base/tests/enum01.hs
@@ -1,5 +1,9 @@
 -- !!! Testing the Prelude's Enum instances.
-{-# LANGUAGE CPP #-}
+{-# OPTIONS_GHC -F -pgmF ./enum_processor.py #-}
+-- The processor is a non-CPP-based equivalent of
+-- #define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
+-- which is not portable to clang
+
 module Main(main) where
 
 import Control.Exception
@@ -82,7 +86,6 @@ main = do
   OK - on with the regression testing.
 -}
 
-#define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
 
 
 testEnumInt :: IO ()
diff --git a/libraries/base/tests/enum02.hs b/libraries/base/tests/enum02.hs
index 23de6eb..f7e843c 100644
--- a/libraries/base/tests/enum02.hs
+++ b/libraries/base/tests/enum02.hs
@@ -1,5 +1,9 @@
 -- !!! Testing the Int Enum instances.
-{-# LANGUAGE CPP #-}
+{-# OPTIONS_GHC -F -pgmF ./enum_processor.py #-}
+-- The processor is a non-CPP-based equivalent of
+-- #define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
+-- which is not portable to clang
+
 module Main(main) where
 
 import Control.Exception
@@ -15,7 +19,6 @@ main = do
   putStrLn "Testing Enum Int64:"
   testEnumInt64
 
-#define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
 
 testEnumInt8 :: IO ()
 testEnumInt8 = do
diff --git a/libraries/base/tests/enum03.hs b/libraries/base/tests/enum03.hs
index 1cbe309..181354a 100644
--- a/libraries/base/tests/enum03.hs
+++ b/libraries/base/tests/enum03.hs
@@ -1,5 +1,9 @@
 -- !!! Testing the Word Enum instances.
-{-# LANGUAGE CPP #-}
+{-# OPTIONS_GHC -F -pgmF ./enum_processor.py #-}
+-- The processor is a non-CPP-based equivalent of
+-- #define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
+-- which is not portable to clang
+
 module Main(main) where
 
 import Control.Exception
@@ -17,7 +21,6 @@ main = do
   testEnumWord64
 
 
-#define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
 
 testEnumWord8 :: IO ()
 testEnumWord8 = do
diff --git a/libraries/base/tests/enum_processor.py b/libraries/base/tests/enum_processor.py
new file mode 100755
index 0000000..86c3d6c
--- /dev/null
+++ b/libraries/base/tests/enum_processor.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import sys
+
+def process(s):
+    while True:
+        start = s.find('printTest')
+        if start == -1:
+            return s
+        j0 = j = s.index('(', start) + 1
+        depth = 1
+        while depth > 0:
+            if s[j] == '(':
+                depth += 1
+            if s[j] == ')':
+                depth -= 1
+            j += 1
+        argument = s[j0:j-1]
+        expansion = '(do{ putStr ( "    " ++ "%s" ++ " = " ) ; print (%s) })' \
+                    % (argument, argument)
+        s = s[:start] + expansion + s[j:]
+
+_, _, inputFile, outputFile = sys.argv
+open(outputFile, 'w').write(process(open(inputFile, 'r').read()))



More information about the ghc-commits mailing list