From c2aaf2fcf760a7a94237ba6fa8d268d6e9f65f4c Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 23 Jan 2009 14:42:46 +0000 Subject: [PATCH] Provided more helpful errors in the test harness when something is wrong --- common/TestHarness.hs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/common/TestHarness.hs b/common/TestHarness.hs index 976fd1d..7844ae0 100644 --- a/common/TestHarness.hs +++ b/common/TestHarness.hs @@ -96,18 +96,20 @@ testRain source = do (result,_) <- runPassM (defaultState FrontendRain) compila -- | Substitutes each substitution into the prologue substitute :: AutoTest -> Either String [(Bool, String, String)] -substitute t = sequence [ do ls <- execWriterT $ subst (prologueLines t, ss) +substitute t = sequence [ do ls <- execWriterT $ subst n (prologueLines t, ss) return (p, n, unlines ls) | TestBody p n ss <- bodies t] where - subst :: ([TestLine], [(String, [String])]) -> WriterT [String] (Either String) () - subst ([], []) = return () - subst ([], subs) = throwError $ "Left over substitutions: " ++ show subs - subst (Line l : ls, subs) = tell [l] >> subst (ls, subs) - subst (Sub s : ls, subs) + subst :: String -> ([TestLine], [(String, [String])]) -> WriterT [String] (Either String) () + subst _ ([], []) = return () + subst n ([], subs) = throwError $ "Left over substitutions: " ++ show subs + ++ " in " ++ n + subst n (Line l : ls, subs) = tell [l] >> subst n (ls, subs) + subst n (Sub s : ls, subs) = case lookup s subs of - Just subLines -> tell subLines >> subst (ls, filter ((/= s) . fst) subs) - Nothing -> throwError $ "Could not find substitution \"" ++ s ++ "\"" + Just subLines -> tell subLines >> subst n (ls, filter ((/= s) . fst) subs) + Nothing -> throwError $ "Could not find substitution \"" ++ s + ++ "\" in test: " ++ n -- | Given a file's contents, tests it