Commits

Jasper Van der Jeugt  committed 74228a6

Move =^= to TestUtils

  • Participants
  • Parent commits bd4185d

Comments (0)

Files changed (2)

File tests/tests/src/Data/Text/Tests/Properties.hs

 import Data.Text.Tests.TestUtils
 import qualified Data.Text.Tests.SlowFunctions as Slow
 
--- Ensure that two potentially bottom values (in the sense of crashing
--- for some inputs, not looping infinitely) either both crash, or both
--- give comparable results for some input.
-(=^=) :: (Eq a, Show a) => a -> a -> Bool
-{-# NOINLINE (=^=) #-}
-i =^= j = unsafePerformIO $ do
-  x <- try (evaluate i)
-  y <- try (evaluate j)
-  case (x,y) of
-    (Left (_ :: SomeException), Left (_ :: SomeException))
-                       -> return True
-    (Right a, Right b) -> return (a == b)
-    e                  -> trace ("*** Divergence: " ++ show e) return False
-infix 4 =^=
-
 t_pack_unpack       = (T.unpack . T.pack) `eq` id
 tl_pack_unpack      = (TL.unpack . TL.pack) `eq` id
 t_stream_unstream   = (S.unstream . S.stream) `eq` id

File tests/tests/src/Data/Text/Tests/TestUtils.hs

+-- | Miscellaneous testing utilities
+--
+{-# LANGUAGE ScopedTypeVariables #-}
 module Data.Text.Tests.TestUtils
     (
-      withRedirect
+      (=^=)
+    , withRedirect
     , withTempFile
     ) where
 
-import Control.Exception (bracket, bracket_)
+import Control.Exception (SomeException, bracket, bracket_, evaluate, try)
 import Control.Monad (when)
+import Debug.Trace (trace)
 import GHC.IO.Handle.Internals (withHandle)
 import System.Directory (removeFile)
-import System.IO
+import System.IO (Handle, hClose, hFlush, hIsOpen, hIsWritable, openTempFile)
+import System.IO.Unsafe (unsafePerformIO)
+
+-- Ensure that two potentially bottom values (in the sense of crashing
+-- for some inputs, not looping infinitely) either both crash, or both
+-- give comparable results for some input.
+(=^=) :: (Eq a, Show a) => a -> a -> Bool
+i =^= j = unsafePerformIO $ do
+  x <- try (evaluate i)
+  y <- try (evaluate j)
+  case (x,y) of
+    (Left (_ :: SomeException), Left (_ :: SomeException))
+                       -> return True
+    (Right a, Right b) -> return (a == b)
+    e                  -> trace ("*** Divergence: " ++ show e) return False
+infix 4 =^=
+{-# NOINLINE (=^=) #-}
 
 withTempFile :: (FilePath -> Handle -> IO a) -> IO a
 withTempFile = bracket (openTempFile "." "crashy.txt") cleanupTemp . uncurry