{-- Haskell98! --} -- Simple IO Regions. Tests -- $Id: IORegions98Test.hs,v 1.1 2006/01/24 00:29:38 oleg Exp oleg $ module IORegions98Test where import IORegions98E import Monad import Data.Typeable -- We define the following just as an attempt to break the safety -- gurantee. Users should NOT add the following two instances. -- However, even if they do, the safety gurantees still hold instance Typeable1 Q instance Typeable2 IOM reader q = do c1 <- qGetChar q c2 <- qGetChar q return [c1,c2] test0 = withFile "/etc/motd" (const $ return True) test1 = withFile "/etc/motd" reader test1r = runIOM test1 >>= print -- An attempt to leak a handle -- test2 = runIOM (withFile "/etc/motd" (\q -> return q)) test3 = withFile "/etc/motd" (\q -> (qGetChar q)) -- An attempt to leak a computation that uses the handle -- test4 = withFile "/etc/motd" (\q -> return (qGetChar q)) -- Dealing with two handles -- Now we add the type signature, just to show that we can do that reader2 :: Q mark -> Q mark -> IOM mark String reader2 q1 q2 = do c1 <- qGetChar q1 c2 <- qGetChar q2 return [c1,c2] test5 = withFile "/etc/motd" (\q1 -> withFile "/etc/motd" (\q2 -> reader2 q1 q2)) test5r = runIOM test5 >>= print -- An attempt to leak the handles. {- test6 = withFile "/etc/motd" (\q2 -> do q' <- withFile "/etc/motd" (\q -> return q) qGetChar q') test7 = withFile "/etc/motd" (\q2 -> do q' <- withFile "/etc/motd" (\q -> return q2) qGetChar q') -} {- -- An attempt to leak computations involving handles test8 = runIOM (withFile "/etc/motd" (\q2 -> do a <- withFile "/etc/motd" (\q -> return (qGetChar q)) a)) test9 = withFile "/etc/motd" (\q2 -> do a <- withFile "/etc/motd" (\q -> return (qGetChar q2)) a) test9r = runIOM test9 >>= print -} -- An attempt to leak a computation that uses the handle, by Brandon Moore test4' () = join $ withFile "/etc/motd" (\q -> return (qGetChar q)) -- But we can't use test4': -- test4'r = runIOM (test4' ()) -- Another test by Brandon Moore -- Making sure runIOM can be used properly -- testMinus1 = join $ runIOM $ withFile "/etc/motd" $ return . runIOM . qGetChar