A couple more tests and test cleanups

This commit is contained in:
Ryan Trinkle 2023-04-10 22:26:20 -04:00
parent e4f64347c9
commit 7a2d4162cf

View File

@ -19,8 +19,12 @@ testBoth = do
testUIOBadTimeless testUIOBadTimeless
putStrLn "testUIOMany" putStrLn "testUIOMany"
testUIOMany testUIOMany
putStrLn "testUIOCycle"
testUIOCycle
putStrLn "testIO" putStrLn "testIO"
testIO testIO
-- putStrLn "testUIOPrintLots"
-- testUIOPrintLots
{-# NOINLINE testUIOUnique #-} {-# NOINLINE testUIOUnique #-}
testUIOUnique :: IO () testUIOUnique :: IO ()
@ -33,7 +37,8 @@ testUIOUnique = do
unordered $ atomicModifyIORef' r $ \v -> (v + 5, ()) unordered $ atomicModifyIORef' r $ \v -> (v + 5, ())
unordered $ atomicModifyIORef' r2 $ \v -> (v + 10, ()) unordered $ atomicModifyIORef' r2 $ \v -> (v + 10, ())
pure r pure r
print =<< readIORef r 7 <- readIORef r
pure ()
{-# NOINLINE testUIOFix #-} {-# NOINLINE testUIOFix #-}
testUIOFix :: IO () testUIOFix :: IO ()
@ -42,7 +47,8 @@ testUIOFix = do
unordered $ atomicModifyIORef' r $ \v -> (v + 5, ()) unordered $ atomicModifyIORef' r $ \v -> (v + 5, ())
r <- timeless $ newIORef 2 r <- timeless $ newIORef 2
pure r pure r
print =<< readIORef r 7 <- readIORef r
pure ()
{-# NOINLINE testUIOBadTimeless #-} {-# NOINLINE testUIOBadTimeless #-}
testUIOBadTimeless :: IO () testUIOBadTimeless :: IO ()
@ -51,7 +57,8 @@ testUIOBadTimeless = do
timeless $ atomicModifyIORef' r $ \v -> (v + 5, ()) timeless $ atomicModifyIORef' r $ \v -> (v + 5, ())
r <- timeless $ newIORef 2 r <- timeless $ newIORef 2
pure r pure r
print =<< readIORef r 2 <- readIORef r
pure ()
{-# NOINLINE testUIOMany #-} {-# NOINLINE testUIOMany #-}
testUIOMany :: IO () testUIOMany :: IO ()
@ -69,7 +76,8 @@ testUIOMany = do
unordered $ atomicModifyIORef' r $ \v -> (v + 9, ()) unordered $ atomicModifyIORef' r $ \v -> (v + 9, ())
unordered $ atomicModifyIORef' r $ \v -> (v + 10, ()) unordered $ atomicModifyIORef' r $ \v -> (v + 10, ())
pure r pure r
print =<< readIORef r 55 <- readIORef r
pure ()
{-# NOINLINE testUIOReplicate #-} {-# NOINLINE testUIOReplicate #-}
testUIOReplicate :: IO () testUIOReplicate :: IO ()
@ -79,12 +87,26 @@ testUIOReplicate = do
forM_ rs $ \r -> forM_ rs $ \r ->
unordered $ atomicModifyIORef' r $ \v -> (v + 5, ()) unordered $ atomicModifyIORef' r $ \v -> (v + 5, ())
pure rs pure rs
vs <- mapM readIORef rs 70 <- fmap sum $ mapM readIORef rs
print $ sum vs 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 #-} {-# NOINLINE testBoth #-}
testIO :: IO () testIO :: IO ()
testIO = do testIO = do
r <- newIORef 2 r <- newIORef 2
atomicModifyIORef' r $ \v -> (v + 5, ()) atomicModifyIORef' r $ \v -> (v + 5, ())
print =<< readIORef r 7 <- readIORef r
pure ()