AnalysisFramework.formatErrors(): Require providing errors explicitly

This commit is contained in:
Kamil Śliwak 2023-08-04 20:39:37 +02:00
parent 6c1bcb9a81
commit e42242cd6f
2 changed files with 7 additions and 5 deletions

View File

@ -63,14 +63,14 @@ AnalysisFramework::parseAnalyseAndReturnError(
_allowMultipleErrors = _allowMultipleErrors || _allowRecoveryErrors; _allowMultipleErrors = _allowMultipleErrors || _allowRecoveryErrors;
if (!compiler().parse()) if (!compiler().parse())
{ {
BOOST_FAIL("Parsing contract failed in analysis test suite:" + formatErrors()); BOOST_FAIL("Parsing contract failed in analysis test suite:" + formatErrors(compiler().errors()));
} }
compiler().analyze(); compiler().analyze();
ErrorList errors = filteredErrors(_reportWarnings); ErrorList errors = filteredErrors(_reportWarnings);
if (errors.size() > 1 && !_allowMultipleErrors) if (errors.size() > 1 && !_allowMultipleErrors)
BOOST_FAIL("Multiple errors found: " + formatErrors()); BOOST_FAIL("Multiple errors found: " + formatErrors(compiler().errors()));
return make_pair(&compiler().ast(""), std::move(errors)); return make_pair(&compiler().ast(""), std::move(errors));
} }
@ -123,7 +123,7 @@ SourceUnit const* AnalysisFramework::parseAndAnalyse(string const& _source)
BOOST_REQUIRE(!!sourceAndError.first); BOOST_REQUIRE(!!sourceAndError.first);
string message; string message;
if (!sourceAndError.second.empty()) if (!sourceAndError.second.empty())
message = "Unexpected error: " + formatErrors(); message = "Unexpected error: " + formatErrors(compiler().errors());
BOOST_REQUIRE_MESSAGE(sourceAndError.second.empty(), message); BOOST_REQUIRE_MESSAGE(sourceAndError.second.empty(), message);
return sourceAndError.first; return sourceAndError.first;
} }
@ -142,12 +142,13 @@ ErrorList AnalysisFramework::expectError(std::string const& _source, bool _warni
} }
string AnalysisFramework::formatErrors( string AnalysisFramework::formatErrors(
langutil::ErrorList _errors,
bool _colored, bool _colored,
bool _withErrorIds bool _withErrorIds
) const ) const
{ {
string message; string message;
for (auto const& error: compiler().errors()) for (auto const& error: _errors)
message += formatError(*error, _colored, _withErrorIds); message += formatError(*error, _colored, _withErrorIds);
return message; return message;
} }

View File

@ -58,6 +58,7 @@ protected:
langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false);
std::string formatErrors( std::string formatErrors(
langutil::ErrorList _errors,
bool _colored = false, bool _colored = false,
bool _withErrorIds = false bool _withErrorIds = false
) const; ) const;
@ -158,7 +159,7 @@ do \
auto sourceAndError = parseAnalyseAndReturnError((text), true); \ auto sourceAndError = parseAnalyseAndReturnError((text), true); \
std::string message; \ std::string message; \
if (!sourceAndError.second.empty()) \ if (!sourceAndError.second.empty()) \
message = formatErrors();\ message = formatErrors(compiler().errors());\
BOOST_CHECK_MESSAGE(sourceAndError.second.empty(), message); \ BOOST_CHECK_MESSAGE(sourceAndError.second.empty(), message); \
} \ } \
while(0) while(0)