summaryrefslogtreecommitdiff
path: root/libraries/base/tests/tempfiles.hs
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2011-05-08 22:04:51 +0100
committerIan Lynagh <igloo@earth.li>2011-05-23 18:52:23 +0100
commita21710bf52af581d60a754636d3ccdac591639a2 (patch)
tree25190cdf05974411b8838c26738ca48c1fce6e3f /libraries/base/tests/tempfiles.hs
parent4a669405efbd83993a3e2361a302a36bea36c00f (diff)
downloadhaskell-a21710bf52af581d60a754636d3ccdac591639a2.tar.gz
Move tests from testsuite/tests/libraries
Diffstat (limited to 'libraries/base/tests/tempfiles.hs')
-rw-r--r--libraries/base/tests/tempfiles.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/libraries/base/tests/tempfiles.hs b/libraries/base/tests/tempfiles.hs
new file mode 100644
index 0000000000..2fc156034f
--- /dev/null
+++ b/libraries/base/tests/tempfiles.hs
@@ -0,0 +1,36 @@
+
+import Control.Exception
+import Data.List
+import System.FilePath
+import System.Directory
+import System.IO
+
+-- Checks that openTempFile returns filenames with the right structure
+main :: IO ()
+main = do
+ fp0 <- otf ".no_prefix.hs"
+ print (".hs" `isSuffixOf` fp0)
+ print (".no_prefix" `isPrefixOf` takeFileName fp0)
+
+ fp1 <- otf "no_suffix"
+ print (not ('.' `elem` fp1))
+ print ("no_suffix" `isPrefixOf` takeFileName fp1)
+
+ fp2 <- otf "one_suffix.hs"
+ print (".hs" `isSuffixOf` fp2)
+ print ("one_suffix" `isPrefixOf` takeFileName fp2)
+
+ fp3 <- otf "two_suffixes.hs.blah"
+ print (".blah" `isSuffixOf` fp3)
+ print ("two_suffixes.hs" `isPrefixOf` takeFileName fp3)
+
+otf :: FilePath -> IO FilePath
+otf fp = do putStrLn fp
+ bracket (openTempFile "." fp)
+ (\(fp', h) -> do hClose h
+ removeFile fp')
+ (\(fp', _) -> case fp' of
+ '.' : '/' : fp'' -> return fp''
+ '.' : '\\' : fp'' -> return fp''
+ _ -> return fp')
+