Use global Settings instance in TestCmdlineParser, since most tests just need it to pass something to CmdlineParser class.

This change implies that we do not rely on any default state of the Settings class - as it should be, since CmdlineParser is tested, not Settings.
This commit is contained in:
PKEuS 2013-04-01 04:12:56 -07:00
parent 395a474ec2
commit fbe997ca80
1 changed files with 69 additions and 101 deletions

View File

@ -27,6 +27,7 @@ public:
{ } { }
private: private:
Settings settings;
void run() { void run() {
TEST_CASE(nooptions); TEST_CASE(nooptions);
@ -135,7 +136,6 @@ private:
void nooptions() { void nooptions() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck"}; const char *argv[] = {"cppcheck"};
Settings settings;
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());
@ -144,7 +144,6 @@ private:
void helpshort() { void helpshort() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-h"}; const char *argv[] = {"cppcheck", "-h"};
Settings settings;
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());
@ -153,7 +152,6 @@ private:
void helplong() { void helplong() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--help"}; const char *argv[] = {"cppcheck", "--help"};
Settings settings;
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());
@ -162,7 +160,6 @@ private:
void showversion() { void showversion() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--version"}; const char *argv[] = {"cppcheck", "--version"};
Settings settings;
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());
@ -171,7 +168,6 @@ private:
void onefile() { void onefile() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "file.cpp"}; const char *argv[] = {"cppcheck", "file.cpp"};
Settings settings;
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());
@ -181,7 +177,6 @@ private:
void onepath() { void onepath() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "src"}; const char *argv[] = {"cppcheck", "src"};
Settings settings;
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());
@ -191,7 +186,6 @@ private:
void optionwithoutfile() { void optionwithoutfile() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-v"}; const char *argv[] = {"cppcheck", "-v"};
Settings settings;
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());
@ -200,7 +194,7 @@ private:
void verboseshort() { void verboseshort() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-v", "file.cpp"};
Settings settings; settings._verbose = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._verbose); ASSERT_EQUALS(true, settings._verbose);
@ -209,7 +203,7 @@ private:
void verboselong() { void verboselong() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "file.cpp"}; const char *argv[] = {"cppcheck", "--verbose", "file.cpp"};
Settings settings; settings._verbose = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._verbose); ASSERT_EQUALS(true, settings._verbose);
@ -218,7 +212,7 @@ private:
void debug() { void debug() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--debug", "file.cpp"}; const char *argv[] = {"cppcheck", "--debug", "file.cpp"};
Settings settings; settings.debug = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debug); ASSERT_EQUALS(true, settings.debug);
@ -227,7 +221,7 @@ private:
void debugwarnings() { void debugwarnings() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"}; const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"};
Settings settings; settings.debugwarnings = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debugwarnings); ASSERT_EQUALS(true, settings.debugwarnings);
@ -236,7 +230,7 @@ private:
void forceshort() { void forceshort() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-f", "file.cpp"}; const char *argv[] = {"cppcheck", "-f", "file.cpp"};
Settings settings; settings._force = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._force); ASSERT_EQUALS(true, settings._force);
@ -245,7 +239,7 @@ private:
void forcelong() { void forcelong() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--force", "file.cpp"}; const char *argv[] = {"cppcheck", "--force", "file.cpp"};
Settings settings; settings._force = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._force); ASSERT_EQUALS(true, settings._force);
@ -253,8 +247,8 @@ private:
void relativePaths() { void relativePaths() {
REDIRECT; REDIRECT;
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
settings._relativePaths = false;
const char *argvs[] = {"cppcheck", "-rp", "file.cpp"}; const char *argvs[] = {"cppcheck", "-rp", "file.cpp"};
ASSERT(parser.ParseFromArgs(3, argvs)); ASSERT(parser.ParseFromArgs(3, argvs));
@ -290,7 +284,7 @@ private:
void quietshort() { void quietshort() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-q", "file.cpp"}; const char *argv[] = {"cppcheck", "-q", "file.cpp"};
Settings settings; settings._errorsOnly = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._errorsOnly); ASSERT_EQUALS(true, settings._errorsOnly);
@ -299,7 +293,7 @@ private:
void quietlong() { void quietlong() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "--quiet", "file.cpp"};
Settings settings; settings._errorsOnly = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._errorsOnly); ASSERT_EQUALS(true, settings._errorsOnly);
@ -308,7 +302,6 @@ private:
void defines_noarg() { void defines_noarg() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D"}; const char *argv[] = {"cppcheck", "-D"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -D has no param // Fails since -D has no param
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
@ -317,7 +310,6 @@ private:
void defines_noarg2() { void defines_noarg2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -D has no param // Fails since -D has no param
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
@ -326,7 +318,6 @@ private:
void defines_noarg3() { void defines_noarg3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -D has no param // Fails since -D has no param
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
@ -335,7 +326,7 @@ private:
void defines() { void defines() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"}; const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"};
Settings settings; settings.userDefines.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("_WIN32=1", settings.userDefines); ASSERT_EQUALS("_WIN32=1", settings.userDefines);
@ -344,7 +335,7 @@ private:
void defines2() { void defines2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"}; const char *argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"};
Settings settings; settings.userDefines.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines); ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
@ -353,7 +344,7 @@ private:
void defines3() { void defines3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"};
Settings settings; settings.userDefines.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("DEBUG=1", settings.userDefines); ASSERT_EQUALS("DEBUG=1", settings.userDefines);
@ -362,7 +353,7 @@ private:
void defines4() { void defines4() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"};
Settings settings; settings.userDefines.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("DEBUG", settings.userDefines); ASSERT_EQUALS("DEBUG", settings.userDefines);
@ -372,47 +363,44 @@ private:
REDIRECT; REDIRECT;
{ {
const char *argv[] = {"cppcheck", "file.cpp"}; const char *argv[] = {"cppcheck", "file.cpp"};
Settings settings; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.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 *argv[] = {"cppcheck", "-x", "c++", "file.cpp"};
Settings settings; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang); ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
} }
{ {
const char *argv[] = {"cppcheck", "-x"}; const char *argv[] = {"cppcheck", "-x"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(!parser.ParseFromArgs(2, argv)); ASSERT(!parser.ParseFromArgs(2, argv));
} }
{ {
const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"}; const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(!parser.ParseFromArgs(4, argv)); ASSERT(!parser.ParseFromArgs(4, argv));
} }
{ {
const char *argv[] = {"cppcheck", "--language=c++", "file.cpp"}; const char *argv[] = {"cppcheck", "--language=c++", "file.cpp"};
Settings settings; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.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 *argv[] = {"cppcheck", "--language=c", "file.cpp"};
Settings settings; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.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 *argv[] = {"cppcheck", "--language=unknownLanguage", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(!parser.ParseFromArgs(3, argv)); ASSERT(!parser.ParseFromArgs(3, argv));
} }
@ -421,7 +409,6 @@ private:
void includesnopath() { void includesnopath() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -I has no param // Fails since -I has no param
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
@ -430,7 +417,7 @@ private:
void includes() { void includes() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"};
Settings settings; settings._includePaths.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
@ -439,7 +426,7 @@ private:
void includesslash() { void includesslash() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"};
Settings settings; settings._includePaths.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
@ -448,7 +435,7 @@ private:
void includesbackslash() { void includesbackslash() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"};
Settings settings; settings._includePaths.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
@ -457,7 +444,7 @@ private:
void includesnospace() { void includesnospace() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"}; const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
Settings settings; settings._includePaths.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
@ -466,7 +453,7 @@ private:
void includes2() { void includes2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"};
Settings settings; settings._includePaths.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(6, argv)); ASSERT(parser.ParseFromArgs(6, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
@ -478,7 +465,7 @@ private:
// TODO: Fails since cannot open the file // TODO: Fails since cannot open the file
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"}; const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"};
Settings settings; settings._includePaths.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT_EQUALS(true, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(true, parser.ParseFromArgs(3, argv));
} }
@ -486,7 +473,7 @@ private:
void enabledAll() { void enabledAll() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("style")); ASSERT(settings.isEnabled("style"));
@ -498,7 +485,7 @@ private:
void enabledStyle() { void enabledStyle() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("style")); ASSERT(settings.isEnabled("style"));
@ -511,7 +498,7 @@ private:
void enabledPerformance() { void enabledPerformance() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(!settings.isEnabled("style")); ASSERT(!settings.isEnabled("style"));
@ -524,7 +511,7 @@ private:
void enabledPortability() { void enabledPortability() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(!settings.isEnabled("style")); ASSERT(!settings.isEnabled("style"));
@ -537,7 +524,7 @@ private:
void enabledUnusedFunction() { void enabledUnusedFunction() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("unusedFunction")); ASSERT(settings.isEnabled("unusedFunction"));
@ -546,7 +533,7 @@ private:
void enabledMissingInclude() { void enabledMissingInclude() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("missingInclude")); ASSERT(settings.isEnabled("missingInclude"));
@ -556,7 +543,7 @@ private:
void enabledInternal() { void enabledInternal() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("internal")); ASSERT(settings.isEnabled("internal"));
@ -566,7 +553,7 @@ private:
void errorExitcode() { void errorExitcode() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"}; const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"};
Settings settings; settings._exitCode = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(5, settings._exitCode); ASSERT_EQUALS(5, settings._exitCode);
@ -575,7 +562,7 @@ private:
void errorExitcodeMissing() { void errorExitcodeMissing() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"}; const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"};
Settings settings; settings._exitCode = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since exit code not given // Fails since exit code not given
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
@ -584,7 +571,7 @@ private:
void errorExitcodeStr() { void errorExitcodeStr() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"}; const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"};
Settings settings; settings._exitCode = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since invalid exit code // Fails since invalid exit code
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
@ -594,7 +581,7 @@ private:
// 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 *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"};
Settings settings; settings._exitCode = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv));
} }
@ -603,7 +590,7 @@ private:
// 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 *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"};
Settings settings; settings._exitCode = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
@ -612,7 +599,7 @@ private:
// 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 *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"};
Settings settings; settings._exitCode = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
@ -621,7 +608,6 @@ private:
// 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 *argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv));
} }
@ -631,7 +617,6 @@ private:
// files in stdin (_pathnames) is empty // files in stdin (_pathnames) is empty
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--file-list=-", "file.cpp"}; const char *argv[] = {"cppcheck", "--file-list=-", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
@ -639,7 +624,6 @@ private:
void inlineSuppr() { void inlineSuppr() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"}; const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
} }
@ -647,7 +631,7 @@ private:
void jobs() { void jobs() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"};
Settings settings; settings._jobs = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(3, settings._jobs); ASSERT_EQUALS(3, settings._jobs);
@ -656,7 +640,7 @@ private:
void jobsMissingCount() { void jobsMissingCount() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-j", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "file.cpp"};
Settings settings; settings._jobs = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -j is missing thread count // Fails since -j is missing thread count
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
@ -665,7 +649,7 @@ private:
void jobsInvalid() { void jobsInvalid() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"};
Settings settings; settings._jobs = 0;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since invalid count given for -j // Fails since invalid count given for -j
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
@ -674,7 +658,8 @@ private:
void maxConfigs() { void maxConfigs() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"}; const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"};
Settings settings; settings._force = false;
settings._maxConfigs = 12;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(12, settings._maxConfigs); ASSERT_EQUALS(12, settings._maxConfigs);
@ -684,7 +669,6 @@ private:
void maxConfigsMissingCount() { void maxConfigsMissingCount() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since --max-configs= is missing limit // Fails since --max-configs= is missing limit
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
@ -693,7 +677,6 @@ private:
void maxConfigsInvalid() { void maxConfigsInvalid() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since invalid count given for --max-configs= // Fails since invalid count given for --max-configs=
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
@ -702,7 +685,6 @@ private:
void maxConfigsTooSmall() { void maxConfigsTooSmall() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since limit must be greater than 0 // Fails since limit must be greater than 0
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
@ -711,7 +693,7 @@ private:
void reportProgressTest() { void reportProgressTest() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"}; const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"};
Settings settings; settings.reportProgress = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.reportProgress); ASSERT(settings.reportProgress);
@ -720,7 +702,7 @@ private:
void stdposix() { void stdposix() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"}; const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"};
Settings settings; settings.standards.posix = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.standards.posix); ASSERT(settings.standards.posix);
@ -729,7 +711,7 @@ private:
void stdc99() { void stdc99() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"}; const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"};
Settings settings; settings.standards.c = Standards::C89;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.standards.c == Standards::C99); ASSERT(settings.standards.c == Standards::C99);
@ -738,7 +720,7 @@ private:
void stdcpp11() { void stdcpp11() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"}; const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"};
Settings settings; settings.standards.cpp = Standards::CPP03;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.standards.cpp == Standards::CPP11); ASSERT(settings.standards.cpp == Standards::CPP11);
@ -748,7 +730,6 @@ private:
// 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 *argv[] = {"cppcheck", "--suppressions", "suppr.txt", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(!parser.ParseFromArgs(4, argv)); ASSERT(!parser.ParseFromArgs(4, argv));
} }
@ -757,7 +738,6 @@ private:
// 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 *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
@ -767,7 +747,6 @@ private:
{ {
CLEAR_REDIRECT_OUTPUT; CLEAR_REDIRECT_OUTPUT;
const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.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);
@ -776,7 +755,6 @@ private:
{ {
CLEAR_REDIRECT_OUTPUT; CLEAR_REDIRECT_OUTPUT;
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.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);
@ -785,7 +763,6 @@ private:
{ {
CLEAR_REDIRECT_OUTPUT; CLEAR_REDIRECT_OUTPUT;
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, parser.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);
@ -795,7 +772,7 @@ private:
void suppressionSingle() { void suppressionSingle() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U)); ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
@ -804,7 +781,7 @@ private:
void suppressionSingleFile() { void suppressionSingleFile() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U)); ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
@ -813,7 +790,7 @@ private:
void suppressionTwo() { void suppressionTwo() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar,unnecessaryQualification", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppress=uninitvar,unnecessaryQualification", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U)); TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
@ -823,7 +800,7 @@ private:
void suppressionTwoSeparate() { void suppressionTwoSeparate() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=unnecessaryQualification", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=unnecessaryQualification", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U)); ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
@ -833,7 +810,7 @@ private:
void templates() { void templates() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "file.cpp"};
Settings settings; settings._outputFormat.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings._outputFormat); ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings._outputFormat);
@ -842,7 +819,7 @@ private:
void templatesGcc() { void templatesGcc() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
Settings settings; settings._outputFormat.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings._outputFormat); ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings._outputFormat);
@ -851,7 +828,7 @@ private:
void templatesVs() { void templatesVs() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
Settings settings; settings._outputFormat.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings._outputFormat); ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings._outputFormat);
@ -860,7 +837,7 @@ private:
void templatesEdit() { void templatesEdit() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
Settings settings; settings._outputFormat.clear();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings._outputFormat); ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings._outputFormat);
@ -869,7 +846,8 @@ private:
void xml() { void xml() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "file.cpp"};
Settings settings; settings._xml_version = 1;
settings._xml = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
@ -879,7 +857,8 @@ private:
void xmlver1() { void xmlver1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"};
Settings settings; settings._xml_version = 1;
settings._xml = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
@ -889,7 +868,8 @@ private:
void xmlver2() { void xmlver2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"};
Settings settings; settings._xml_version = 1;
settings._xml = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
@ -899,7 +879,8 @@ private:
void xmlver2both() { void xmlver2both() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"};
Settings settings; settings._xml_version = 1;
settings._xml = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
@ -909,7 +890,8 @@ private:
void xmlver2both2() { void xmlver2both2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"};
Settings settings; settings._xml_version = 1;
settings._xml = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
@ -919,7 +901,6 @@ private:
void xmlverunknown() { void xmlverunknown() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// FAils since unknown XML format version // FAils since unknown XML format version
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
@ -928,7 +909,6 @@ private:
void xmlverinvalid() { void xmlverinvalid() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// FAils since unknown XML format version // FAils since unknown XML format version
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
@ -937,7 +917,6 @@ private:
void errorlist1() { void errorlist1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist"}; const char *argv[] = {"cppcheck", "--errorlist"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.ParseFromArgs(2, argv));
} }
@ -945,7 +924,7 @@ private:
void errorlistverbose1() { void errorlistverbose1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "--errorlist"}; const char *argv[] = {"cppcheck", "--verbose", "--errorlist"};
Settings settings; settings._verbose = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._verbose); ASSERT(settings._verbose);
@ -954,7 +933,7 @@ private:
void errorlistverbose2() { void errorlistverbose2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist", "--verbose"}; const char *argv[] = {"cppcheck", "--errorlist", "--verbose"};
Settings settings; settings._verbose = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._verbose); ASSERT(settings._verbose);
@ -963,7 +942,6 @@ private:
void ignorepathsnopath() { void ignorepathsnopath() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-i"}; const char *argv[] = {"cppcheck", "-i"};
Settings settings;
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));
@ -973,7 +951,6 @@ private:
void ignorepaths1() { void ignorepaths1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-isrc", "file.cpp"}; const char *argv[] = {"cppcheck", "-isrc", "file.cpp"};
Settings settings;
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());
@ -983,7 +960,6 @@ private:
void ignorepaths2() { void ignorepaths2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"}; const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"};
Settings settings;
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());
@ -993,7 +969,6 @@ private:
void ignorepaths3() { void ignorepaths3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"}; const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
Settings settings;
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());
@ -1004,7 +979,6 @@ private:
void ignorepaths4() { void ignorepaths4() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"}; const char *argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
Settings settings;
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());
@ -1015,7 +989,6 @@ private:
void ignorefilepaths1() { void ignorefilepaths1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"}; const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
Settings settings;
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());
@ -1025,7 +998,6 @@ private:
void ignorefilepaths2() { void ignorefilepaths2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"}; const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
Settings settings;
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());
@ -1035,7 +1007,7 @@ private:
void checkconfig() { void checkconfig() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--check-config", "file.cpp"}; const char *argv[] = {"cppcheck", "--check-config", "file.cpp"};
Settings settings; settings.checkConfiguration = false;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.checkConfiguration); ASSERT_EQUALS(true, settings.checkConfiguration);
@ -1044,7 +1016,6 @@ private:
void unknownParam() { void unknownParam() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--foo", "file.cpp"}; const char *argv[] = {"cppcheck", "--foo", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(!parser.ParseFromArgs(3, argv)); ASSERT(!parser.ParseFromArgs(3, argv));
} }
@ -1052,7 +1023,7 @@ private:
void undefs() { void undefs() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"}; const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(1, settings.userUndefs.size()); ASSERT_EQUALS(1, settings.userUndefs.size());
@ -1062,7 +1033,7 @@ private:
void undefs2() { void undefs2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"}; const char *argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"};
Settings settings; settings = Settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(2, settings.userUndefs.size()); ASSERT_EQUALS(2, settings.userUndefs.size());
@ -1073,7 +1044,6 @@ private:
void undefs_noarg() { void undefs_noarg() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U"}; const char *argv[] = {"cppcheck", "-U"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -U has no param // Fails since -U has no param
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
@ -1082,7 +1052,6 @@ private:
void undefs_noarg2() { void undefs_noarg2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -U has no param // Fails since -U has no param
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
@ -1091,7 +1060,6 @@ private:
void undefs_noarg3() { void undefs_noarg3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since -U has no param // Fails since -U has no param
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));