Store Error::Type rather than a string in SyntaxTestError

This commit is contained in:
Kamil Śliwak 2023-09-29 22:08:10 +02:00
parent fc37b4eeb6
commit 81b5387a9f
4 changed files with 13 additions and 9 deletions

View File

@ -114,7 +114,7 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
{ {
assert(static_cast<size_t>(error.locationStart) <= source.length()); assert(static_cast<size_t>(error.locationStart) <= source.length());
assert(static_cast<size_t>(error.locationEnd) <= source.length()); assert(static_cast<size_t>(error.locationEnd) <= source.length());
bool isWarning = error.type == "Warning"; bool isWarning = (error.type == Error::Type::Warning);
for (int i = error.locationStart; i < error.locationEnd; i++) for (int i = error.locationStart; i < error.locationEnd; i++)
if (isWarning) if (isWarning)
{ {
@ -192,8 +192,8 @@ void CommonSyntaxTest::printErrorList(
for (auto const& error: _errorList) for (auto const& error: _errorList)
{ {
{ {
util::AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED}); util::AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == Error::Type::Warning) ? YELLOW : RED});
_stream << _linePrefix << error.type; _stream << _linePrefix << Error::formatErrorType(error.type);
if (error.errorId.has_value()) if (error.errorId.has_value())
_stream << ' ' << error.errorId->error; _stream << ' ' << error.errorId->error;
_stream << ": "; _stream << ": ";
@ -246,7 +246,11 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
auto typeBegin = it; auto typeBegin = it;
while (it != line.end() && isalpha(*it, locale::classic())) while (it != line.end() && isalpha(*it, locale::classic()))
++it; ++it;
string errorType(typeBegin, it);
std::string errorTypeStr(typeBegin, it);
optional<Error::Type> errorType = Error::parseErrorType(errorTypeStr);
if (!errorType.has_value())
BOOST_THROW_EXCEPTION(runtime_error("Invalid error type: " + errorTypeStr));
skipWhitespace(it, line.end()); skipWhitespace(it, line.end());
@ -283,7 +287,7 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
string errorMessage(it, line.end()); string errorMessage(it, line.end());
expectations.emplace_back(SyntaxTestError{ expectations.emplace_back(SyntaxTestError{
std::move(errorType), errorType.value(),
std::move(errorId), std::move(errorId),
std::move(errorMessage), std::move(errorMessage),
std::move(sourceName), std::move(sourceName),

View File

@ -34,7 +34,7 @@ namespace solidity::test
struct SyntaxTestError struct SyntaxTestError
{ {
std::string type; langutil::Error::Type type;
std::optional<langutil::ErrorId> errorId; std::optional<langutil::ErrorId> errorId;
std::string message; std::string message;
std::string sourceName; std::string sourceName;

View File

@ -86,7 +86,7 @@ void SyntaxTest::parseAndAnalyze()
catch (UnimplementedFeatureError const& _e) catch (UnimplementedFeatureError const& _e)
{ {
m_errorList.emplace_back(SyntaxTestError{ m_errorList.emplace_back(SyntaxTestError{
"UnimplementedFeatureError", Error::Type::UnimplementedFeatureError,
nullopt, nullopt,
errorMessage(_e), errorMessage(_e),
"", "",
@ -135,7 +135,7 @@ void SyntaxTest::filterObtainedErrors()
} }
} }
m_errorList.emplace_back(SyntaxTestError{ m_errorList.emplace_back(SyntaxTestError{
Error::formatErrorType(currentError->type()), currentError->type(),
currentError->errorId(), currentError->errorId(),
errorMessage(*currentError), errorMessage(*currentError),
sourceName, sourceName,

View File

@ -61,7 +61,7 @@ void SyntaxTest::parseAndAnalyze()
} }
m_errorList.emplace_back(SyntaxTestError{ m_errorList.emplace_back(SyntaxTestError{
Error::formatErrorType(error->type()), error->type(),
error->errorId(), error->errorId(),
errorMessage(*error), errorMessage(*error),
name, name,