Removed --doc formating hack that removes more than three newlines and added format testing of Check::classInfo instead.
- Fixed test failures shown by new test. Use const_iterator instead of iterator in testcppcheck.cpp when possible
This commit is contained in:
parent
1fbaae948c
commit
046712aaec
|
@ -521,13 +521,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
const std::string info((*it)->classInfo());
|
const std::string info((*it)->classInfo());
|
||||||
if (!name.empty() && !info.empty())
|
if (!name.empty() && !info.empty())
|
||||||
doc << "===" << name << "===\n"
|
doc << "===" << name << "===\n"
|
||||||
<< info << "\n\n";
|
<< info << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string doc2(doc.str());
|
std::cout << doc.str();
|
||||||
while (doc2.find("\n\n\n") != std::string::npos)
|
|
||||||
doc2.erase(doc2.find("\n\n\n"), 1);
|
|
||||||
std::cout << doc2;
|
|
||||||
_exitAfterPrint = true;
|
_exitAfterPrint = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ private:
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "Check if there is 64-bit portability issues:\n"
|
return "Check if there is 64-bit portability issues:\n"
|
||||||
"* assign address to/from int/long\n"
|
"* assign address to/from int/long\n"
|
||||||
"* casting address from/to integer when returning from function";
|
"* casting address from/to integer when returning from function\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -88,7 +88,7 @@ private:
|
||||||
return "Match assignments and conditions:\n"
|
return "Match assignments and conditions:\n"
|
||||||
"* Mismatching assignment and comparison => comparison is always true/false\n"
|
"* Mismatching assignment and comparison => comparison is always true/false\n"
|
||||||
"* Mismatching lhs and rhs in comparison => comparison is always true/false\n"
|
"* Mismatching lhs and rhs in comparison => comparison is always true/false\n"
|
||||||
"* Detect matching 'if' and 'else if' conditions";
|
"* Detect matching 'if' and 'else if' conditions\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -251,7 +251,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "out of bounds checking";
|
return "out of bounds checking\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -117,7 +117,7 @@ private:
|
||||||
"* Throwing exceptions in destructors\n"
|
"* Throwing exceptions in destructors\n"
|
||||||
"* Throwing exception during invalid state\n"
|
"* Throwing exception during invalid state\n"
|
||||||
"* Throwing a copy of a caught exception instead of rethrowing the original exception\n"
|
"* Throwing a copy of a caught exception instead of rethrowing the original exception\n"
|
||||||
"* Exception caught by value instead of by reference";
|
"* Exception caught by value instead of by reference\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -128,7 +128,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "Detect when a auto variable is allocated but not deallocated.";
|
return "Detect when a auto variable is allocated but not deallocated.\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -334,7 +334,7 @@ private:
|
||||||
* @return Wiki formatted information about this class
|
* @return Wiki formatted information about this class
|
||||||
*/
|
*/
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "Is there any allocated memory when a function goes out of scope";
|
return "Is there any allocated memory when a function goes out of scope\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Function names for functions that are "noreturn" */
|
/** Function names for functions that are "noreturn" */
|
||||||
|
@ -387,7 +387,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "If the constructor allocate memory then the destructor must deallocate it.";
|
return "If the constructor allocate memory then the destructor must deallocate it.\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "Don't forget to deallocate struct members";
|
return "Don't forget to deallocate struct members\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -465,7 +465,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "Not taking the address to allocated memory";
|
return "Not taking the address to allocated memory\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -221,7 +221,7 @@ private:
|
||||||
"* redundant condition\n"
|
"* redundant condition\n"
|
||||||
"* common mistakes when using string::c_str()\n"
|
"* common mistakes when using string::c_str()\n"
|
||||||
"* using auto pointer (auto_ptr)\n"
|
"* using auto pointer (auto_ptr)\n"
|
||||||
"* useless calls of string and STL functions";
|
"* useless calls of string and STL functions\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isStlContainer(unsigned int varid);
|
bool isStlContainer(unsigned int varid);
|
||||||
|
|
|
@ -54,12 +54,13 @@ private:
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
TEST_CASE(instancesSorted);
|
TEST_CASE(instancesSorted);
|
||||||
|
TEST_CASE(classInfoFormat);
|
||||||
TEST_CASE(getErrorMessages);
|
TEST_CASE(getErrorMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
void instancesSorted() {
|
void instancesSorted() {
|
||||||
for (std::list<Check *>::iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
|
for (std::list<Check *>::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
|
||||||
std::list<Check *>::iterator j = i;
|
std::list<Check *>::const_iterator j = i;
|
||||||
++j;
|
++j;
|
||||||
if (j != Check::instances().end()) {
|
if (j != Check::instances().end()) {
|
||||||
ASSERT_EQUALS(true, (*i)->name() < (*j)->name());
|
ASSERT_EQUALS(true, (*i)->name() < (*j)->name());
|
||||||
|
@ -67,6 +68,18 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void classInfoFormat() {
|
||||||
|
for (std::list<Check *>::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
|
||||||
|
const std::string info = (*i)->classInfo();
|
||||||
|
if (!info.empty()) {
|
||||||
|
ASSERT('\n' != info[0]); // No \n in the beginning
|
||||||
|
ASSERT('\n' == info[info.length()-1]); // \n at end
|
||||||
|
if (info.size() > 1)
|
||||||
|
ASSERT('\n' != info[info.length()-2]); // Only one \n at end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void getErrorMessages() {
|
void getErrorMessages() {
|
||||||
ErrorLogger2 errorLogger;
|
ErrorLogger2 errorLogger;
|
||||||
CppCheck cppCheck(errorLogger, true);
|
CppCheck cppCheck(errorLogger, true);
|
||||||
|
|
Loading…
Reference in New Issue