ErrorLogger: add 'column' in serializer/deserializer

This commit is contained in:
Daniel Marjamäki 2019-08-18 09:06:40 +02:00
parent 016647d1d5
commit de9b928d98
2 changed files with 33 additions and 8 deletions

View File

@ -245,7 +245,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc) {
std::ostringstream smallStream;
smallStream << (*loc).line << ':' << (*loc).getfile() << '\t' << loc->getinfo();
smallStream << (*loc).line << ':' << (*loc).col << ':' << (*loc).getfile() << '\t' << loc->getinfo();
oss << smallStream.str().length() << " " << smallStream.str();
}
@ -307,23 +307,28 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
temp.append(1, c);
}
const std::string::size_type colonPos = temp.find(':');
if (colonPos == std::string::npos)
throw InternalError(nullptr, "Internal Error: No colon found in <filename:line> pattern");
const std::string::size_type colonPos1 = temp.find(':');
if (colonPos1 == std::string::npos)
throw InternalError(nullptr, "Internal Error: No colon found in <line:col:filename> pattern");
const std::string::size_type colonPos2 = temp.find(':', colonPos1+1);
if (colonPos2 == std::string::npos)
throw InternalError(nullptr, "Internal Error: second colon not found in <line:col:filename> pattern");
const std::string::size_type tabPos = temp.find('\t');
if (tabPos == std::string::npos)
throw InternalError(nullptr, "Internal Error: No tab found in <filename:line> pattern");
const std::string tempinfo = temp.substr(tabPos + 1);
temp.erase(tabPos);
const std::string tempfile = temp.substr(colonPos + 1);
temp.erase(colonPos);
const std::string tempfile = temp.substr(colonPos2 + 1);
temp.erase(colonPos2);
const std::string tempcolumn = temp.substr(colonPos1 + 1);
temp.erase(colonPos1);
const std::string templine = temp;
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(tempfile);
loc.setinfo(tempinfo);
std::istringstream fiss(templine);
fiss >> loc.line;
loc.col = MathLib::toLongNumber(tempcolumn);
loc.line = MathLib::toLongNumber(templine);
_callStack.push_back(loc);

View File

@ -57,6 +57,7 @@ private:
TEST_CASE(SerializeInconclusiveMessage);
TEST_CASE(DeserializeInvalidInput);
TEST_CASE(SerializeSanitize);
TEST_CASE(SerializeFileLocation);
TEST_CASE(suppressUnmatchedSuppressions);
}
@ -289,6 +290,25 @@ private:
ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.verboseMessage());
}
void SerializeFileLocation() const {
ErrorLogger::ErrorMessage::FileLocation loc1;
loc1.setfile(":/,");
loc1.line = 643;
loc1.col = 33;
loc1.setinfo("abcd:/,");
std::list<ErrorLogger::ErrorMessage::FileLocation> locs{loc1};
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error", "errorId", true);
ErrorMessage msg2;
msg2.deserialize(msg.serialize());
ASSERT_EQUALS(":/,", msg2._callStack.front().getfile(false));
ASSERT_EQUALS(643, msg2._callStack.front().line);
ASSERT_EQUALS(33, msg2._callStack.front().col);
ASSERT_EQUALS("abcd:/,", msg2._callStack.front().getinfo());
}
void suppressUnmatchedSuppressions() {
std::list<Suppressions::Suppression> suppressions;