add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / tests / tempfiles.hs
1
2 import Control.Exception
3 import Data.List
4 import System.FilePath
5 import System.Directory
6 import System.IO
7
8 -- Checks that openTempFile returns filenames with the right structure
9 main :: IO ()
10 main = do
11  fp0 <- otf ".no_prefix.hs"
12  print (".hs"        `isSuffixOf` fp0)
13  print (".no_prefix" `isPrefixOf` takeFileName fp0)
14
15  fp1 <- otf "no_suffix"
16  print (not ('.' `elem` fp1))
17  print ("no_suffix" `isPrefixOf` takeFileName fp1)
18
19  fp2 <- otf "one_suffix.hs"
20  print (".hs"        `isSuffixOf` fp2)
21  print ("one_suffix" `isPrefixOf` takeFileName fp2)
22
23  fp3 <- otf "two_suffixes.hs.blah"
24  print (".blah"           `isSuffixOf` fp3)
25  print ("two_suffixes.hs" `isPrefixOf` takeFileName fp3)
26
27 otf :: FilePath -> IO FilePath
28 otf fp = do putStrLn fp
29             bracket (openTempFile "." fp)
30                     (\(fp', h) -> do hClose h
31                                      removeFile fp')
32                     (\(fp', _) -> case fp' of
33                                   '.' : '/'  : fp'' -> return fp''
34                                   '.' : '\\' : fp'' -> return fp''
35                                   _                 -> return fp')
36