2 import Control.Exception
5 import System.Directory
8 -- Checks that openTempFile returns filenames with the right structure
11 fp0 <- otf ".no_prefix.hs"
12 print (".hs" `isSuffixOf` fp0)
13 print (".no_prefix" `isPrefixOf` takeFileName fp0)
15 fp1 <- otf "no_suffix"
16 print (not ('.' `elem` fp1))
17 print ("no_suffix" `isPrefixOf` takeFileName fp1)
19 fp2 <- otf "one_suffix.hs"
20 print (".hs" `isSuffixOf` fp2)
21 print ("one_suffix" `isPrefixOf` takeFileName fp2)
23 fp3 <- otf "two_suffixes.hs.blah"
24 print (".blah" `isSuffixOf` fp3)
25 print ("two_suffixes.hs" `isPrefixOf` takeFileName fp3)
27 otf :: FilePath -> IO FilePath
28 otf fp = do putStrLn fp
29 bracket (openTempFile "." fp)
30 (\(fp', h) -> do hClose h
32 (\(fp', _) -> case fp' of
33 '.' : '/' : fp'' -> return fp''
34 '.' : '\\' : fp'' -> return fp''