From 7a2d4162cf5d8ceb496bc191eb0c319eecfda3b9 Mon Sep 17 00:00:00 2001 From: Ryan Trinkle Date: Mon, 10 Apr 2023 22:26:20 -0400 Subject: [PATCH] A couple more tests and test cleanups --- src/Test/UIO.hs | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Test/UIO.hs b/src/Test/UIO.hs index a3976bb..3e568be 100644 --- a/src/Test/UIO.hs +++ b/src/Test/UIO.hs @@ -19,8 +19,12 @@ testBoth = do testUIOBadTimeless putStrLn "testUIOMany" testUIOMany + putStrLn "testUIOCycle" + testUIOCycle putStrLn "testIO" testIO +-- putStrLn "testUIOPrintLots" +-- testUIOPrintLots {-# NOINLINE testUIOUnique #-} testUIOUnique :: IO () @@ -33,7 +37,8 @@ testUIOUnique = do unordered $ atomicModifyIORef' r $ \v -> (v + 5, ()) unordered $ atomicModifyIORef' r2 $ \v -> (v + 10, ()) pure r - print =<< readIORef r + 7 <- readIORef r + pure () {-# NOINLINE testUIOFix #-} testUIOFix :: IO () @@ -42,7 +47,8 @@ testUIOFix = do unordered $ atomicModifyIORef' r $ \v -> (v + 5, ()) r <- timeless $ newIORef 2 pure r - print =<< readIORef r + 7 <- readIORef r + pure () {-# NOINLINE testUIOBadTimeless #-} testUIOBadTimeless :: IO () @@ -51,7 +57,8 @@ testUIOBadTimeless = do timeless $ atomicModifyIORef' r $ \v -> (v + 5, ()) r <- timeless $ newIORef 2 pure r - print =<< readIORef r + 2 <- readIORef r + pure () {-# NOINLINE testUIOMany #-} testUIOMany :: IO () @@ -69,7 +76,8 @@ testUIOMany = do unordered $ atomicModifyIORef' r $ \v -> (v + 9, ()) unordered $ atomicModifyIORef' r $ \v -> (v + 10, ()) pure r - print =<< readIORef r + 55 <- readIORef r + pure () {-# NOINLINE testUIOReplicate #-} testUIOReplicate :: IO () @@ -79,12 +87,26 @@ testUIOReplicate = do forM_ rs $ \r -> unordered $ atomicModifyIORef' r $ \v -> (v + 5, ()) pure rs - vs <- mapM readIORef rs - print $ sum vs + 70 <- fmap sum $ mapM readIORef rs + pure () + +{-# NOINLINE testUIOPrintLots #-} +testUIOPrintLots :: IO () +testUIOPrintLots = runUIO2 $ do + replicateM_ 1000000 $ unordered $ putStrLn "Task" + +newtype CycleRef = CycleRef (IORef CycleRef) + +{-# NOINLINE testUIOCycle #-} +testUIOCycle :: IO () +testUIOCycle = runUIO2 $ mdo + r <- timeless $ newIORef $ CycleRef r + pure () {-# NOINLINE testBoth #-} testIO :: IO () testIO = do r <- newIORef 2 atomicModifyIORef' r $ \v -> (v + 5, ()) - print =<< readIORef r + 7 <- readIORef r + pure ()