Update examples
This commit is contained in:
69
testsuite/misc/mkstemps/Main.hs
Normal file
69
testsuite/misc/mkstemps/Main.hs
Normal file
@ -0,0 +1,69 @@
|
||||
|
||||
import System.MkTemp
|
||||
|
||||
import Data.Maybe
|
||||
|
||||
import System.IO
|
||||
import System.Directory
|
||||
|
||||
main = do
|
||||
createDirectory "t"
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Try mkstemp with simple template
|
||||
--
|
||||
ts <- mapM (\_ -> mkstemp "t/t.X" ) [0..(26+26)] -- 1+26+26 files
|
||||
() <- if (not $ all isJust ts)
|
||||
then putStrLn $ "mkstemp couldn't create all expected files"
|
||||
else putStrLn $ "created "++(show $ length $ catMaybes ts)++" files"
|
||||
closeAll ts
|
||||
|
||||
-- next one shouldn't be possible
|
||||
t <- mkstemp "t/t.X"
|
||||
() <- if (not $ isNothing t)
|
||||
then putStrLn $ "shouldn't have been able to create this file"
|
||||
else putStrLn $ "correctly ran out of permutations"
|
||||
closeAll [t]
|
||||
|
||||
rmAll (t:ts)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Try again with large tmp
|
||||
--
|
||||
ts <- mapM (\_->do v <- mkstemp "t/t.XXXXXXXXXX"
|
||||
case v of Just (t,h) -> hClose h >> return v
|
||||
_ -> return v ) [1..10000]
|
||||
|
||||
() <- if (not $ all isJust ts)
|
||||
then putStrLn $ "mkstemp couldn't create all expected files"
|
||||
else putStrLn $ "mkstemp: created "++(show $ length $ catMaybes ts)++" files"
|
||||
rmAll ts
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- test mkstemps
|
||||
--
|
||||
ts <- mapM (\_->do v <- mkstemps "t/t.XXXXXXXXXX.hs" 3
|
||||
case v of Just (t,h) -> hClose h >> return v
|
||||
_ -> return v ) [1..2000]
|
||||
() <- if (not $ all isJust ts)
|
||||
then putStrLn $ "mkstemps couldn't create all expected files"
|
||||
else putStrLn $ "mkstemps: created "++(show $ length $ catMaybes ts)++" files"
|
||||
rmAll ts
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- mkdtemp
|
||||
--
|
||||
ts <- mapM (\_ -> mkdtemp "t/XXXXXXXXXX") [1..2000]
|
||||
() <- if (not $ all isJust ts)
|
||||
then putStrLn $ "mkdtemp: couldn't create all expected directories"
|
||||
else putStrLn $ "mkdtemp: created "++(show $ length $ catMaybes ts)++" directories"
|
||||
rmAllDirs ts
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
removeDirectory "t"
|
||||
|
||||
where
|
||||
closeAll ts = mapM_ hClose $ map snd $ catMaybes ts
|
||||
rmAll ts = mapM_ removeFile $ map fst $ catMaybes ts
|
||||
rmAllDirs ts = mapM_ removeDirectory $ catMaybes ts
|
2
testsuite/misc/mkstemps/Makefile
Normal file
2
testsuite/misc/mkstemps/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
5
testsuite/misc/mkstemps/expected
Normal file
5
testsuite/misc/mkstemps/expected
Normal file
@ -0,0 +1,5 @@
|
||||
created 53 files
|
||||
correctly ran out of permutations
|
||||
mkstemp: created 10000 files
|
||||
mkstemps: created 2000 files
|
||||
mkdtemp: created 2000 directories
|
Reference in New Issue
Block a user