Base.hs 840 B

1234567891011121314151617181920212223242526272829303132333435
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Base (simpleTest, noTimeoutTest) where
  3. import Distribution.TestSuite
  4. import System.IO.Error
  5. import Data.Maybe
  6. import System.Timeout
  7. mktest :: String -> IO Progress -> Test
  8. mktest n t = let
  9. test = TestInstance {
  10. run = t,
  11. name = n,
  12. tags = [],
  13. options = [],
  14. setOption = \_ _ -> Right test
  15. }
  16. in Test test
  17. simpleTest :: String -> IO Progress -> Test
  18. simpleTest n t = mktest n . catchTest . timeoutTest $ t
  19. noTimeoutTest :: String -> IO Progress -> Test
  20. noTimeoutTest n t = mktest n . catchTest $ t
  21. catchTest :: IO Progress -> IO Progress
  22. catchTest t = catchIOError t (
  23. \e -> return . Finished . Fail $ "Raised exception: " ++ show e
  24. )
  25. timeoutTest :: IO Progress -> IO Progress
  26. timeoutTest t = fromMaybe (Finished . Fail $ "Timeout!") <$> (
  27. timeout 1000000 t
  28. )