UnkindPartition / tasty

Modern and extensible testing framework for Haskell
638 stars 108 forks source link

Simple TestReporter ingredient makes the testsuite hang #336

Closed KristianBalaj closed 4 months ago

KristianBalaj commented 2 years ago

The following code runs forever even if it should not according to the documentation since the tasty runs the tests in case of TestReporter. It just wants to print resultDescription of every test.

main :: IO ()
main = do
  defaultMainWithIngredients [myReporter] $
    testGroup
      "my suite"
      [ testCase "" $ assertBool "" True
      ]

myReporter :: Ingredient
myReporter = TestReporter [] $
  \opts tree -> Just $ \smap -> do
    return $ \time -> do
      foldM (\acc a -> fmap (acc &&) (getResultFromTVar a >>= processResult)) True smap

processResult :: Result -> IO Bool
processResult res = putStrLn (resultDescription res) >> pure True

getResultFromTVar :: TVar Status -> IO Result
getResultFromTVar var =
  atomically $ do
    status <- readTVar var
    case status of
      Done r -> return r
      _ -> retry

The Done case never happens in the getResultFromTVar and only the retry case is happening.

Bodigrim commented 4 months ago

FWIW it does not run forever for me, but rather throws Exception: AsyncCancelled.

#!/usr/bin/env cabal
{- cabal:
build-depends: tasty, tasty-hunit, base, stm
-}

module Main where

import Control.Exception
import Control.Monad
import Test.Tasty
import Test.Tasty.Runners
import Test.Tasty.HUnit
import Control.Concurrent.STM

main :: IO ()
main = do
  defaultMainWithIngredients [myReporter] $
    testGroup
      "my suite"
      [ testCase "" $ assertBool "" True
      ]

myReporter :: Ingredient
myReporter = TestReporter [] $
  \opts tree -> Just $ \smap -> do
    return $ \time -> do
      foldM (\acc a -> fmap (acc &&) (getResultFromTVar a >>= processResult)) True smap

processResult :: Result -> IO Bool
processResult res = putStrLn (resultDescription res) >> pure True

getResultFromTVar :: TVar Status -> IO Result
getResultFromTVar var =
  atomically $ do
    status <- readTVar var
    case status of
      Done r -> return r
      _ -> retry
KristianBalaj commented 4 months ago

It's already quite old, maybe I've used some broken tasty version. I believe this is no longer relevant. Closing...