File: MkstempSpec.hs

package info (click to toggle)
haskell-unix-compat 0.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 172 kB
  • sloc: ansic: 419; haskell: 334; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 763 bytes parent folder | download
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