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:
PKEuS 2012-08-26 16:22:46 +02:00
parent 1fbaae948c
commit 046712aaec
9 changed files with 27 additions and 17 deletions

View File

@ -521,13 +521,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
const std::string info((*it)->classInfo());
if (!name.empty() && !info.empty())
doc << "===" << name << "===\n"
<< info << "\n\n";
<< info << "\n";
}
std::string doc2(doc.str());
while (doc2.find("\n\n\n") != std::string::npos)
doc2.erase(doc2.find("\n\n\n"), 1);
std::cout << doc2;
std::cout << doc.str();
_exitAfterPrint = true;
return true;
}

View File

@ -82,7 +82,7 @@ private:
std::string classInfo() const {
return "Check if there is 64-bit portability issues:\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";
}
};
/// @}

View File

@ -88,7 +88,7 @@ private:
return "Match assignments and conditions:\n"
"* Mismatching assignment and 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";
}
};
/// @}

View File

@ -251,7 +251,7 @@ private:
}
std::string classInfo() const {
return "out of bounds checking";
return "out of bounds checking\n";
}
};
/// @}

View File

@ -117,7 +117,7 @@ private:
"* Throwing exceptions in destructors\n"
"* Throwing exception during invalid state\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";
}
};
/// @}

View File

@ -128,7 +128,7 @@ private:
}
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";
}
};
/// @}

View File

@ -334,7 +334,7 @@ private:
* @return Wiki formatted information about this class
*/
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" */
@ -387,7 +387,7 @@ private:
}
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 {
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 {
return "Not taking the address to allocated memory";
return "Not taking the address to allocated memory\n";
}
};
/// @}

View File

@ -221,7 +221,7 @@ private:
"* redundant condition\n"
"* common mistakes when using string::c_str()\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);

View File

@ -54,12 +54,13 @@ private:
void run() {
TEST_CASE(instancesSorted);
TEST_CASE(classInfoFormat);
TEST_CASE(getErrorMessages);
}
void instancesSorted() {
for (std::list<Check *>::iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
std::list<Check *>::iterator j = i;
for (std::list<Check *>::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
std::list<Check *>::const_iterator j = i;
++j;
if (j != Check::instances().end()) {
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() {
ErrorLogger2 errorLogger;
CppCheck cppCheck(errorLogger, true);