summaryrefslogtreecommitdiff
path: root/test/runTests.hs
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-17 11:21:35 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-17 11:21:35 +0100
commited7cff18118bddc2b57fe1738e7edb2fb0064305 (patch)
treeac38ae6e0e66103429a779c86ce36fc30ea465b3 /test/runTests.hs
parent02d18fe787cbe69d422ad9f76a5324f6ba86f4da (diff)
better path handling
Diffstat (limited to 'test/runTests.hs')
-rw-r--r--test/runTests.hs25
1 files changed, 17 insertions, 8 deletions
diff --git a/test/runTests.hs b/test/runTests.hs
index 7be9cb4b..c36e6c59 100644
--- a/test/runTests.hs
+++ b/test/runTests.hs
@@ -5,11 +5,13 @@
5{-# LANGUAGE RecordWildCards #-} 5{-# LANGUAGE RecordWildCards #-}
6module Main where 6module Main where
7 7
8import Data.Char
8import Data.List 9import Data.List
9import Data.Either 10import Data.Either
10import Data.Time.Clock 11import Data.Time.Clock
11import Data.Algorithm.Patience 12import Data.Algorithm.Patience
12import Control.Applicative 13import Control.Applicative
14import Control.Arrow
13import Control.Concurrent 15import Control.Concurrent
14import Control.Concurrent.Async 16import Control.Concurrent.Async
15import Control.Monad 17import Control.Monad
@@ -43,9 +45,11 @@ getDirectoryContentsRecursive path = do
43 <*> (fmap concat . mapM getDirectoryContentsRecursive . filter ((".ignore" `notElem`) . takeExtensions') =<< filterM doesDirectoryExist l) 45 <*> (fmap concat . mapM getDirectoryContentsRecursive . filter ((".ignore" `notElem`) . takeExtensions') =<< filterM doesDirectoryExist l)
44 46
45takeExtensions' :: FilePath -> [String] 47takeExtensions' :: FilePath -> [String]
46takeExtensions' fn = case splitExtension fn of 48takeExtensions' = snd . splitExtensions'
47 (_, "") -> [] 49
48 (fn', ext) -> ext: takeExtensions' fn' 50splitExtensions' fn = case splitExtension fn of
51 (a, "") -> (a, [])
52 (fn', ext) -> second (ext:) $ splitExtensions' fn'
49 53
50getYNChar = do 54getYNChar = do
51 c <- getChar 55 c <- getChar
@@ -170,8 +174,13 @@ main = do
170 when (or [erroneous r | ((_, r), f) <- zip resultDiffs testSet, isWip f]) $ 174 when (or [erroneous r | ((_, r), f) <- zip resultDiffs testSet, isWip f]) $
171 putStrLn "Only work in progress test cases are failing." 175 putStrLn "Only work in progress test cases are failing."
172 176
177splitMPath fn = (joinPath $ reverse as, foldr1 (</>) $ reverse bs ++ [y], intercalate "." $ reverse bs ++ [y])
178 where
179 (bs, as) = span (\x -> not (null x) && isUpper (head x)) $ reverse xs
180 (xs, y) = map takeDirectory . splitPath *** id $ splitFileName $ dropExtension fn
181
173doTest Config{..} (i, fn) = do 182doTest Config{..} (i, fn) = do
174 liftIO $ putStr $ fn ++ " " 183 liftIO $ putStr $ pa ++ " " ++ mn ++ " " ++ concat exts ++ " "
175 (runtime, res) <- mapMMT (timeOut cfgTimeout $ Left ("!Timed Out", TimedOut)) 184 (runtime, res) <- mapMMT (timeOut cfgTimeout $ Left ("!Timed Out", TimedOut))
176 $ catchErr (\e -> return $ Left (tab "!Crashed" e, ErrorCatched)) 185 $ catchErr (\e -> return $ Left (tab "!Crashed" e, ErrorCatched))
177 $ liftIO . evaluate =<< (force <$> action) 186 $ liftIO . evaluate =<< (force <$> action)
@@ -182,14 +191,14 @@ doTest Config{..} (i, fn) = do
182 liftIO $ putStrLn msg 191 liftIO $ putStrLn msg
183 return (runtime, result) 192 return (runtime, result)
184 where 193 where
185 n = dropExtension fn 194 (splitMPath -> (pa, mn', mn), exts) = splitExtensions' $ dropExtension fn
186 195
187 getMain n = do 196 getMain = do
188 r@(fname, x, _) <- getDef n "main" Nothing 197 r@(fname, x, _) <- local (const $ ioFetch [pa]) $ getDef (mn' ++ concat exts ++ ".lc") "main" Nothing
189 when (isRight x) $ removeFromCache fname 198 when (isRight x) $ removeFromCache fname
190 return r 199 return r
191 200
192 action = f <$> (Right <$> getMain n) `catchMM` (\e is -> return $ Left (e, is)) 201 action = f <$> (Right <$> getMain) `catchMM` (\e is -> return $ Left (e, is))
193 202
194 f | not $ isReject fn = \case 203 f | not $ isReject fn = \case
195 Left (e, i) -> Left (unlines $ tab "!Failed" e: listTraceInfos i, Failed) 204 Left (e, i) -> Left (unlines $ tab "!Failed" e: listTraceInfos i, Failed)