diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-06 12:29:36 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-06 12:29:36 +0200 |
commit | d353a29bb93d3105a763465300b28250117c3f40 (patch) | |
tree | 1517e23109d5e3c266b634b3c7af4dd4ca29e4d7 /test | |
parent | 3430070058610b6aeab2543bc050bb1cf2e95d0c (diff) |
show typechecked source code in .out files & fix local function handling (again)
Diffstat (limited to 'test')
-rw-r--r-- | test/runTests.hs | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/test/runTests.hs b/test/runTests.hs index f9bb5424..b817ed0b 100644 --- a/test/runTests.hs +++ b/test/runTests.hs | |||
@@ -3,15 +3,17 @@ | |||
3 | {-# LANGUAGE ViewPatterns #-} | 3 | {-# LANGUAGE ViewPatterns #-} |
4 | {-# LANGUAGE FlexibleContexts #-} | 4 | {-# LANGUAGE FlexibleContexts #-} |
5 | {-# LANGUAGE RecordWildCards #-} | 5 | {-# LANGUAGE RecordWildCards #-} |
6 | {-# LANGUAGE NoMonomorphismRestriction #-} | ||
6 | module Main where | 7 | module Main where |
7 | 8 | ||
8 | import Data.Char | 9 | import Data.Char |
9 | import Data.List | 10 | import Data.List |
10 | --import Data.Either | 11 | --import Data.Either |
12 | import qualified Data.Map.Strict as Map | ||
11 | import Data.Time.Clock | 13 | import Data.Time.Clock |
12 | import Data.Algorithm.Patience | 14 | import Data.Algorithm.Patience |
13 | import Control.Applicative | 15 | import Control.Applicative |
14 | import Control.Arrow | 16 | import Control.Arrow hiding ((<+>)) |
15 | import Control.Concurrent | 17 | import Control.Concurrent |
16 | import Control.Concurrent.Async | 18 | import Control.Concurrent.Async |
17 | import Control.Monad | 19 | import Control.Monad |
@@ -34,6 +36,8 @@ import LambdaCube.Compiler.Pretty hiding ((</>)) | |||
34 | 36 | ||
35 | ------------------------------------------ utils | 37 | ------------------------------------------ utils |
36 | 38 | ||
39 | (<&>) = flip (<$>) | ||
40 | |||
37 | readFileStrict :: FilePath -> IO String | 41 | readFileStrict :: FilePath -> IO String |
38 | readFileStrict = fmap T.unpack . TIO.readFile | 42 | readFileStrict = fmap T.unpack . TIO.readFile |
39 | 43 | ||
@@ -204,25 +208,42 @@ doTest Config{..} (i, fn) = do | |||
204 | (splitMPath -> (pa, mn', mn), reverse -> exts) = splitExtensions' $ dropExtension fn | 208 | (splitMPath -> (pa, mn', mn), reverse -> exts) = splitExtensions' $ dropExtension fn |
205 | 209 | ||
206 | getMain = do | 210 | getMain = do |
207 | (is, res) <- local (const $ ioFetch [pa]) $ getDef (mn' ++ concat exts ++ ".lc") "main" Nothing | 211 | res <- local (const $ ioFetch [pa]) $ loadModule id Nothing (Left $ mn' ++ concat exts ++ ".lc") <&> \case |
208 | (,) is <$> case res of | 212 | Left err -> (mempty, Left err) |
209 | Left err -> return $ Left err | 213 | Right (fname, (src, Left err)) -> (mempty, Left err) |
210 | Right (fname, x@Left{}) -> return $ Right (fname, x) | 214 | Right (fname, (src, Right (pm, infos, Left err))) -> (,) infos $ Left err |
211 | Right (fname, x@Right{}) -> Right (fname, x) <$ removeFromCache fname | 215 | Right (fname, (src, Right (pm, infos, Right (_, ge)))) -> (,) infos $ Right |
216 | ( fname | ||
217 | , ge | ||
218 | , case Map.lookup "main" ge of | ||
219 | Just (e, thy, si) -> Right (ET e thy) | ||
220 | Nothing -> Left $ text "main" <+> "is not found" | ||
221 | ) | ||
222 | case res of | ||
223 | (_, Right (fi, _, Right{})) -> removeFromCache $ filePath fi | ||
224 | _ -> return () | ||
225 | return res | ||
226 | |||
227 | --getDef :: MonadMask m => FilePath -> SName -> Maybe Exp -> MMT m (Infos, [Stmt]) ((Infos, [Stmt]), Either Doc (FilePath, Either Doc ExpType)) | ||
212 | 228 | ||
213 | f ((i, desug), e) | not $ isReject fn = case e of | 229 | f ((i, desug), e) | not $ isReject fn = case e of |
214 | Left (show -> e) -> Left (unlines $ tab "!Failed" e: map show (listTraceInfos i), Failed) | 230 | Left (show -> e) -> Left (unlines $ tab "!Failed" e: map show (listTraceInfos i), Failed) |
215 | Right (fname, Left (pShow -> e)) | 231 | Right (fname, ge, Left (pShow -> e)) |
216 | -> Right ("typechecked module" | 232 | -> Right ("typechecked module" |
217 | , simpleShow $ vcat $ e: "------------ desugared source code": intersperse "" (map pShow desug) ++ | 233 | , simpleShow $ vcat $ e |
218 | listAllInfos i) | 234 | : "------------ desugared source code": intersperse "" (map pShow desug) |
219 | Right (fname, Right (ET e te)) | 235 | ++ "------------ core code": intersperse "" |
236 | [ DAnn (text n) (DResetFreshNames $ pShow t) | ||
237 | <$$> DLet "=" (text n) (DResetFreshNames $ mkDoc (True, True) e) | ||
238 | | (n, (e, t, RangeSI (Range fi _ _))) <- Map.toList ge, fileId fi == fileId fname] | ||
239 | ++ listAllInfos' i) | ||
240 | Right (fname, ge, Right (ET e te)) | ||
220 | | te == outputType -> Right ("compiled pipeline", prettyShowUnlines $ compilePipeline OpenGL33 (ET e te)) | 241 | | te == outputType -> Right ("compiled pipeline", prettyShowUnlines $ compilePipeline OpenGL33 (ET e te)) |
221 | | e == trueExp -> Right ("reducted main", de) | 242 | | e == trueExp -> Right ("reducted main", de) |
222 | | te == boolType -> Left (tab "!Failed" $ "main should be True but it is \n" ++ de, Failed) | 243 | | te == boolType -> Left (tab "!Failed" $ "main should be True but it is \n" ++ de, Failed) |
223 | | otherwise -> Right ("reduced main " ++ ppShow te, de) | 244 | | otherwise -> Right ("reduced main " ++ ppShow te, de) |
224 | where | 245 | where |
225 | de = simpleShow (mkDoc True e) | 246 | de = simpleShow (mkDoc (True, False) e) |
226 | | otherwise = case e of | 247 | | otherwise = case e of |
227 | Left (pShow -> e) -> Right ("error message", simpleShow $ vcat $ e: listAllInfos i) | 248 | Left (pShow -> e) -> Right ("error message", simpleShow $ vcat $ e: listAllInfos i) |
228 | Right _ -> Left (tab "!Failed" "failed to catch error", Failed) | 249 | Right _ -> Left (tab "!Failed" "failed to catch error", Failed) |