Skip to content

Commit 2e8e1f3

Browse files
committed
Store Error::Type rather than a string in SyntaxTestError
1 parent 0e51e57 commit 2e8e1f3

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

test/CommonSyntaxTest.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
115115
{
116116
assert(static_cast<size_t>(error.locationStart) <= source.length());
117117
assert(static_cast<size_t>(error.locationEnd) <= source.length());
118-
bool isWarning = error.type == "Warning";
118+
bool isWarning = (error.type == Error::Type::Warning);
119119
for (int i = error.locationStart; i < error.locationEnd; i++)
120120
if (isWarning)
121121
{
@@ -190,8 +190,8 @@ void CommonSyntaxTest::printErrorList(
190190
for (auto const& error: _errorList)
191191
{
192192
{
193-
util::AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED});
194-
_stream << _linePrefix << error.type;
193+
util::AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == Error::Type::Warning) ? YELLOW : RED});
194+
_stream << _linePrefix << Error::formatErrorType(error.type);
195195
if (error.errorId.has_value())
196196
_stream << ' ' << error.errorId->error;
197197
_stream << ": ";
@@ -244,7 +244,11 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
244244
auto typeBegin = it;
245245
while (it != line.end() && isalpha(*it, locale::classic()))
246246
++it;
247-
string errorType(typeBegin, it);
247+
248+
string errorTypeStr(typeBegin, it);
249+
optional<Error::Type> errorType = Error::parseErrorType(errorTypeStr);
250+
if (!errorType.has_value())
251+
BOOST_THROW_EXCEPTION(runtime_error("Invalid error type: " + errorTypeStr));
248252

249253
skipWhitespace(it, line.end());
250254

@@ -281,7 +285,7 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
281285

282286
string errorMessage(it, line.end());
283287
expectations.emplace_back(SyntaxTestError{
284-
std::move(errorType),
288+
errorType.value(),
285289
std::move(errorId),
286290
std::move(errorMessage),
287291
std::move(sourceName),

test/CommonSyntaxTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace solidity::test
3434

3535
struct SyntaxTestError
3636
{
37-
std::string type;
37+
langutil::Error::Type type;
3838
std::optional<langutil::ErrorId> errorId;
3939
std::string message;
4040
std::string sourceName;

test/libsolidity/SyntaxTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void SyntaxTest::parseAndAnalyze()
9191
catch (UnimplementedFeatureError const& _e)
9292
{
9393
m_errorList.emplace_back(SyntaxTestError{
94-
"UnimplementedFeatureError",
94+
Error::Type::UnimplementedFeatureError,
9595
std::nullopt,
9696
errorMessage(_e),
9797
"",
@@ -140,7 +140,7 @@ void SyntaxTest::filterObtainedErrors()
140140
}
141141
}
142142
m_errorList.emplace_back(SyntaxTestError{
143-
Error::formatErrorType(currentError->type()),
143+
currentError->type(),
144144
currentError->errorId(),
145145
errorMessage(*currentError),
146146
sourceName,

test/libyul/SyntaxTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void SyntaxTest::parseAndAnalyze()
6161
}
6262

6363
m_errorList.emplace_back(SyntaxTestError{
64-
Error::formatErrorType(error->type()),
64+
error->type(),
6565
error->errorId(),
6666
errorMessage(*error),
6767
name,

0 commit comments

Comments
 (0)