Added error codes to SyntaxTest expectations (changed code)

This commit is contained in:
a3d4 2020-06-22 16:53:03 +02:00
parent e04cedafc5
commit 1d2ae7d82a
6 changed files with 23 additions and 6 deletions

View File

@ -64,7 +64,11 @@ struct InvalidAstError: virtual util::Exception {};
* To create a new ID, one can add 0000_error and then run "python ./scripts/fix_error_ids.py"
* from the root of the repo.
*/
struct ErrorId { unsigned long long error = 0; };
struct ErrorId
{
unsigned long long error = 0;
bool operator==(ErrorId const& _rhs) const { return error == _rhs.error; }
};
constexpr ErrorId operator"" _error(unsigned long long _error) { return ErrorId{ _error }; }
class Error: virtual public util::Exception

View File

@ -165,8 +165,10 @@ void CommonSyntaxTest::printErrorList(
{
{
AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED});
_stream << _linePrefix;
_stream << error.type << ": ";
_stream << _linePrefix << error.type;
if (error.errorId.has_value())
_stream << ' ' << error.errorId->error;
_stream << ": ";
}
if (!error.sourceName.empty() || error.locationStart >= 0 || error.locationEnd >= 0)
{
@ -206,13 +208,17 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
if (it == line.end()) continue;
auto typeBegin = it;
while (it != line.end() && *it != ':')
while (it != line.end() && isalpha(*it))
++it;
string errorType(typeBegin, it);
// skip colon
if (it != line.end()) it++;
skipWhitespace(it, line.end());
optional<ErrorId> errorId;
if (it != line.end() && isdigit(*it))
errorId = ErrorId{static_cast<unsigned long long>(parseUnsignedInteger(it, line.end()))};
expect(it, line.end(), ':');
skipWhitespace(it, line.end());
int locationStart = -1;
@ -242,6 +248,7 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
string errorMessage(it, line.end());
expectations.emplace_back(SyntaxTestError{
move(errorType),
move(errorId),
move(errorMessage),
move(sourceName),
locationStart,

View File

@ -33,6 +33,7 @@ namespace solidity::test
struct SyntaxTestError
{
std::string type;
std::optional<langutil::ErrorId> errorId;
std::string message;
std::string sourceName;
int locationStart = -1;
@ -40,6 +41,7 @@ struct SyntaxTestError
bool operator==(SyntaxTestError const& _rhs) const
{
return type == _rhs.type &&
errorId == _rhs.errorId &&
message == _rhs.message &&
sourceName == _rhs.sourceName &&
locationStart == _rhs.locationStart &&

View File

@ -127,6 +127,7 @@ TestCase::TestResult SMTCheckerJSONTest::run(ostream& _stream, string const& _li
end -= preamble.size();
m_errorList.emplace_back(SyntaxTestError{
error["type"].asString(),
error["errorId"].isNull() ? nullopt : optional<langutil::ErrorId>(langutil::ErrorId{error["errorId"].asUInt()}),
error["message"].asString(),
sourceName,
static_cast<int>(start),

View File

@ -79,6 +79,7 @@ void SyntaxTest::parseAndAnalyze()
{
m_errorList.emplace_back(SyntaxTestError{
"UnimplementedFeatureError",
nullopt,
errorMessage(_e),
"",
-1,
@ -106,6 +107,7 @@ void SyntaxTest::filterObtainedErrors()
}
m_errorList.emplace_back(SyntaxTestError{
currentError->typeName(),
currentError->errorId(),
errorMessage(*currentError),
sourceName,
locationStart,

View File

@ -66,6 +66,7 @@ void SyntaxTest::parseAndAnalyze()
m_errorList.emplace_back(SyntaxTestError{
error->typeName(),
error->errorId(),
errorMessage(*error),
name,
locationStart,