Improved const correctness of local variables. (#1396)
* Improved const correctness of local variables. * Running astyle [ci-skip]. * Removed duplicate 'const'-keyword.
This commit is contained in:
parent
b6103d15a6
commit
2f032d8fa7
|
@ -325,9 +325,9 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
|||
const Token *lhs = tok1->previous();
|
||||
while (Token::Match(lhs, "(|.|["))
|
||||
lhs = lhs->astOperand1();
|
||||
bool lhsIsConst = (lhs->variable() && lhs->variable()->isConst()) ||
|
||||
(lhs->valueType() && lhs->valueType()->constness > 0) ||
|
||||
(Token::Match(lhs, "%var% . %name% (") && library.isFunctionConst(lhs->tokAt(2)));
|
||||
const bool lhsIsConst = (lhs->variable() && lhs->variable()->isConst()) ||
|
||||
(lhs->valueType() && lhs->valueType()->constness > 0) ||
|
||||
(Token::Match(lhs, "%var% . %name% (") && library.isFunctionConst(lhs->tokAt(2)));
|
||||
if (!lhsIsConst)
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ private:
|
|||
|
||||
void nooptions() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck"};
|
||||
const char * const argv[] = {"cppcheck"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(1, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||
|
@ -161,7 +161,7 @@ private:
|
|||
|
||||
void helpshort() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-h"};
|
||||
const char * const argv[] = {"cppcheck", "-h"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||
|
@ -169,7 +169,7 @@ private:
|
|||
|
||||
void helplong() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--help"};
|
||||
const char * const argv[] = {"cppcheck", "--help"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||
|
@ -177,7 +177,7 @@ private:
|
|||
|
||||
void showversion() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--version"};
|
||||
const char * const argv[] = {"cppcheck", "--version"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowVersion());
|
||||
|
@ -185,7 +185,7 @@ private:
|
|||
|
||||
void onefile() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
||||
|
@ -194,7 +194,7 @@ private:
|
|||
|
||||
void onepath() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "src"};
|
||||
const char * const argv[] = {"cppcheck", "src"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
||||
|
@ -203,7 +203,7 @@ private:
|
|||
|
||||
void optionwithoutfile() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-v"};
|
||||
const char * const argv[] = {"cppcheck", "-v"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(0, (int)parser.getPathNames().size());
|
||||
|
@ -211,7 +211,7 @@ private:
|
|||
|
||||
void verboseshort() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-v", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-v", "file.cpp"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.verbose);
|
||||
|
@ -219,7 +219,7 @@ private:
|
|||
|
||||
void verboselong() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--verbose", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--verbose", "file.cpp"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.verbose);
|
||||
|
@ -227,7 +227,7 @@ private:
|
|||
|
||||
void debugSimplified() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--debug-simplified", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--debug-simplified", "file.cpp"};
|
||||
settings.debugSimplified = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.debugSimplified);
|
||||
|
@ -235,7 +235,7 @@ private:
|
|||
|
||||
void debugwarnings() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--debug-warnings", "file.cpp"};
|
||||
settings.debugwarnings = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.debugwarnings);
|
||||
|
@ -243,7 +243,7 @@ private:
|
|||
|
||||
void forceshort() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-f", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-f", "file.cpp"};
|
||||
settings.force = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.force);
|
||||
|
@ -251,7 +251,7 @@ private:
|
|||
|
||||
void forcelong() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--force", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--force", "file.cpp"};
|
||||
settings.force = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.force);
|
||||
|
@ -261,20 +261,20 @@ private:
|
|||
REDIRECT;
|
||||
settings.relativePaths = false;
|
||||
|
||||
const char *argvs[] = {"cppcheck", "-rp", "file.cpp"};
|
||||
const char * const argvs[] = {"cppcheck", "-rp", "file.cpp"};
|
||||
ASSERT(defParser.parseFromArgs(3, argvs));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
|
||||
settings.relativePaths = false;
|
||||
|
||||
const char *argvl[] = {"cppcheck", "--relative-paths", "file.cpp"};
|
||||
const char * const argvl[] = {"cppcheck", "--relative-paths", "file.cpp"};
|
||||
ASSERT(defParser.parseFromArgs(3, argvl));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
|
||||
settings.relativePaths = false;
|
||||
settings.basePaths.clear();
|
||||
|
||||
const char *argvsp[] = {"cppcheck", "-rp=C:/foo;C:\\bar", "file.cpp"};
|
||||
const char * const argvsp[] = {"cppcheck", "-rp=C:/foo;C:\\bar", "file.cpp"};
|
||||
ASSERT(defParser.parseFromArgs(3, argvsp));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
ASSERT_EQUALS(2, settings.basePaths.size());
|
||||
|
@ -284,7 +284,7 @@ private:
|
|||
settings.relativePaths = false;
|
||||
settings.basePaths.clear();
|
||||
|
||||
const char *argvlp[] = {"cppcheck", "--relative-paths=C:/foo;C:\\bar", "file.cpp"};
|
||||
const char * const argvlp[] = {"cppcheck", "--relative-paths=C:/foo;C:\\bar", "file.cpp"};
|
||||
ASSERT(defParser.parseFromArgs(3, argvlp));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
ASSERT_EQUALS(2, settings.basePaths.size());
|
||||
|
@ -294,7 +294,7 @@ private:
|
|||
|
||||
void quietshort() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-q", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-q", "file.cpp"};
|
||||
settings.quiet = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.quiet);
|
||||
|
@ -302,7 +302,7 @@ private:
|
|||
|
||||
void quietlong() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--quiet", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--quiet", "file.cpp"};
|
||||
settings.quiet = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.quiet);
|
||||
|
@ -310,28 +310,28 @@ private:
|
|||
|
||||
void defines_noarg() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D"};
|
||||
const char * const argv[] = {"cppcheck", "-D"};
|
||||
// Fails since -D has no param
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
|
||||
void defines_noarg2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
|
||||
// Fails since -D has no param
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void defines_noarg3() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
|
||||
// Fails since -D has no param
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void defines() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-D_WIN32", "file.cpp"};
|
||||
settings.userDefines.clear();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS("_WIN32=1", settings.userDefines);
|
||||
|
@ -339,7 +339,7 @@ private:
|
|||
|
||||
void defines2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"};
|
||||
settings.userDefines.clear();;
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
|
||||
|
@ -347,7 +347,7 @@ private:
|
|||
|
||||
void defines3() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"};
|
||||
settings.userDefines.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("DEBUG=1", settings.userDefines);
|
||||
|
@ -355,7 +355,7 @@ private:
|
|||
|
||||
void defines4() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; // #5137 - defining empty macro
|
||||
const char * const argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; // #5137 - defining empty macro
|
||||
settings.userDefines.clear();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS("DEBUG=", settings.userDefines);
|
||||
|
@ -364,53 +364,53 @@ private:
|
|||
void enforceLanguage() {
|
||||
REDIRECT;
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(Settings::None, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "-x", "c++", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-x", "c++", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "-x"};
|
||||
const char * const argv[] = {"cppcheck", "-x"};
|
||||
ASSERT(!defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"};
|
||||
ASSERT(!defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--language=c++", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--language=c++", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--language=c", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--language=c", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::C, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--language=unknownLanguage", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--language=unknownLanguage", "file.cpp"};
|
||||
ASSERT(!defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
}
|
||||
|
||||
void includesnopath() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I"};
|
||||
const char * const argv[] = {"cppcheck", "-I"};
|
||||
// Fails since -I has no param
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
|
||||
void includes() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-I", "include", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
|
@ -418,7 +418,7 @@ private:
|
|||
|
||||
void includesslash() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-I", "include/", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
|
@ -426,7 +426,7 @@ private:
|
|||
|
||||
void includesbackslash() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-I", "include\\", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
|
@ -434,7 +434,7 @@ private:
|
|||
|
||||
void includesnospace() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
|
@ -442,7 +442,7 @@ private:
|
|||
|
||||
void includes2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.parseFromArgs(6, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
|
@ -466,7 +466,7 @@ private:
|
|||
|
||||
void enabledAll() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=all", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::STYLE));
|
||||
|
@ -478,7 +478,7 @@ private:
|
|||
|
||||
void enabledStyle() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=style", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::STYLE));
|
||||
|
@ -491,7 +491,7 @@ private:
|
|||
|
||||
void enabledPerformance() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=performance", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(!settings.isEnabled(Settings::STYLE));
|
||||
|
@ -504,7 +504,7 @@ private:
|
|||
|
||||
void enabledPortability() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=portability", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(!settings.isEnabled(Settings::STYLE));
|
||||
|
@ -517,7 +517,7 @@ private:
|
|||
|
||||
void enabledUnusedFunction() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::UNUSED_FUNCTION));
|
||||
|
@ -525,7 +525,7 @@ private:
|
|||
|
||||
void enabledMissingInclude() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::MISSING_INCLUDE));
|
||||
|
@ -534,7 +534,7 @@ private:
|
|||
#ifdef CHECK_INTERNAL
|
||||
void enabledInternal() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=internal", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::INTERNAL));
|
||||
|
@ -543,7 +543,7 @@ private:
|
|||
|
||||
void enabledMultiple() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=missingInclude,portability,warning", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--enable=missingInclude,portability,warning", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(!settings.isEnabled(Settings::STYLE));
|
||||
|
@ -556,7 +556,7 @@ private:
|
|||
|
||||
void inconclusive() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--inconclusive"};
|
||||
const char * const argv[] = {"cppcheck", "--inconclusive"};
|
||||
settings.inconclusive = false;
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, settings.inconclusive);
|
||||
|
@ -564,7 +564,7 @@ private:
|
|||
|
||||
void errorExitcode() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(5, settings.exitCode);
|
||||
|
@ -572,7 +572,7 @@ private:
|
|||
|
||||
void errorExitcodeMissing() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
// Fails since exit code not given
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
|
@ -580,7 +580,7 @@ private:
|
|||
|
||||
void errorExitcodeStr() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
// Fails since invalid exit code
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
|
@ -589,7 +589,7 @@ private:
|
|||
void exitcodeSuppressionsOld() {
|
||||
// TODO: Fails since cannot open the file
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
@ -597,7 +597,7 @@ private:
|
|||
void exitcodeSuppressions() {
|
||||
// TODO: Fails since cannot open the file
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
@ -605,7 +605,7 @@ private:
|
|||
void exitcodeSuppressionsNoFile() {
|
||||
// TODO: Fails since cannot open the file
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
@ -613,7 +613,7 @@ private:
|
|||
void fileList() {
|
||||
// TODO: Fails since cannot open the file
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"};
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
|
@ -621,19 +621,19 @@ private:
|
|||
// TODO: Give it some stdin to read from, fails because the list of
|
||||
// files in stdin (_pathnames) is empty
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--file-list=-", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--file-list=-", "file.cpp"};
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
} */
|
||||
|
||||
void inlineSuppr() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--inline-suppr", "file.cpp"};
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void jobs() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-j", "3", "file.cpp"};
|
||||
settings.jobs = 0;
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(3, settings.jobs);
|
||||
|
@ -641,7 +641,7 @@ private:
|
|||
|
||||
void jobsMissingCount() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-j", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-j", "file.cpp"};
|
||||
settings.jobs = 0;
|
||||
// Fails since -j is missing thread count
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
|
@ -649,7 +649,7 @@ private:
|
|||
|
||||
void jobsInvalid() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-j", "e", "file.cpp"};
|
||||
settings.jobs = 0;
|
||||
// Fails since invalid count given for -j
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
|
@ -657,7 +657,7 @@ private:
|
|||
|
||||
void maxConfigs() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"};
|
||||
settings.force = false;
|
||||
settings.maxConfigs = 12;
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
|
@ -667,28 +667,28 @@ private:
|
|||
|
||||
void maxConfigsMissingCount() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--max-configs=", "file.cpp"};
|
||||
// Fails since --max-configs= is missing limit
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void maxConfigsInvalid() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--max-configs=e", "file.cpp"};
|
||||
// Fails since invalid count given for --max-configs=
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void maxConfigsTooSmall() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--max-configs=0", "file.cpp"};
|
||||
// Fails since limit must be greater than 0
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void reportProgressTest() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--report-progress", "file.cpp"};
|
||||
settings.reportProgress = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.reportProgress);
|
||||
|
@ -696,7 +696,7 @@ private:
|
|||
|
||||
void stdposix() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--std=posix", "file.cpp"};
|
||||
settings.standards.posix = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.standards.posix);
|
||||
|
@ -704,7 +704,7 @@ private:
|
|||
|
||||
void stdc99() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--std=c99", "file.cpp"};
|
||||
settings.standards.c = Standards::C89;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.standards.c == Standards::C99);
|
||||
|
@ -712,7 +712,7 @@ private:
|
|||
|
||||
void stdcpp11() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--std=c++11", "file.cpp"};
|
||||
settings.standards.cpp = Standards::CPP03;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.standards.cpp == Standards::CPP11);
|
||||
|
@ -720,7 +720,7 @@ private:
|
|||
|
||||
void platform() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--platform=win64", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--platform=win64", "file.cpp"};
|
||||
settings.platform(Settings::Unspecified);
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.platformType == Settings::Win64);
|
||||
|
@ -729,14 +729,14 @@ private:
|
|||
void suppressionsOld() {
|
||||
// TODO: Fails because there is no suppr.txt file!
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions", "suppr.txt", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppressions", "suppr.txt", "file.cpp"};
|
||||
ASSERT(!defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void suppressions() {
|
||||
// TODO: Fails because there is no suppr.txt file!
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"};
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
|
@ -744,21 +744,21 @@ private:
|
|||
REDIRECT;
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"};
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"};
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ private:
|
|||
|
||||
void suppressionSingle() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1)));
|
||||
|
@ -782,7 +782,7 @@ private:
|
|||
|
||||
void suppressionSingleFile() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
|
||||
|
@ -790,7 +790,7 @@ private:
|
|||
|
||||
void suppressionTwo() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar,noConstructor", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppress=uninitvar,noConstructor", "file.cpp"};
|
||||
settings = Settings();
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
|
||||
|
@ -799,7 +799,7 @@ private:
|
|||
|
||||
void suppressionTwoSeparate() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=noConstructor", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=noConstructor", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
|
||||
|
@ -808,7 +808,7 @@ private:
|
|||
|
||||
void templates() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "file.cpp"};
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings.templateFormat);
|
||||
|
@ -816,7 +816,7 @@ private:
|
|||
|
||||
void templatesGcc() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\\n{code}", settings.templateFormat);
|
||||
|
@ -824,7 +824,7 @@ private:
|
|||
|
||||
void templatesVs() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings.templateFormat);
|
||||
|
@ -832,7 +832,7 @@ private:
|
|||
|
||||
void templatesEdit() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings.templateFormat);
|
||||
|
@ -840,7 +840,7 @@ private:
|
|||
|
||||
void xml() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--xml", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
|
@ -850,7 +850,7 @@ private:
|
|||
|
||||
void xmlver2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--xml-version=2", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
|
@ -860,7 +860,7 @@ private:
|
|||
|
||||
void xmlver2both() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
|
@ -870,7 +870,7 @@ private:
|
|||
|
||||
void xmlver2both2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
|
@ -880,28 +880,28 @@ private:
|
|||
|
||||
void xmlverunknown() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"};
|
||||
// FAils since unknown XML format version
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void xmlverinvalid() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"};
|
||||
// FAils since unknown XML format version
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void doc() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--doc"};
|
||||
const char * const argv[] = {"cppcheck", "--doc"};
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT(defParser.exitAfterPrinting());
|
||||
}
|
||||
|
||||
void showtime() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--showtime=summary"};
|
||||
const char * const argv[] = {"cppcheck", "--showtime=summary"};
|
||||
settings.showtime = SHOWTIME_NONE;
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT(settings.showtime == SHOWTIME_SUMMARY);
|
||||
|
@ -909,14 +909,14 @@ private:
|
|||
|
||||
void errorlist1() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--errorlist"};
|
||||
const char * const argv[] = {"cppcheck", "--errorlist"};
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT(defParser.getShowErrorMessages());
|
||||
}
|
||||
|
||||
void errorlistverbose1() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--verbose", "--errorlist"};
|
||||
const char * const argv[] = {"cppcheck", "--verbose", "--errorlist"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.verbose);
|
||||
|
@ -924,7 +924,7 @@ private:
|
|||
|
||||
void errorlistverbose2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--errorlist", "--verbose"};
|
||||
const char * const argv[] = {"cppcheck", "--errorlist", "--verbose"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.verbose);
|
||||
|
@ -932,7 +932,7 @@ private:
|
|||
|
||||
void ignorepathsnopath() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-i"};
|
||||
const char * const argv[] = {"cppcheck", "-i"};
|
||||
CmdLineParser parser(&settings);
|
||||
// Fails since no ignored path given
|
||||
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
||||
|
@ -942,7 +942,7 @@ private:
|
|||
/*
|
||||
void ignorepaths1() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-isrc", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
|
@ -951,7 +951,7 @@ private:
|
|||
|
||||
void ignorepaths2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-i", "src", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
|
@ -960,7 +960,7 @@ private:
|
|||
|
||||
void ignorepaths3() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
||||
|
@ -970,7 +970,7 @@ private:
|
|||
*/
|
||||
void ignorepaths4() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(6, argv));
|
||||
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
||||
|
@ -980,7 +980,7 @@ private:
|
|||
/*
|
||||
void ignorefilepaths1() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
|
@ -989,7 +989,7 @@ private:
|
|||
*/
|
||||
void ignorefilepaths2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
|
@ -998,7 +998,7 @@ private:
|
|||
|
||||
void checkconfig() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--check-config", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--check-config", "file.cpp"};
|
||||
settings.checkConfiguration = false;
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.checkConfiguration);
|
||||
|
@ -1006,13 +1006,13 @@ private:
|
|||
|
||||
void unknownParam() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--foo", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "--foo", "file.cpp"};
|
||||
ASSERT(!defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void undefs() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-U_WIN32", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, settings.userUndefs.size());
|
||||
|
@ -1021,7 +1021,7 @@ private:
|
|||
|
||||
void undefs2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(2, settings.userUndefs.size());
|
||||
|
@ -1031,21 +1031,21 @@ private:
|
|||
|
||||
void undefs_noarg() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U"};
|
||||
const char * const argv[] = {"cppcheck", "-U"};
|
||||
// Fails since -U has no param
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
|
||||
void undefs_noarg2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-U", "-v", "file.cpp"};
|
||||
// Fails since -U has no param
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void undefs_noarg3() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"};
|
||||
const char * const argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"};
|
||||
// Fails since -U has no param
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
|
|
@ -1088,7 +1088,7 @@ private:
|
|||
void incdec() const {
|
||||
// increment
|
||||
{
|
||||
MathLib::biguint num = ~10U;
|
||||
const MathLib::biguint num = ~10U;
|
||||
const std::string op = "++";
|
||||
const std::string strNum = MathLib::incdec(MathLib::toString(num), op);
|
||||
const MathLib::biguint incrementedNum = MathLib::toULongNumber(strNum);
|
||||
|
@ -1096,7 +1096,7 @@ private:
|
|||
}
|
||||
// decrement
|
||||
{
|
||||
MathLib::biguint num = ~10U;
|
||||
const MathLib::biguint num = ~10U;
|
||||
const std::string op = "--";
|
||||
const std::string strNum = MathLib::incdec(MathLib::toString(num), op);
|
||||
const MathLib::biguint decrementedNum = MathLib::toULongNumber(strNum);
|
||||
|
|
|
@ -56,7 +56,7 @@ private:
|
|||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
CheckMemoryLeak c(&tokenizer, this, &settings);
|
||||
const CheckMemoryLeak c(&tokenizer, this, &settings);
|
||||
|
||||
return c.functionReturnType(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front());
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ private:
|
|||
|
||||
// there is no allocation
|
||||
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "ret =");
|
||||
CheckMemoryLeak check(&tokenizer, 0, &settings);
|
||||
const CheckMemoryLeak check(&tokenizer, 0, &settings);
|
||||
ASSERT_EQUALS(CheckMemoryLeak::No, check.getAllocationType(tok->tokAt(2), 1));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
options args(argc, const_cast<const char**>(argv));
|
||||
|
||||
std::size_t failedTestsCount = TestFixture::runTests(args);
|
||||
const std::size_t failedTestsCount = TestFixture::runTests(args);
|
||||
return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
#ifdef NDEBUG
|
||||
} catch (const InternalError& e) {
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
CLEAR_REDIRECT_ERROUT;
|
||||
char* path = new char[i->first.size() + 1];
|
||||
strcpy(path, i->first.c_str());
|
||||
const char* argv[] = {
|
||||
const char * const argv[] = {
|
||||
#ifdef _WIN32
|
||||
".\\..\\testrunner",
|
||||
#else
|
||||
|
|
|
@ -103,7 +103,7 @@ extern std::ostringstream output;
|
|||
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
|
||||
#define ASSERT_NO_THROW( CMD ) try { CMD ; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); }
|
||||
#define TODO_ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; } catch (const EXCEPTION&) { } catch (...) { assertThrow(__FILE__, __LINE__); }
|
||||
#define TODO_ASSERT( CONDITION ) { bool condition=CONDITION; todoAssertEquals(__FILE__, __LINE__, true, false, condition); }
|
||||
#define TODO_ASSERT( CONDITION ) { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); }
|
||||
#define TODO_ASSERT_EQUALS( WANTED , CURRENT , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL)
|
||||
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_##CLASSNAME; }
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ private:
|
|||
for (std::map<std::string, std::size_t>::const_iterator i = files.begin(); i != files.end(); ++i)
|
||||
executor.addFileContent(i->first, code);
|
||||
|
||||
unsigned int exitCode = executor.check();
|
||||
const unsigned int exitCode = executor.check();
|
||||
|
||||
std::map<std::string, std::string> files_for_report;
|
||||
for (std::map<std::string, std::size_t>::const_iterator file = files.begin(); file != files.end(); ++file)
|
||||
|
|
|
@ -408,7 +408,7 @@ private:
|
|||
|
||||
void test_isVariableDeclarationCanHandleNull() {
|
||||
reset();
|
||||
bool result = nullScope.isVariableDeclaration(nullptr, vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(nullptr, vartok, typetok);
|
||||
ASSERT_EQUALS(false, result);
|
||||
ASSERT(nullptr == vartok);
|
||||
ASSERT(nullptr == typetok);
|
||||
|
@ -418,7 +418,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesSimpleDeclaration() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize simpleDeclaration("int x;");
|
||||
bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("x", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -431,7 +431,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesInitialization() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize simpleDeclaration("int x (1);");
|
||||
bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("x", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -444,7 +444,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesCpp11Initialization() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize simpleDeclaration("int x {1};");
|
||||
bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("x", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -457,7 +457,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesScopedDeclaration() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize ScopedDeclaration("::int x;");
|
||||
bool result = nullScope.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("x", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -470,7 +470,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesStdDeclaration() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize StdDeclaration("std::string x;");
|
||||
bool result = nullScope.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("x", vartok->str());
|
||||
ASSERT_EQUALS("string", typetok->str());
|
||||
|
@ -483,7 +483,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesScopedStdDeclaration() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize StdDeclaration("::std::string x;");
|
||||
bool result = nullScope.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("x", vartok->str());
|
||||
ASSERT_EQUALS("string", typetok->str());
|
||||
|
@ -496,7 +496,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesManyScopes() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE x;");
|
||||
bool result = nullScope.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("x", vartok->str());
|
||||
ASSERT_EQUALS("EE", typetok->str());
|
||||
|
@ -509,7 +509,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesPointers() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize pointer("int* p;");
|
||||
bool result1 = nullScope.isVariableDeclaration(pointer.tokens(), vartok, typetok);
|
||||
const bool result1 = nullScope.isVariableDeclaration(pointer.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result1);
|
||||
ASSERT_EQUALS("p", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -528,7 +528,7 @@ private:
|
|||
|
||||
reset();
|
||||
givenACodeSampleToTokenize pointerconst("int* const p;");
|
||||
bool result2 = nullScope.isVariableDeclaration(pointerconst.tokens(), vartok, typetok);
|
||||
const bool result2 = nullScope.isVariableDeclaration(pointerconst.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result2);
|
||||
ASSERT_EQUALS("p", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -542,7 +542,7 @@ private:
|
|||
void test_isVariableDeclarationDoesNotIdentifyConstness() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize constness("const int* cp;");
|
||||
bool result = nullScope.isVariableDeclaration(constness.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(constness.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(false, result);
|
||||
ASSERT(nullptr == vartok);
|
||||
ASSERT(nullptr == typetok);
|
||||
|
@ -551,7 +551,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesFirstOfManyVariables() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize multipleDeclaration("int first, second;");
|
||||
bool result = nullScope.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("first", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -564,7 +564,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesScopedPointerDeclaration() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE* p;");
|
||||
bool result = nullScope.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("p", vartok->str());
|
||||
ASSERT_EQUALS("EE", typetok->str());
|
||||
|
@ -577,7 +577,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesDeclarationWithIndirection() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize pointerToPointer("int** pp;");
|
||||
bool result = nullScope.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("pp", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -590,7 +590,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize pointerToPointer("int***** p;");
|
||||
bool result = nullScope.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("p", vartok->str());
|
||||
ASSERT_EQUALS("int", typetok->str());
|
||||
|
@ -603,7 +603,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesArray() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize arr("::std::string v[3];");
|
||||
bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("v", vartok->str());
|
||||
ASSERT_EQUALS("string", typetok->str());
|
||||
|
@ -617,7 +617,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesPointerArray() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize arr("A *a[5];");
|
||||
bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("a", vartok->str());
|
||||
ASSERT_EQUALS("A", typetok->str());
|
||||
|
@ -632,7 +632,7 @@ private:
|
|||
void test_isVariableDeclarationIdentifiesOfArrayPointers() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize arr("A (*a)[5];");
|
||||
bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(arr.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("a", vartok->str());
|
||||
ASSERT_EQUALS("A", typetok->str());
|
||||
|
@ -647,7 +647,7 @@ private:
|
|||
void isVariableDeclarationIdentifiesTemplatedPointerVariable() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("std::set<char>* chars;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("chars", vartok->str());
|
||||
ASSERT_EQUALS("set", typetok->str());
|
||||
|
@ -660,7 +660,7 @@ private:
|
|||
void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("std::deque<int>*** ints;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("ints", vartok->str());
|
||||
ASSERT_EQUALS("deque", typetok->str());
|
||||
|
@ -673,7 +673,7 @@ private:
|
|||
void isVariableDeclarationIdentifiesTemplatedArrayVariable() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("std::deque<int> ints[3];");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("ints", vartok->str());
|
||||
ASSERT_EQUALS("deque", typetok->str());
|
||||
|
@ -686,7 +686,7 @@ private:
|
|||
void isVariableDeclarationIdentifiesTemplatedVariable() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("std::vector<int> ints;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("ints", vartok->str());
|
||||
ASSERT_EQUALS("vector", typetok->str());
|
||||
|
@ -699,7 +699,7 @@ private:
|
|||
void isVariableDeclarationIdentifiesTemplatedVariableIterator() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("std::list<int>::const_iterator floats;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("floats", vartok->str());
|
||||
ASSERT_EQUALS("const_iterator", typetok->str());
|
||||
|
@ -712,7 +712,7 @@ private:
|
|||
void isVariableDeclarationIdentifiesNestedTemplateVariable() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
ASSERT_EQUALS("intsets", vartok->str());
|
||||
ASSERT_EQUALS("deque", typetok->str());
|
||||
|
@ -725,7 +725,7 @@ private:
|
|||
void isVariableDeclarationIdentifiesReference() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var1("int& foo;");
|
||||
bool result1 = nullScope.isVariableDeclaration(var1.tokens(), vartok, typetok);
|
||||
const bool result1 = nullScope.isVariableDeclaration(var1.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result1);
|
||||
Variable v1(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
|
||||
ASSERT(false == v1.isArray());
|
||||
|
@ -734,7 +734,7 @@ private:
|
|||
|
||||
reset();
|
||||
givenACodeSampleToTokenize var2("foo*& bar;");
|
||||
bool result2 = nullScope.isVariableDeclaration(var2.tokens(), vartok, typetok);
|
||||
const bool result2 = nullScope.isVariableDeclaration(var2.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result2);
|
||||
Variable v2(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
|
||||
ASSERT(false == v2.isArray());
|
||||
|
@ -743,7 +743,7 @@ private:
|
|||
|
||||
reset();
|
||||
givenACodeSampleToTokenize var3("std::vector<int>& foo;");
|
||||
bool result3 = nullScope.isVariableDeclaration(var3.tokens(), vartok, typetok);
|
||||
const bool result3 = nullScope.isVariableDeclaration(var3.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result3);
|
||||
Variable v3(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
|
||||
ASSERT(false == v3.isArray());
|
||||
|
@ -754,21 +754,21 @@ private:
|
|||
void isVariableDeclarationDoesNotIdentifyTemplateClass() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("template <class T> class SomeClass{};");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(false, result);
|
||||
}
|
||||
|
||||
void isVariableDeclarationDoesNotIdentifyCppCast() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("reinterpret_cast <char *> (code)[0] = 0;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(false, result);
|
||||
}
|
||||
|
||||
void isVariableDeclarationPointerConst() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("std::string const* s;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens()->next(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens()->next(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
|
||||
ASSERT(false == v.isArray());
|
||||
|
@ -779,7 +779,7 @@ private:
|
|||
void isVariableDeclarationRValueRef() {
|
||||
reset();
|
||||
givenACodeSampleToTokenize var("int&& i;");
|
||||
bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0, &settings1);
|
||||
ASSERT(false == v.isArray());
|
||||
|
@ -913,7 +913,7 @@ private:
|
|||
std::istringstream code("std::string s;");
|
||||
TokenList list(nullptr);
|
||||
list.createTokens(code, "test.cpp");
|
||||
bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
Variable v(vartok, list.front(), list.back(), 0, Public, 0, 0, &settings1);
|
||||
static const std::set<std::string> types = { "string", "wstring" };
|
||||
|
@ -929,7 +929,7 @@ private:
|
|||
TokenList list(nullptr);
|
||||
list.createTokens(code, "test.cpp");
|
||||
list.front()->tokAt(3)->link(list.front()->tokAt(5));
|
||||
bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
Variable v(vartok, list.front(), list.back(), 0, Public, 0, 0, &settings1);
|
||||
static const std::set<std::string> types = { "bitset", "set", "vector", "wstring" };
|
||||
|
@ -944,7 +944,7 @@ private:
|
|||
std::istringstream code("SomeClass s;");
|
||||
TokenList list(nullptr);
|
||||
list.createTokens(code, "test.cpp");
|
||||
bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
|
||||
const bool result = nullScope.isVariableDeclaration(list.front(), vartok, typetok);
|
||||
ASSERT_EQUALS(true, result);
|
||||
Variable v(vartok, list.front(), list.back(), 0, Public, 0, 0, &settings1);
|
||||
static const std::set<std::string> types = { "bitset", "set", "vector" };
|
||||
|
@ -4439,7 +4439,7 @@ private:
|
|||
const Scope * bar = db->findScopeByName("bar");
|
||||
ASSERT(bar != nullptr);
|
||||
if (bar) {
|
||||
unsigned int linenrs[] = { 2, 1 };
|
||||
const unsigned int linenrs[2] = { 2, 1 };
|
||||
unsigned int index = 0;
|
||||
for (const Token * tok = bar->bodyStart->next(); tok != bar->bodyEnd; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%name% (") && !tok->varId() && Token::simpleMatch(tok->linkAt(1), ") ;")) {
|
||||
|
@ -6612,7 +6612,7 @@ private:
|
|||
}
|
||||
|
||||
void using1() {
|
||||
Standards::cppstd_t original_std = settings1.standards.cpp;
|
||||
const Standards::cppstd_t original_std = settings1.standards.cpp;
|
||||
settings1.standards.cpp = Standards::CPP11;
|
||||
GET_SYMBOL_DB("using INT = int;\n"
|
||||
"using PINT = INT *;\n"
|
||||
|
@ -6656,7 +6656,7 @@ private:
|
|||
}
|
||||
|
||||
void using2() { // #8331 (segmentation fault)
|
||||
Standards::cppstd_t original_std = settings1.standards.cpp;
|
||||
const Standards::cppstd_t original_std = settings1.standards.cpp;
|
||||
settings1.standards.cpp = Standards::CPP11;
|
||||
|
||||
{
|
||||
|
@ -6686,7 +6686,7 @@ private:
|
|||
}
|
||||
|
||||
void using3() { // #8343 (segmentation fault)
|
||||
Standards::cppstd_t original_std = settings1.standards.cpp;
|
||||
const Standards::cppstd_t original_std = settings1.standards.cpp;
|
||||
settings1.standards.cpp = Standards::CPP11;
|
||||
GET_SYMBOL_DB("template <typename T>\n"
|
||||
"using vector = typename MemoryModel::template vector<T>;\n"
|
||||
|
|
|
@ -321,7 +321,7 @@ private:
|
|||
|
||||
void deleteLast() const {
|
||||
TokensFrontBack listEnds{ 0 };
|
||||
Token **tokensBack = &(listEnds.back);
|
||||
Token ** const tokensBack = &(listEnds.back);
|
||||
Token tok(&listEnds);
|
||||
tok.insertToken("aba");
|
||||
ASSERT_EQUALS(true, *tokensBack == tok.next());
|
||||
|
@ -331,7 +331,7 @@ private:
|
|||
|
||||
void deleteFirst() const {
|
||||
TokensFrontBack listEnds{ 0 };
|
||||
Token **tokensFront = &(listEnds.front);
|
||||
Token ** const tokensFront = &(listEnds.front);
|
||||
Token tok(&listEnds);
|
||||
|
||||
tok.insertToken("aba");
|
||||
|
@ -886,14 +886,14 @@ private:
|
|||
void canFindMatchingBracketsNeedsOpen() const {
|
||||
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
||||
|
||||
const Token* t = var.tokens()->findClosingBracket();
|
||||
const Token* const t = var.tokens()->findClosingBracket();
|
||||
ASSERT(t == nullptr);
|
||||
}
|
||||
|
||||
void canFindMatchingBracketsInnerPair() const {
|
||||
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
||||
|
||||
Token* t = const_cast<Token*>(var.tokens()->tokAt(7))->findClosingBracket();
|
||||
const Token * const t = const_cast<Token*>(var.tokens()->tokAt(7))->findClosingBracket();
|
||||
ASSERT_EQUALS(">", t->str());
|
||||
ASSERT(var.tokens()->tokAt(9) == t);
|
||||
}
|
||||
|
@ -901,7 +901,7 @@ private:
|
|||
void canFindMatchingBracketsOuterPair() const {
|
||||
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
||||
|
||||
const Token* t = var.tokens()->tokAt(3)->findClosingBracket();
|
||||
const Token* const t = var.tokens()->tokAt(3)->findClosingBracket();
|
||||
ASSERT_EQUALS(">", t->str());
|
||||
ASSERT(var.tokens()->tokAt(10) == t);
|
||||
}
|
||||
|
@ -909,7 +909,7 @@ private:
|
|||
void canFindMatchingBracketsWithTooManyClosing() const {
|
||||
givenACodeSampleToTokenize var("X< 1>2 > x1;\n");
|
||||
|
||||
const Token* t = var.tokens()->next()->findClosingBracket();
|
||||
const Token* const t = var.tokens()->next()->findClosingBracket();
|
||||
ASSERT_EQUALS(">", t->str());
|
||||
ASSERT(var.tokens()->tokAt(3) == t);
|
||||
}
|
||||
|
@ -927,17 +927,17 @@ private:
|
|||
void findClosingBracket() {
|
||||
givenACodeSampleToTokenize var("template<typename X, typename...Y> struct S : public Fred<Wilma<Y...>> {}");
|
||||
|
||||
const Token* t = var.tokens()->next()->findClosingBracket();
|
||||
const Token* const t = var.tokens()->next()->findClosingBracket();
|
||||
ASSERT(Token::simpleMatch(t, "> struct"));
|
||||
}
|
||||
|
||||
void expressionString() {
|
||||
givenACodeSampleToTokenize var1("void f() { *((unsigned long long *)x) = 0; }");
|
||||
const Token *tok1 = Token::findsimplematch(var1.tokens(), "*");
|
||||
const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*");
|
||||
ASSERT_EQUALS("*((unsigned long long*)x)", tok1->expressionString());
|
||||
|
||||
givenACodeSampleToTokenize var2("typedef unsigned long long u64; void f() { *((u64 *)x) = 0; }");
|
||||
const Token *tok2 = Token::findsimplematch(var2.tokens(), "*");
|
||||
const Token *const tok2 = Token::findsimplematch(var2.tokens(), "*");
|
||||
ASSERT_EQUALS("*((unsigned long long*)x)", tok2->expressionString());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -272,8 +272,8 @@ private:
|
|||
// This function ensure that test works with different compilers. Floats can
|
||||
// be stringified differently.
|
||||
static std::string removeFloat(const std::string& msg) {
|
||||
std::string::size_type pos1 = msg.find("float (");
|
||||
std::string::size_type pos2 = msg.find(") to integer conversion");
|
||||
const std::string::size_type pos1 = msg.find("float (");
|
||||
const std::string::size_type pos2 = msg.find(") to integer conversion");
|
||||
if (pos1 == std::string::npos || pos2 == std::string::npos || pos1 > pos2)
|
||||
return msg;
|
||||
return msg.substr(0,pos1+7) + msg.substr(pos2);
|
||||
|
|
Loading…
Reference in New Issue