1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
module MkstempSpec(mkstempSpec) where
import Control.Monad.Parallel
import System.Directory
import System.IO
import System.PosixCompat ( mkstemp )
import Test.Hspec
mkstempSpec :: Spec
mkstempSpec = describe "mkstemp" $ do
it "TODO" $ do
let n = 10000
hSetBuffering stdout NoBuffering
putStr $ "Creating " ++ show n ++ " temp files..."
xs <- replicateM n createTempFile
if length xs == n
then putStrLn "ok"
else putStrLn "FAIL"
putStr "Deleting temp files..."
Control.Monad.Parallel.mapM_ removeFile xs
putStrLn "ok"
createTempFile :: IO FilePath
createTempFile = do
(p,h) <- mkstemp "tempfileXXXXXXX"
hPutStrLn h "this is a temporary file"
hClose h
return p
|