Commits

Jasper Van der Jeugt committed 5dbba39

GHC 7 compatibility for tests

Comments (0)

Files changed (2)

 version := $(shell awk '/^version:/{print $$2}' ../text.cabal)
+ghc-major-version := $(shell ghc --numeric-version | sed 's/\..*//')
 ghc := ghc
 ghc-opt-flags = -O0
 ghc-base-flags := -funbox-strict-fields -hide-all-packages \
 	-package criterion -package deepseq -DASSERTS -DHAVE_DEEPSEQ \
 	-package bytestring -ignore-package text \
 	-fno-ignore-asserts
+ifeq ($(ghc-major-version),7)
+    ghc-base-flags += -rtsopts
+endif
 ghc-test-flags := -package QuickCheck -package test-framework -package deepseq \
 	-package test-framework-quickcheck2 -package test-framework-hunit \
-	-package HUnit
+	-package HUnit -package directory
 ghc-base-flags += -Wall -fno-warn-orphans -fno-warn-missing-signatures
 ghc-flags := $(ghc-base-flags) -i../dist/build -package-name text-$(version)
 ghc-hpc-flags := $(ghc-base-flags) -fhpc -fno-ignore-asserts -odir hpcdir \

tests/Properties.hs

 {-# LANGUAGE BangPatterns, FlexibleInstances, OverloadedStrings,
-             ScopedTypeVariables, TypeSynonymInstances #-}
+             ScopedTypeVariables, TypeSynonymInstances, CPP #-}
 {-# OPTIONS_GHC -fno-enable-rewrite-rules #-}
 
 import Test.QuickCheck
 
 windowsNewlineMode  = NewlineMode { inputNL = CRLF, outputNL = CRLF }
 
+-- Newline and NewlineMode have standard Show instance from GHC 7 onwards
+#if __GLASGOW_HASKELL__ < 700
 instance Show Newline where
     show CRLF = "CRLF"
     show LF   = "LF"
 instance Show NewlineMode where
     show (NewlineMode i o) = "NewlineMode { inputNL = " ++ show i ++
                              ", outputNL = " ++ show o ++ " }"
+# endif
 
 instance Arbitrary NewlineMode where
     arbitrary = oneof . map return $
     monadicIO $ assert . (==t) =<< run act
   where t = unline . map (filt (not . (`elem` "\r\n"))) $ ts
         act = withTempFile $ \path h -> do
-                hSetEncoding h enc
+                -- hSetEncoding h enc
                 hSetNewlineMode h nl
                 hSetBuffering h buf
                 () <- writer h t
                 hClose h
                 bracket (openFile path ReadMode) hClose $ \h' -> do
-                  hSetEncoding h' enc
+                  -- hSetEncoding h' enc
                   hSetNewlineMode h' nl
                   hSetBuffering h' buf
                   r <- reader h'