From 036c583ea243869f05a5a311c90b94943a2b635c Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 30 Aug 2019 11:46:13 +0200 Subject: Improve error messages --- tests/TestSuite/Util.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests/TestSuite') diff --git a/tests/TestSuite/Util.hs b/tests/TestSuite/Util.hs index fa411f8..2678fea 100644 --- a/tests/TestSuite/Util.hs +++ b/tests/TestSuite/Util.hs @@ -6,6 +6,7 @@ module TestSuite.Util , newTestProvider , testCompiler , testCompilerDone + , testCompilerError , testConfiguration , cleanTestEnv , renderParagraphs @@ -13,7 +14,7 @@ module TestSuite.Util -------------------------------------------------------------------------------- -import Data.List (intercalate) +import Data.List (intercalate, isInfixOf) import Data.Monoid (mempty) import qualified Data.Set as S import Test.Tasty @@ -80,13 +81,21 @@ testCompilerDone store provider underlying compiler = do CompilerDone x _ -> return x CompilerError e -> fail $ "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++ - " threw: " ++ intercalate "; " e + " threw: " ++ intercalate "; " (compilerErrorMessages e) CompilerRequire i _ -> fail $ "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++ " requires: " ++ show i CompilerSnapshot _ _ -> fail "TestSuite.Util.testCompilerDone: unexpected CompilerSnapshot" +testCompilerError :: Store -> Provider -> Identifier -> Compiler a -> String -> IO () +testCompilerError store provider underlying compiler expectedMessage = do + result <- testCompiler store provider underlying compiler + case result of + CompilerError e -> + any (expectedMessage `isInfixOf`) (compilerErrorMessages e) @? + "Expecting '" ++ expectedMessage ++ "' error" + _ -> assertFailure "Expecting CompilerError" -------------------------------------------------------------------------------- testConfiguration :: Configuration -- cgit v1.2.3