Commits

Bryan O'Sullivan  committed ea425bf

Factor out the useful withTempFile function

  • Participants
  • Parent commits 45d0d12

Comments (0)

Files changed (3)

File tests/Makefile

 	$(ghc) $(ghc-hpc-flags) $(ghc-test-flags) $(ghc-opt-flags) -ihpcdir \
 	  --make -threaded -o $@ $<
 
-regressions: Regressions.o
+Regressions.o: TestUtils.o
+
+regressions: Regressions.o TestUtils.o
 	$(ghc) $(ghc-test-flags) -o $@ $^ $(lib)
 
 coverage: qc-hpc-html/hpc_index.html

File tests/Regressions.hs

 
 -- Regression tests for specific bugs.
 
-import Control.Exception (SomeException, bracket, handle)
-import Control.Monad (when)
-import System.Directory (removeFile)
+import Control.Exception (SomeException, handle)
 import System.IO
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy as LB
 import qualified Test.Framework as F
 import qualified Test.Framework.Providers.HUnit as F
 import Test.HUnit (assertFailure)
-
-withTempFile = bracket (openTempFile "." "crashy.txt") cleanupTemp . uncurry
-  where
-    cleanupTemp (path,h) = do
-      open <- hIsOpen h
-      when open (hClose h)
-      removeFile path
+import TestUtils (withTempFile)
 
 -- Reported by Michael Snoyman: UTF-8 encoding a large lazy bytestring
 -- caused either a segfault or attempt to allocate a negative number

File tests/TestUtils.hs

+module TestUtils
+    (
+      withTempFile
+    ) where
+
+import Control.Exception (bracket)
+import Control.Monad (when)
+import System.Directory (removeFile)
+import System.IO (Handle, hClose, hIsOpen, openTempFile)
+
+withTempFile :: (FilePath -> Handle -> IO a) -> IO a
+withTempFile = bracket (openTempFile "." "crashy.txt") cleanupTemp . uncurry
+  where
+    cleanupTemp (path,h) = do
+      open <- hIsOpen h
+      when open (hClose h)
+      removeFile path