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