diff options
author | Ian Lynagh <igloo@earth.li> | 2011-05-08 22:04:51 +0100 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2011-05-23 18:52:23 +0100 |
commit | a21710bf52af581d60a754636d3ccdac591639a2 (patch) | |
tree | 25190cdf05974411b8838c26738ca48c1fce6e3f /libraries/base/tests/tempfiles.hs | |
parent | 4a669405efbd83993a3e2361a302a36bea36c00f (diff) | |
download | haskell-a21710bf52af581d60a754636d3ccdac591639a2.tar.gz |
Move tests from testsuite/tests/libraries
Diffstat (limited to 'libraries/base/tests/tempfiles.hs')
-rw-r--r-- | libraries/base/tests/tempfiles.hs | 36 |
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') + |