diff options
author | Andor Penzes <andor.penzes@gmail.com> | 2016-01-20 22:47:45 +0100 |
---|---|---|
committer | Andor Penzes <andor.penzes@gmail.com> | 2016-01-20 22:47:52 +0100 |
commit | 4658e1f62d467b683639c4a7082a1e5f360ab732 (patch) | |
tree | 95dca983c6abfa5fb8201a1cda002cbde72e866d /test/runTests.hs | |
parent | 0d78183129e77d81766819a1527e4a7b1c571d3c (diff) |
Print the runtime of test cases.
Diffstat (limited to 'test/runTests.hs')
-rw-r--r-- | test/runTests.hs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/test/runTests.hs b/test/runTests.hs index 3e37a992..42a9625d 100644 --- a/test/runTests.hs +++ b/test/runTests.hs | |||
@@ -5,6 +5,7 @@ | |||
5 | module Main where | 5 | module Main where |
6 | 6 | ||
7 | import Data.List | 7 | import Data.List |
8 | import Data.Time.Clock | ||
8 | import Control.Applicative | 9 | import Control.Applicative |
9 | import Control.Arrow | 10 | import Control.Arrow |
10 | import Control.Concurrent | 11 | import Control.Concurrent |
@@ -172,13 +173,18 @@ testFrame Config{..} dirs f tests | |||
172 | dirs' = dirs ++ dirs_ -- if null dirs_ then dirs else dirs_ | 173 | dirs' = dirs ++ dirs_ -- if null dirs_ then dirs else dirs_ |
173 | 174 | ||
174 | 175 | ||
175 | timeOut :: Int -> a -> MM a -> MM a | 176 | timeOut :: Int -> a -> MM a -> MM (NominalDiffTime, a) |
176 | timeOut n d = mapMMT $ \m -> | 177 | timeOut n d = mapMMT $ \m -> |
177 | control (\runInIO -> | 178 | control (\runInIO -> |
178 | race' (runInIO m) | 179 | race' (runInIO $ timeDiff m) |
179 | (threadDelay (n * 1000000) >> (runInIO $ return d))) | 180 | (runInIO $ timeDiff ((liftIO $ threadDelay (n * 1000000)) >> return d)) |
181 | ) | ||
180 | where | 182 | where |
181 | race' a b = either id id <$> race a b | 183 | race' a b = either id id <$> race a b |
184 | timeDiff m = (\s x e -> (diffUTCTime e s, x)) | ||
185 | <$> liftIO getCurrentTime | ||
186 | <*> m | ||
187 | <*> liftIO getCurrentTime | ||
182 | 188 | ||
183 | testFrame_ timeout compareResult path action tests = fmap concat $ forM (zip [1..] (tests :: [TestCasePath])) $ \(i, tn) -> do | 189 | testFrame_ timeout compareResult path action tests = fmap concat $ forM (zip [1..] (tests :: [TestCasePath])) $ \(i, tn) -> do |
184 | let n = testCaseVal tn | 190 | let n = testCaseVal tn |
@@ -186,13 +192,15 @@ testFrame_ timeout compareResult path action tests = fmap concat $ forM (zip [1. | |||
186 | liftIO $ putStrLn $ "\n!Crashed " ++ n ++ "\n" ++ tab e | 192 | liftIO $ putStrLn $ "\n!Crashed " ++ n ++ "\n" ++ tab e |
187 | return $ [(,) ErrorCatched <$> tn] | 193 | return $ [(,) ErrorCatched <$> tn] |
188 | catchErr er $ do | 194 | catchErr er $ do |
189 | result <- timeOut timeout (Left "Timed Out") (action n) | 195 | liftIO $ putStrLn $ unwords ["\nStart to compile", n] |
196 | (runtime, result) <- timeOut timeout (Left "Timed Out") (action n) | ||
190 | liftIO $ case result of | 197 | liftIO $ case result of |
191 | Left e -> do | 198 | Left e -> do |
192 | putStrLn $ "\n!Failed " ++ n ++ "\n" ++ tab e | 199 | putStrLn $ "\n!Failed " ++ n ++ "in" ++ show runtime ++ "\n" ++ tab e |
193 | return [(,) Failed <$> tn] | 200 | return [(,) Failed <$> tn] |
194 | Right (op, x) -> do | 201 | Right (op, x) -> do |
195 | length x `seq` compareResult tn (pad 15 op) (path </> (n ++ ".out")) x | 202 | putStrLn $ unwords ["Runtime:", show runtime] |
203 | length x `seq` compareResult tn (pad 15 op) (path </> (n ++ ".out")) x | ||
196 | where | 204 | where |
197 | tab = unlines . map (" " ++) . lines | 205 | tab = unlines . map (" " ++) . lines |
198 | 206 | ||