Use static CmdLineParser instance where possible in testcmdlineparser.cpp, fixed wrong unit test.

This commit is contained in:
PKEuS 2013-08-07 18:24:18 +02:00
parent 36dba8373b
commit 298a33211f
1 changed files with 98 additions and 183 deletions

View File

@ -23,11 +23,14 @@
class TestCmdlineParser : public TestFixture { class TestCmdlineParser : public TestFixture {
public: public:
TestCmdlineParser() : TestFixture("TestCmdlineParser") { TestCmdlineParser()
: TestFixture("TestCmdlineParser")
, defParser(&settings) {
} }
private: private:
Settings settings; Settings settings;
CmdLineParser defParser;
void run() { void run() {
TEST_CASE(nooptions); TEST_CASE(nooptions);
@ -196,8 +199,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-v", "file.cpp"};
settings._verbose = false; settings._verbose = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._verbose); ASSERT_EQUALS(true, settings._verbose);
} }
@ -205,8 +207,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "file.cpp"}; const char *argv[] = {"cppcheck", "--verbose", "file.cpp"};
settings._verbose = false; settings._verbose = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._verbose); ASSERT_EQUALS(true, settings._verbose);
} }
@ -214,8 +215,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--debug", "file.cpp"}; const char *argv[] = {"cppcheck", "--debug", "file.cpp"};
settings.debug = false; settings.debug = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debug); ASSERT_EQUALS(true, settings.debug);
} }
@ -223,8 +223,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"}; const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"};
settings.debugwarnings = false; settings.debugwarnings = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debugwarnings); ASSERT_EQUALS(true, settings.debugwarnings);
} }
@ -232,8 +231,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-f", "file.cpp"}; const char *argv[] = {"cppcheck", "-f", "file.cpp"};
settings._force = false; settings._force = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._force); ASSERT_EQUALS(true, settings._force);
} }
@ -241,31 +239,29 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--force", "file.cpp"}; const char *argv[] = {"cppcheck", "--force", "file.cpp"};
settings._force = false; settings._force = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._force); ASSERT_EQUALS(true, settings._force);
} }
void relativePaths() { void relativePaths() {
REDIRECT; REDIRECT;
CmdLineParser parser(&settings);
settings._relativePaths = false; settings._relativePaths = false;
const char *argvs[] = {"cppcheck", "-rp", "file.cpp"}; const char *argvs[] = {"cppcheck", "-rp", "file.cpp"};
ASSERT(parser.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 *argvl[] = {"cppcheck", "--relative-paths", "file.cpp"};
ASSERT(parser.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 *argvsp[] = {"cppcheck", "-rp=C:/foo;C:\\bar", "file.cpp"};
ASSERT(parser.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());
ASSERT_EQUALS("C:/foo", settings._basePaths[0]); ASSERT_EQUALS("C:/foo", settings._basePaths[0]);
@ -275,7 +271,7 @@ private:
settings._basePaths.clear(); settings._basePaths.clear();
const char *argvlp[] = {"cppcheck", "--relative-paths=C:/foo;C:\\bar", "file.cpp"}; const char *argvlp[] = {"cppcheck", "--relative-paths=C:/foo;C:\\bar", "file.cpp"};
ASSERT(parser.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());
ASSERT_EQUALS("C:/foo", settings._basePaths[0]); ASSERT_EQUALS("C:/foo", settings._basePaths[0]);
@ -286,8 +282,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-q", "file.cpp"}; const char *argv[] = {"cppcheck", "-q", "file.cpp"};
settings._errorsOnly = false; settings._errorsOnly = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._errorsOnly); ASSERT_EQUALS(true, settings._errorsOnly);
} }
@ -295,50 +290,44 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "--quiet", "file.cpp"};
settings._errorsOnly = false; settings._errorsOnly = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._errorsOnly); ASSERT_EQUALS(true, settings._errorsOnly);
} }
void defines_noarg() { void defines_noarg() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D"}; const char *argv[] = {"cppcheck", "-D"};
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, defParser.ParseFromArgs(2, argv));
} }
void defines_noarg2() { void defines_noarg2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
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, defParser.ParseFromArgs(4, argv));
} }
void defines_noarg3() { void defines_noarg3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
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, defParser.ParseFromArgs(4, argv));
} }
void defines() { void defines() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"}; const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"};
settings.userDefines.clear(); settings.userDefines.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("_WIN32=1", settings.userDefines); ASSERT_EQUALS("_WIN32=1", settings.userDefines);
} }
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.userDefines.clear(); settings.userDefines.clear();;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines); ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
} }
@ -346,8 +335,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"};
settings.userDefines.clear(); settings.userDefines.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("DEBUG=1", settings.userDefines); ASSERT_EQUALS("DEBUG=1", settings.userDefines);
} }
@ -355,8 +343,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"};
settings.userDefines.clear(); settings.userDefines.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("DEBUG", settings.userDefines); ASSERT_EQUALS("DEBUG", settings.userDefines);
} }
@ -365,62 +352,53 @@ private:
{ {
const char *argv[] = {"cppcheck", "file.cpp"}; const char *argv[] = {"cppcheck", "file.cpp"};
settings.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); ASSERT(defParser.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.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); ASSERT(defParser.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"};
CmdLineParser parser(&settings); ASSERT(!defParser.ParseFromArgs(2, argv));
ASSERT(!parser.ParseFromArgs(2, argv));
} }
{ {
const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"}; const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"};
CmdLineParser parser(&settings); ASSERT(!defParser.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.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); ASSERT(defParser.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.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
CmdLineParser parser(&settings); ASSERT(defParser.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"};
CmdLineParser parser(&settings); ASSERT(!defParser.ParseFromArgs(3, argv));
ASSERT(!parser.ParseFromArgs(3, argv));
} }
} }
void includesnopath() { void includesnopath() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "file.cpp"}; const char *argv[] = {"cppcheck", "-I"};
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, defParser.ParseFromArgs(2, argv));
} }
void includes() { void includes() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"};
settings._includePaths.clear(); settings._includePaths.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
} }
@ -428,8 +406,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"};
settings._includePaths.clear(); settings._includePaths.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
} }
@ -437,8 +414,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"};
settings._includePaths.clear(); settings._includePaths.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
} }
@ -446,8 +422,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"}; const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
settings._includePaths.clear(); settings._includePaths.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
} }
@ -455,8 +430,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"};
settings._includePaths.clear(); settings._includePaths.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(6, argv));
ASSERT(parser.ParseFromArgs(6, argv));
ASSERT_EQUALS("include/", settings._includePaths.front()); ASSERT_EQUALS("include/", settings._includePaths.front());
settings._includePaths.pop_front(); settings._includePaths.pop_front();
ASSERT_EQUALS("framework/", settings._includePaths.front()); ASSERT_EQUALS("framework/", settings._includePaths.front());
@ -467,16 +441,14 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"}; const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"};
settings._includePaths.clear(); settings._includePaths.clear();
CmdLineParser parser(&settings); ASSERT_EQUALS(true, defParser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, parser.ParseFromArgs(3, argv));
} }
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("style")); ASSERT(settings.isEnabled("style"));
ASSERT(settings.isEnabled("warning")); ASSERT(settings.isEnabled("warning"));
ASSERT(settings.isEnabled("unusedFunction")); ASSERT(settings.isEnabled("unusedFunction"));
@ -488,8 +460,7 @@ private:
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("style")); ASSERT(settings.isEnabled("style"));
ASSERT(settings.isEnabled("warning")); ASSERT(settings.isEnabled("warning"));
ASSERT(settings.isEnabled("performance")); ASSERT(settings.isEnabled("performance"));
@ -502,8 +473,7 @@ private:
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(!settings.isEnabled("style")); ASSERT(!settings.isEnabled("style"));
ASSERT(!settings.isEnabled("warning")); ASSERT(!settings.isEnabled("warning"));
ASSERT(settings.isEnabled("performance")); ASSERT(settings.isEnabled("performance"));
@ -516,8 +486,7 @@ private:
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(!settings.isEnabled("style")); ASSERT(!settings.isEnabled("style"));
ASSERT(!settings.isEnabled("warning")); ASSERT(!settings.isEnabled("warning"));
ASSERT(!settings.isEnabled("performance")); ASSERT(!settings.isEnabled("performance"));
@ -530,8 +499,7 @@ private:
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("unusedFunction")); ASSERT(settings.isEnabled("unusedFunction"));
} }
@ -539,8 +507,7 @@ private:
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("missingInclude")); ASSERT(settings.isEnabled("missingInclude"));
} }
@ -549,8 +516,7 @@ private:
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.isEnabled("internal")); ASSERT(settings.isEnabled("internal"));
} }
#endif #endif
@ -559,8 +525,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=missingInclude,portability,warning", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=missingInclude,portability,warning", "file.cpp"};
settings = Settings(); settings = Settings();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(!settings.isEnabled("style")); ASSERT(!settings.isEnabled("style"));
ASSERT(settings.isEnabled("warning")); ASSERT(settings.isEnabled("warning"));
ASSERT(!settings.isEnabled("performance")); ASSERT(!settings.isEnabled("performance"));
@ -573,8 +538,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"}; const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"};
settings._exitCode = 0; settings._exitCode = 0;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(5, settings._exitCode); ASSERT_EQUALS(5, settings._exitCode);
} }
@ -582,18 +546,16 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"}; const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"};
settings._exitCode = 0; settings._exitCode = 0;
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, defParser.ParseFromArgs(3, argv));
} }
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._exitCode = 0; settings._exitCode = 0;
CmdLineParser parser(&settings);
// Fails since invalid exit code // Fails since invalid exit code
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
} }
void exitcodeSuppressionsOld() { void exitcodeSuppressionsOld() {
@ -601,8 +563,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"}; const char *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"};
settings._exitCode = 0; settings._exitCode = 0;
CmdLineParser parser(&settings); TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(4, argv));
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv));
} }
void exitcodeSuppressions() { void exitcodeSuppressions() {
@ -610,8 +571,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"}; const char *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"};
settings._exitCode = 0; settings._exitCode = 0;
CmdLineParser parser(&settings); TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
void exitcodeSuppressionsNoFile() { void exitcodeSuppressionsNoFile() {
@ -619,16 +579,14 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"}; const char *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"};
settings._exitCode = 0; settings._exitCode = 0;
CmdLineParser parser(&settings); TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
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 *argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"};
CmdLineParser parser(&settings); TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(4, argv));
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv));
} }
void fileListStdin() { void fileListStdin() {
@ -636,23 +594,20 @@ 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"};
CmdLineParser parser(&settings); TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
void inlineSuppr() { void inlineSuppr() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"}; const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"};
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
} }
void jobs() { void jobs() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"};
settings._jobs = 0; settings._jobs = 0;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(3, settings._jobs); ASSERT_EQUALS(3, settings._jobs);
} }
@ -660,18 +615,16 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-j", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "file.cpp"};
settings._jobs = 0; settings._jobs = 0;
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, defParser.ParseFromArgs(3, argv));
} }
void jobsInvalid() { void jobsInvalid() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"};
settings._jobs = 0; settings._jobs = 0;
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, defParser.ParseFromArgs(4, argv));
} }
void maxConfigs() { void maxConfigs() {
@ -679,8 +632,7 @@ private:
const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"}; const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"};
settings._force = false; settings._force = false;
settings._maxConfigs = 12; settings._maxConfigs = 12;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(12, settings._maxConfigs); ASSERT_EQUALS(12, settings._maxConfigs);
ASSERT_EQUALS(false, settings._force); ASSERT_EQUALS(false, settings._force);
} }
@ -688,33 +640,29 @@ private:
void maxConfigsMissingCount() { void maxConfigsMissingCount() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"};
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, defParser.ParseFromArgs(3, argv));
} }
void maxConfigsInvalid() { void maxConfigsInvalid() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"};
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, defParser.ParseFromArgs(3, argv));
} }
void maxConfigsTooSmall() { void maxConfigsTooSmall() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"};
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, defParser.ParseFromArgs(3, argv));
} }
void reportProgressTest() { void reportProgressTest() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"}; const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"};
settings.reportProgress = false; settings.reportProgress = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.reportProgress); ASSERT(settings.reportProgress);
} }
@ -722,8 +670,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"}; const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"};
settings.standards.posix = false; settings.standards.posix = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.standards.posix); ASSERT(settings.standards.posix);
} }
@ -731,8 +678,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"}; const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"};
settings.standards.c = Standards::C89; settings.standards.c = Standards::C89;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.standards.c == Standards::C99); ASSERT(settings.standards.c == Standards::C99);
} }
@ -740,8 +686,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"}; const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"};
settings.standards.cpp = Standards::CPP03; settings.standards.cpp = Standards::CPP03;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings.standards.cpp == Standards::CPP11); ASSERT(settings.standards.cpp == Standards::CPP11);
} }
@ -749,16 +694,14 @@ 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"};
CmdLineParser parser(&settings); ASSERT(!defParser.ParseFromArgs(4, argv));
ASSERT(!parser.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 *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"};
CmdLineParser parser(&settings); TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
} }
void suppressionsNoFile() { void suppressionsNoFile() {
@ -766,24 +709,21 @@ private:
{ {
CLEAR_REDIRECT_OUTPUT; CLEAR_REDIRECT_OUTPUT;
const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
CmdLineParser parser(&settings); ASSERT_EQUALS(false, defParser.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);
} }
{ {
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"};
CmdLineParser parser(&settings); ASSERT_EQUALS(false, defParser.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);
} }
{ {
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"};
CmdLineParser parser(&settings); ASSERT_EQUALS(false, defParser.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);
} }
} }
@ -792,8 +732,7 @@ private:
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); ASSERT(defParser.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));
} }
@ -801,8 +740,7 @@ private:
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); ASSERT(defParser.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));
} }
@ -810,8 +748,7 @@ private:
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); TODO_ASSERT_EQUALS(true, false, defParser.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));
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U)); TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U));
} }
@ -820,8 +757,7 @@ private:
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); ASSERT(defParser.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));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U)); ASSERT_EQUALS(true, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U));
} }
@ -830,8 +766,7 @@ private:
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._outputFormat.clear(); settings._outputFormat.clear();
CmdLineParser parser(&settings); ASSERT(defParser.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);
} }
@ -839,8 +774,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
settings._outputFormat.clear(); settings._outputFormat.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings._outputFormat); ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings._outputFormat);
} }
@ -848,8 +782,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
settings._outputFormat.clear(); settings._outputFormat.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings._outputFormat); ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings._outputFormat);
} }
@ -857,8 +790,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
settings._outputFormat.clear(); settings._outputFormat.clear();
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings._outputFormat); ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings._outputFormat);
} }
@ -867,8 +799,7 @@ private:
const char *argv[] = {"cppcheck", "--xml", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "file.cpp"};
settings._xml_version = 1; settings._xml_version = 1;
settings._xml = false; settings._xml = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
ASSERT_EQUALS(1, settings._xml_version); ASSERT_EQUALS(1, settings._xml_version);
} }
@ -878,8 +809,7 @@ private:
const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"};
settings._xml_version = 1; settings._xml_version = 1;
settings._xml = false; settings._xml = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
ASSERT_EQUALS(1, settings._xml_version); ASSERT_EQUALS(1, settings._xml_version);
} }
@ -889,8 +819,7 @@ private:
const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"};
settings._xml_version = 1; settings._xml_version = 1;
settings._xml = false; settings._xml = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
ASSERT_EQUALS(2, settings._xml_version); ASSERT_EQUALS(2, settings._xml_version);
} }
@ -900,8 +829,7 @@ private:
const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"};
settings._xml_version = 1; settings._xml_version = 1;
settings._xml = false; settings._xml = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
ASSERT_EQUALS(2, settings._xml_version); ASSERT_EQUALS(2, settings._xml_version);
} }
@ -911,8 +839,7 @@ private:
const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"};
settings._xml_version = 1; settings._xml_version = 1;
settings._xml = false; settings._xml = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT(settings._xml); ASSERT(settings._xml);
ASSERT_EQUALS(2, settings._xml_version); ASSERT_EQUALS(2, settings._xml_version);
} }
@ -920,32 +847,28 @@ 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"};
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, defParser.ParseFromArgs(4, argv));
} }
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"};
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, defParser.ParseFromArgs(4, argv));
} }
void errorlist1() { void errorlist1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist"}; const char *argv[] = {"cppcheck", "--errorlist"};
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(2, argv));
ASSERT(parser.ParseFromArgs(2, argv));
} }
void errorlistverbose1() { void errorlistverbose1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "--errorlist"}; const char *argv[] = {"cppcheck", "--verbose", "--errorlist"};
settings._verbose = false; settings._verbose = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._verbose); ASSERT(settings._verbose);
} }
@ -953,8 +876,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist", "--verbose"}; const char *argv[] = {"cppcheck", "--errorlist", "--verbose"};
settings._verbose = false; settings._verbose = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._verbose); ASSERT(settings._verbose);
} }
@ -1027,24 +949,21 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--check-config", "file.cpp"}; const char *argv[] = {"cppcheck", "--check-config", "file.cpp"};
settings.checkConfiguration = false; settings.checkConfiguration = false;
CmdLineParser parser(&settings); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.checkConfiguration); ASSERT_EQUALS(true, settings.checkConfiguration);
} }
void unknownParam() { void unknownParam() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--foo", "file.cpp"}; const char *argv[] = {"cppcheck", "--foo", "file.cpp"};
CmdLineParser parser(&settings); ASSERT(!defParser.ParseFromArgs(3, argv));
ASSERT(!parser.ParseFromArgs(3, argv));
} }
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); ASSERT(defParser.ParseFromArgs(3, argv));
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(1, settings.userUndefs.size()); ASSERT_EQUALS(1, settings.userUndefs.size());
ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end()); ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end());
} }
@ -1053,8 +972,7 @@ private:
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); ASSERT(defParser.ParseFromArgs(4, argv));
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS(2, settings.userUndefs.size()); ASSERT_EQUALS(2, settings.userUndefs.size());
ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end()); ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end());
ASSERT(settings.userUndefs.find("NODEBUG") != settings.userUndefs.end()); ASSERT(settings.userUndefs.find("NODEBUG") != settings.userUndefs.end());
@ -1063,25 +981,22 @@ private:
void undefs_noarg() { void undefs_noarg() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U"}; const char *argv[] = {"cppcheck", "-U"};
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, defParser.ParseFromArgs(2, argv));
} }
void undefs_noarg2() { void undefs_noarg2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"};
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, defParser.ParseFromArgs(4, argv));
} }
void undefs_noarg3() { void undefs_noarg3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"};
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, defParser.ParseFromArgs(4, argv));
} }
}; };