Inconclusive checking: Report inconclusive errors with reportInconclusiveError. It takes the same parameters as reportError.

This commit is contained in:
Daniel Marjamäki 2011-04-14 18:02:01 +02:00
parent 7021e3224b
commit 58dbbb0cab
12 changed files with 95 additions and 60 deletions

View File

@ -254,7 +254,8 @@ unsigned int ThreadExecutor::check()
const ErrorLogger::ErrorMessage errmsg(locations, const ErrorLogger::ErrorMessage errmsg(locations,
Severity::error, Severity::error,
oss.str(), oss.str(),
"cppcheckError"); "cppcheckError",
false);
_errorLogger.reportErr(errmsg); _errorLogger.reportErr(errmsg);
} }
} }

View File

@ -128,6 +128,32 @@ protected:
/** report an error */ /** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg) void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg)
{
reportError(callstack, severity, id, msg, false);
}
/** report an inconclusive error */
void reportInconclusiveError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg)
{
std::list<const Token *> callstack;
if (tok)
callstack.push_back(tok);
reportInconclusiveError(callstack, severity, id, msg);
}
/** report an inconclusive error */
void reportInconclusiveError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg)
{
reportError(callstack, severity, id, msg, true);
}
private:
/** disabled assignment operator */
void operator=(const Check &);
/** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg, bool inconclusive)
{ {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList; std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it)
@ -142,7 +168,7 @@ protected:
locationList.push_back(loc); locationList.push_back(loc);
} }
ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id); ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id, inconclusive);
if (_tokenizer && _tokenizer->getFiles() && !_tokenizer->getFiles()->empty()) if (_tokenizer && _tokenizer->getFiles() && !_tokenizer->getFiles()->empty())
errmsg.file0 = _tokenizer->getFiles()->at(0); errmsg.file0 = _tokenizer->getFiles()->at(0);
if (_errorLogger) if (_errorLogger)
@ -151,12 +177,6 @@ protected:
reportError(errmsg); reportError(errmsg);
} }
private:
/** disabled assignment operator */
void operator=(const Check &);
}; };
namespace std namespace std

View File

@ -352,7 +352,7 @@ void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Sever
locations.push_back(loc); locations.push_back(loc);
} }
const ErrorLogger::ErrorMessage errmsg(locations, severity, msg, id); const ErrorLogger::ErrorMessage errmsg(locations, severity, msg, id, false);
if (errorLogger) if (errorLogger)
errorLogger->reportErr(errmsg); errorLogger->reportErr(errmsg);

View File

@ -192,7 +192,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
locationList.push_back(fileLoc); locationList.push_back(fileLoc);
} }
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction"); const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction", false);
if (errorLogger) if (errorLogger)
errorLogger->reportErr(errmsg); errorLogger->reportErr(errmsg);
else else

View File

@ -164,7 +164,8 @@ unsigned int CppCheck::check()
ErrorLogger::ErrorMessage errmsg(loclist, ErrorLogger::ErrorMessage errmsg(loclist,
Severity::information, Severity::information,
msg, msg,
"toomanyconfigs"); "toomanyconfigs",
false);
_errorLogger.reportErr(errmsg); _errorLogger.reportErr(errmsg);
break; break;
} }
@ -333,7 +334,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(), ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
Severity::error, Severity::error,
error, error,
"pcre_compile"); "pcre_compile",
false);
reportErr(errmsg); reportErr(errmsg);
} }
@ -375,7 +377,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
summary = "found '" + str.substr(pos1, pos2 - pos1) + "'"; summary = "found '" + str.substr(pos1, pos2 - pos1) + "'";
else else
summary = rule.summary; summary = rule.summary;
ErrorLogger::ErrorMessage errmsg(callStack, Severity::fromString(rule.severity), summary, rule.id); const ErrorLogger::ErrorMessage errmsg(callStack, Severity::fromString(rule.severity), summary, rule.id, false);
// Report error // Report error
reportErr(errmsg); reportErr(errmsg);

View File

@ -26,10 +26,10 @@
ErrorLogger::ErrorMessage::ErrorMessage() ErrorLogger::ErrorMessage::ErrorMessage()
:_severity(Severity::none) :_severity(Severity::none)
{ {
_inconclusive = false;
} }
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id) ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive)
{ {
// locations for this error message // locations for this error message
_callStack = callStack; _callStack = callStack;
@ -42,6 +42,8 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack
// set the message id // set the message id
_id = id; _id = id;
_inconclusive = inconclusive;
} }
void ErrorLogger::ErrorMessage::setmsg(const std::string &msg) void ErrorLogger::ErrorMessage::setmsg(const std::string &msg)
@ -68,6 +70,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
std::ostringstream oss; std::ostringstream oss;
oss << _id.length() << " " << _id; oss << _id.length() << " " << _id;
oss << Severity::toString(_severity).length() << " " << Severity::toString(_severity); oss << Severity::toString(_severity).length() << " " << Severity::toString(_severity);
oss << (_inconclusive ? "12 inconclusive" : "");
oss << _shortMessage.length() << " " << _shortMessage; oss << _shortMessage.length() << " " << _shortMessage;
oss << _verboseMessage.length() << " " << _verboseMessage; oss << _verboseMessage.length() << " " << _verboseMessage;
oss << _callStack.size() << " "; oss << _callStack.size() << " ";
@ -84,6 +87,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
{ {
_inconclusive = false;
_callStack.clear(); _callStack.clear();
std::istringstream iss(data); std::istringstream iss(data);
std::vector<std::string> results; std::vector<std::string> results;
@ -101,6 +105,12 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
temp.append(1, c); temp.append(1, c);
} }
if (temp == "inconclusive")
{
_inconclusive = true;
break;
}
results.push_back(temp); results.push_back(temp);
if (results.size() == 4) if (results.size() == 4)
break; break;
@ -205,7 +215,7 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
if (version == 1) if (version == 1)
{ {
// No inconclusive messages in the xml version 1 // No inconclusive messages in the xml version 1
if (Severity::toString(_severity).compare(0,12,"inconclusive")==0) if (_inconclusive)
return ""; return "";
xml << "<error"; xml << "<error";
@ -224,7 +234,7 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
else if (version == 2) else if (version == 2)
{ {
// TODO: How should inconclusive messages be saved in the xml version 2? // TODO: How should inconclusive messages be saved in the xml version 2?
if (Severity::toString(_severity).compare(0,12,"inconclusive")==0) if (_inconclusive)
return ""; return "";
xml << " <error"; xml << " <error";
@ -305,7 +315,7 @@ void ErrorLogger::reportUnmatchedSuppressions(const std::list<Settings::Suppress
{ {
std::list<ErrorLogger::ErrorMessage::FileLocation> callStack; std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->file, i->line)); callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->file, i->line));
reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression")); reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false));
} }
} }

View File

@ -88,13 +88,7 @@ public:
* Debug message. * Debug message.
* Debug-mode message useful for the developers. * Debug-mode message useful for the developers.
*/ */
debug, debug
/** inconclusive error */
inconclusive_error,
/** inconclusive warning */
inconclusive_warning
}; };
static std::string toString(SeverityType severity) static std::string toString(SeverityType severity)
@ -117,10 +111,6 @@ public:
return "information"; return "information";
case debug: case debug:
return "debug"; return "debug";
case inconclusive_error:
return "inconclusive error";
case inconclusive_warning:
return "inconclusive warning";
}; };
return "???"; return "???";
} }
@ -144,10 +134,6 @@ public:
return information; return information;
if (severity == "debug") if (severity == "debug")
return debug; return debug;
if (severity == "inconclusive error")
return inconclusive_error;
if (severity == "inconclusive warning")
return inconclusive_warning;
return none; return none;
} }
}; };
@ -202,7 +188,7 @@ public:
}; };
ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id); ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive);
ErrorMessage(); ErrorMessage();
/** /**
@ -229,6 +215,7 @@ public:
std::list<FileLocation> _callStack; std::list<FileLocation> _callStack;
Severity::SeverityType _severity; Severity::SeverityType _severity;
std::string _id; std::string _id;
bool _inconclusive;
/** source file (not header) */ /** source file (not header) */
std::string file0; std::string file0;

View File

@ -53,7 +53,8 @@ void Preprocessor::writeError(const std::string &fileName, const unsigned int li
errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
Severity::error, Severity::error,
errorText, errorText,
errorType)); errorType,
false));
} }
static unsigned char readChar(std::istream &istr) static unsigned char readChar(std::istream &istr)
@ -1370,7 +1371,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
if (_errorLogger && _settings && _settings->debugwarnings) if (_errorLogger && _settings && _settings->debugwarnings)
{ {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList; std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug"); const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug", false);
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
} }
@ -1765,7 +1766,8 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, _errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
Severity::error, Severity::error,
msg, msg,
"preprocessorErrorDirective")); "preprocessorErrorDirective",
false));
} }
Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str) Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
@ -1963,7 +1965,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
// currently a debug-message. // currently a debug-message.
const Severity::SeverityType severity = userheader ? Severity::information : Severity::debug; const Severity::SeverityType severity = userheader ? Severity::information : Severity::debug;
const std::string id = userheader ? "missingInclude" : "debug"; const std::string id = userheader ? "missingInclude" : "debug";
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id); ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id, false);
errmsg.file0 = file0; errmsg.file0 = file0;
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
} }

View File

@ -1209,7 +1209,8 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &msg) cons
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug, Severity::debug,
msg, msg,
"debug"); "debug",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
else else

View File

@ -482,7 +482,8 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error, Severity::error,
"Internal error. Token::Match called with varid 0.", "Internal error. Token::Match called with varid 0.",
"cppcheckError"); "cppcheckError",
false);
Check::reportError(errmsg); Check::reportError(errmsg);
} }

View File

@ -489,7 +489,8 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons
Severity::style, Severity::style,
std::string(type + " '" + tok2->str() + std::string(type + " '" + tok2->str() +
"' hides typedef with same name"), "' hides typedef with same name"),
"variableHidingTypedef"); "variableHidingTypedef",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -515,7 +516,8 @@ void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2,
Severity::style, Severity::style,
std::string(type + " '" + tok2->str() + std::string(type + " '" + tok2->str() +
"' forward declaration unnecessary, already declared"), "' forward declaration unnecessary, already declared"),
"unnecessaryForwardDeclaration"); "unnecessaryForwardDeclaration",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -751,7 +753,8 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug, Severity::debug,
"Failed to parse \'" + str.str() + "\'. The checking continues anyway.", "Failed to parse \'" + str.str() + "\'. The checking continues anyway.",
"debug"); "debug",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -2950,7 +2953,8 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug, Severity::debug,
"simplifyTemplates: bailing out", "simplifyTemplates: bailing out",
"debug"); "debug",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -3059,7 +3063,8 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug, Severity::debug,
"Failed to instantiate template. The checking continues anyway.", "Failed to instantiate template. The checking continues anyway.",
"debug"); "debug",
false);
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
} }
@ -6807,7 +6812,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug, Severity::debug,
"simplifyKnownVariables: bailing out (variable="+tok3->str()+", value="+value+")", "simplifyKnownVariables: bailing out (variable="+tok3->str()+", value="+value+")",
"debug"); "debug",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -7698,7 +7704,8 @@ void Tokenizer::duplicateEnumError(const Token * tok1, const Token * tok2, const
Severity::style, Severity::style,
std::string(type + " '" + tok2->str() + std::string(type + " '" + tok2->str() +
"' hides enumerator with same name"), "' hides enumerator with same name"),
"variableHidingEnum"); "variableHidingEnum",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -8337,7 +8344,8 @@ void Tokenizer::syntaxError(const Token *tok)
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error, Severity::error,
"syntax error", "syntax error",
"syntaxError"); "syntaxError",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -8364,7 +8372,8 @@ void Tokenizer::syntaxError(const Token *tok, char c)
"when these macros are defined: '" + "when these macros are defined: '" +
_configuration + _configuration +
"'.", "'.",
"syntaxError"); "syntaxError",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -8386,7 +8395,8 @@ void Tokenizer::cppcheckError(const Token *tok) const
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error, Severity::error,
"Analysis failed. If the code is valid then please report this failure.", "Analysis failed. If the code is valid then please report this failure.",
"cppcheckError"); "cppcheckError",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
@ -9667,7 +9677,8 @@ void Tokenizer::removeUnnecessaryQualification()
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::portability, Severity::portability,
"Extra qualification \'" + tok->str() + "::\' unnecessary and considered an error by many compilers.", "Extra qualification \'" + tok->str() + "::\' unnecessary and considered an error by many compilers.",
"portability"); "portability",
false);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);

View File

@ -67,7 +67,7 @@ private:
loc.line = 5; loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Programming error.", msg.verboseMessage()); ASSERT_EQUALS("Programming error.", msg.verboseMessage());
@ -82,7 +82,7 @@ private:
loc.line = 5; loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
@ -97,7 +97,7 @@ private:
loc.line = 5; loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
@ -112,7 +112,7 @@ private:
loc.line = 5; loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
@ -127,7 +127,7 @@ private:
loc.line = 5; loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1)); ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1)); ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1)); ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
@ -140,7 +140,7 @@ private:
loc.line = 5; loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1)); ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1)); ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1)); ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
@ -153,7 +153,7 @@ private:
loc.line = 5; loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n"); std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
header += " <cppcheck version=\""; header += " <cppcheck version=\"";
header += CppCheck::version(); header += CppCheck::version();
@ -175,8 +175,8 @@ private:
std::list<ErrorLogger::ErrorMessage::FileLocation> locs; std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc); locs.push_back(loc);
// Error message // Inconclusive error message
ErrorMessage msg(locs, Severity::inconclusive_error, "Programming error", "errorId"); ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
// Don't save inconclusive messages if the xml version is 1 // Don't save inconclusive messages if the xml version is 1
ASSERT_EQUALS("", msg.toXML(false, 1)); ASSERT_EQUALS("", msg.toXML(false, 1));