From b98ca17e12c7efdc906f4901f25e6263a5399be1 Mon Sep 17 00:00:00 2001 From: Reid Barton Date: Tue, 16 Jun 2015 16:39:15 -0500 Subject: 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 --- 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(-) create mode 100755 libraries/base/tests/enum_processor.py (limited to 'libraries') diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T index 1154a5335d..1c90d14e99 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 0f261732b6..0ae39b14d1 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 23de6ebdf9..f7e843c537 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 1cbe3091ea..181354a5e5 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 0000000000..86c3d6c94a --- /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())) -- cgit v1.2.1