Refactoring. Rename methods

This commit is contained in:
Daniel Marjamäki 2018-04-23 12:39:47 +02:00
parent f058d9ad08
commit 7c5058a42d
4 changed files with 189 additions and 189 deletions

View File

@ -102,17 +102,17 @@ CmdLineParser::CmdLineParser(Settings *settings)
{ {
} }
void CmdLineParser::PrintMessage(const std::string &message) void CmdLineParser::printMessage(const std::string &message)
{ {
std::cout << message << std::endl; std::cout << message << std::endl;
} }
void CmdLineParser::PrintMessage(const char* message) void CmdLineParser::printMessage(const char* message)
{ {
std::cout << message << std::endl; std::cout << message << std::endl;
} }
bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
{ {
bool def = false; bool def = false;
bool maxconfigs = false; bool maxconfigs = false;
@ -168,7 +168,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} else { } else {
i++; i++;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: No language given to '-x' option."); printMessage("cppcheck: No language given to '-x' option.");
return false; return false;
} }
str = argv[i]; str = argv[i];
@ -179,7 +179,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
else if (str == "c++") else if (str == "c++")
_settings->enforcedLang = Settings::CPP; _settings->enforcedLang = Settings::CPP;
else { else {
PrintMessage("cppcheck: Unknown language '" + str + "' enforced."); printMessage("cppcheck: Unknown language '" + str + "' enforced.");
return false; return false;
} }
} }
@ -191,12 +191,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::ifstream f(filename); std::ifstream f(filename);
if (!f.is_open()) { if (!f.is_open()) {
PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\"."); printMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
return false; return false;
} }
const std::string errmsg(_settings->nofail.parseFile(f)); const std::string errmsg(_settings->nofail.parseFile(f));
if (!errmsg.empty()) { if (!errmsg.empty()) {
PrintMessage(errmsg); printMessage(errmsg);
return false; return false;
} }
} }
@ -218,12 +218,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
message += "\n cppcheck --suppressions-list=a.txt --suppressions-list=b.txt file.cpp"; message += "\n cppcheck --suppressions-list=a.txt --suppressions-list=b.txt file.cpp";
} }
PrintMessage(message); printMessage(message);
return false; return false;
} }
const std::string errmsg(_settings->nomsg.parseFile(f)); const std::string errmsg(_settings->nomsg.parseFile(f));
if (!errmsg.empty()) { if (!errmsg.empty()) {
PrintMessage(errmsg); printMessage(errmsg);
return false; return false;
} }
} }
@ -232,7 +232,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
const char * filename = argv[i] + 15; const char * filename = argv[i] + 15;
const std::string errmsg(_settings->nomsg.parseXmlFile(filename)); const std::string errmsg(_settings->nomsg.parseXmlFile(filename));
if (!errmsg.empty()) { if (!errmsg.empty()) {
PrintMessage(errmsg); printMessage(errmsg);
return false; return false;
} }
} }
@ -241,7 +241,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
const std::string suppression = argv[i]+11; const std::string suppression = argv[i]+11;
const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression)); const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression));
if (!errmsg.empty()) { if (!errmsg.empty()) {
PrintMessage(errmsg); printMessage(errmsg);
return false; return false;
} }
} }
@ -275,7 +275,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
paths.erase(0, pos + 1); paths.erase(0, pos + 1);
} }
} else { } else {
PrintMessage("cppcheck: No paths specified for the '" + std::string(argv[i]) + "' option."); printMessage("cppcheck: No paths specified for the '" + std::string(argv[i]) + "' option.");
return false; return false;
} }
} }
@ -303,13 +303,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::istringstream iss(numberString); std::istringstream iss(numberString);
if (!(iss >> _settings->xml_version)) { if (!(iss >> _settings->xml_version)) {
PrintMessage("cppcheck: argument to '--xml-version' is not a number."); printMessage("cppcheck: argument to '--xml-version' is not a number.");
return false; return false;
} }
if (_settings->xml_version != 2) { if (_settings->xml_version != 2) {
// We only have xml version 2 // We only have xml version 2
PrintMessage("cppcheck: '--xml-version' can only be 2."); printMessage("cppcheck: '--xml-version' can only be 2.");
return false; return false;
} }
@ -334,7 +334,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
else if (std::strncmp(argv[i], "--enable=", 9) == 0) { else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
const std::string errmsg = _settings->addEnabled(argv[i] + 9); const std::string errmsg = _settings->addEnabled(argv[i] + 9);
if (!errmsg.empty()) { if (!errmsg.empty()) {
PrintMessage(errmsg); printMessage(errmsg);
return false; return false;
} }
// when "style" is enabled, also enable "warning", "performance" and "portability" // when "style" is enabled, also enable "warning", "performance" and "portability"
@ -351,7 +351,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::istringstream iss(temp); std::istringstream iss(temp);
if (!(iss >> _settings->exitCode)) { if (!(iss >> _settings->exitCode)) {
_settings->exitCode = 0; _settings->exitCode = 0;
PrintMessage("cppcheck: Argument must be an integer. Try something like '--error-exitcode=1'."); printMessage("cppcheck: Argument must be an integer. Try something like '--error-exitcode=1'.");
return false; return false;
} }
} }
@ -364,7 +364,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (std::strcmp(argv[i], "-D") == 0) { if (std::strcmp(argv[i], "-D") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-D' is missing."); printMessage("cppcheck: argument to '-D' is missing.");
return false; return false;
} }
@ -393,7 +393,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (std::strcmp(argv[i], "-U") == 0) { if (std::strcmp(argv[i], "-U") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-U' is missing."); printMessage("cppcheck: argument to '-U' is missing.");
return false; return false;
} }
@ -420,7 +420,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (std::strcmp(argv[i], "-I") == 0) { if (std::strcmp(argv[i], "-I") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-I' is missing."); printMessage("cppcheck: argument to '-I' is missing.");
return false; return false;
} }
path = argv[i]; path = argv[i];
@ -470,7 +470,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (std::strcmp(argv[i], "-i") == 0) { if (std::strcmp(argv[i], "-i") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-i' is missing."); printMessage("cppcheck: argument to '-i' is missing.");
return false; return false;
} }
path = argv[i]; path = argv[i];
@ -507,7 +507,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (std::strstr(argv[i], ".sln") || std::strstr(argv[i], ".vcxproj")) { if (std::strstr(argv[i], ".sln") || std::strstr(argv[i], ".vcxproj")) {
if (!CppCheckExecutor::tryLoadLibrary(_settings->library, argv[0], "windows.cfg")) { if (!CppCheckExecutor::tryLoadLibrary(_settings->library, argv[0], "windows.cfg")) {
// This shouldn't happen normally. // This shouldn't happen normally.
PrintMessage("cppcheck: Failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install."); printMessage("cppcheck: Failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
return false; return false;
} }
} }
@ -545,7 +545,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
++i; ++i;
_settings->templateFormat = argv[i]; _settings->templateFormat = argv[i];
} else { } else {
PrintMessage("cppcheck: argument to '--template' is missing."); printMessage("cppcheck: argument to '--template' is missing.");
return false; return false;
} }
@ -571,7 +571,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
++i; ++i;
_settings->templateLocation = argv[i]; _settings->templateLocation = argv[i];
} else { } else {
PrintMessage("cppcheck: argument to '--template' is missing."); printMessage("cppcheck: argument to '--template' is missing.");
return false; return false;
} }
} }
@ -584,7 +584,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (std::strcmp(argv[i], "-j") == 0) { if (std::strcmp(argv[i], "-j") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-j' is missing."); printMessage("cppcheck: argument to '-j' is missing.");
return false; return false;
} }
@ -597,14 +597,14 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::istringstream iss(numberString); std::istringstream iss(numberString);
if (!(iss >> _settings->jobs)) { if (!(iss >> _settings->jobs)) {
PrintMessage("cppcheck: argument to '-j' is not a number."); printMessage("cppcheck: argument to '-j' is not a number.");
return false; return false;
} }
if (_settings->jobs > 10000) { if (_settings->jobs > 10000) {
// This limit is here just to catch typos. If someone has // This limit is here just to catch typos. If someone has
// need for more jobs, this value should be increased. // need for more jobs, this value should be increased.
PrintMessage("cppcheck: argument for '-j' is allowed to be 10000 at max."); printMessage("cppcheck: argument for '-j' is allowed to be 10000 at max.");
return false; return false;
} }
} else if (std::strncmp(argv[i], "-l", 2) == 0) { } else if (std::strncmp(argv[i], "-l", 2) == 0) {
@ -614,7 +614,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (std::strcmp(argv[i], "-l") == 0) { if (std::strcmp(argv[i], "-l") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-l' is missing."); printMessage("cppcheck: argument to '-l' is missing.");
return false; return false;
} }
@ -627,7 +627,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::istringstream iss(numberString); std::istringstream iss(numberString);
if (!(iss >> _settings->loadAverage)) { if (!(iss >> _settings->loadAverage)) {
PrintMessage("cppcheck: argument to '-l' is not a number."); printMessage("cppcheck: argument to '-l' is not a number.");
return false; return false;
} }
} }
@ -671,7 +671,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::string message("cppcheck: error: unrecognized showtime mode: \""); std::string message("cppcheck: error: unrecognized showtime mode: \"");
message += showtimeMode; message += showtimeMode;
message += "\". Supported modes: file, summary, top5."; message += "\". Supported modes: file, summary, top5.";
PrintMessage(message); printMessage(message);
return false; return false;
} }
} }
@ -745,7 +745,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::string message("cppcheck: error: unrecognized platform: \""); std::string message("cppcheck: error: unrecognized platform: \"");
message += platform; message += platform;
message += "\"."; message += "\".";
PrintMessage(message); printMessage(message);
return false; return false;
} }
} }
@ -756,12 +756,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::istringstream iss(14+argv[i]); std::istringstream iss(14+argv[i]);
if (!(iss >> _settings->maxConfigs)) { if (!(iss >> _settings->maxConfigs)) {
PrintMessage("cppcheck: argument to '--max-configs=' is not a number."); printMessage("cppcheck: argument to '--max-configs=' is not a number.");
return false; return false;
} }
if (_settings->maxConfigs < 1) { if (_settings->maxConfigs < 1) {
PrintMessage("cppcheck: argument to '--max-configs=' must be greater than 0."); printMessage("cppcheck: argument to '--max-configs=' must be greater than 0.");
return false; return false;
} }
@ -780,7 +780,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
std::string message("cppcheck: error: unrecognized command line option: \""); std::string message("cppcheck: error: unrecognized command line option: \"");
message += argv[i]; message += argv[i];
message += "\"."; message += "\".";
PrintMessage(message); printMessage(message);
return false; return false;
} }
} }
@ -801,7 +801,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->maxConfigs = 1U; _settings->maxConfigs = 1U;
if (_settings->isEnabled(Settings::UNUSED_FUNCTION) && _settings->jobs > 1) { if (_settings->isEnabled(Settings::UNUSED_FUNCTION) && _settings->jobs > 1) {
PrintMessage("cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check."); printMessage("cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.");
} }
if (argc <= 1) { if (argc <= 1) {
@ -810,13 +810,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
if (_showHelp) { if (_showHelp) {
PrintHelp(); printHelp();
return true; return true;
} }
// Print error only if we have "real" command and expect files // Print error only if we have "real" command and expect files
if (!_exitAfterPrint && _pathnames.empty() && _settings->project.fileSettings.empty()) { if (!_exitAfterPrint && _pathnames.empty() && _settings->project.fileSettings.empty()) {
PrintMessage("cppcheck: No C or C++ source files found."); printMessage("cppcheck: No C or C++ source files found.");
return false; return false;
} }
@ -827,7 +827,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
return true; return true;
} }
void CmdLineParser::PrintHelp() void CmdLineParser::printHelp()
{ {
std::cout << "Cppcheck - A tool for static C/C++ code analysis\n" std::cout << "Cppcheck - A tool for static C/C++ code analysis\n"
"\n" "\n"

View File

@ -49,47 +49,47 @@ public:
* Parse given command line. * Parse given command line.
* @return true if command line was ok, false if there was an error. * @return true if command line was ok, false if there was an error.
*/ */
bool ParseFromArgs(int argc, const char* const argv[]); bool parseFromArgs(int argc, const char* const argv[]);
/** /**
* Return if user wanted to see program version. * Return if user wanted to see program version.
*/ */
bool GetShowVersion() const { bool getShowVersion() const {
return _showVersion; return _showVersion;
} }
/** /**
* Return if user wanted to see list of error messages. * Return if user wanted to see list of error messages.
*/ */
bool GetShowErrorMessages() const { bool getShowErrorMessages() const {
return _showErrorMessages; return _showErrorMessages;
} }
/** /**
* Return the path names user gave to command line. * Return the path names user gave to command line.
*/ */
const std::vector<std::string>& GetPathNames() const { const std::vector<std::string>& getPathNames() const {
return _pathnames; return _pathnames;
} }
/** /**
* Return if help is shown to user. * Return if help is shown to user.
*/ */
bool GetShowHelp() const { bool getShowHelp() const {
return _showHelp; return _showHelp;
} }
/** /**
* Return if we should exit after printing version, help etc. * Return if we should exit after printing version, help etc.
*/ */
bool ExitAfterPrinting() const { bool exitAfterPrinting() const {
return _exitAfterPrint; return _exitAfterPrint;
} }
/** /**
* Return a list of paths user wants to ignore. * Return a list of paths user wants to ignore.
*/ */
const std::vector<std::string>& GetIgnoredPaths() const { const std::vector<std::string>& getIgnoredPaths() const {
return _ignoredPaths; return _ignoredPaths;
} }
@ -98,13 +98,13 @@ protected:
/** /**
* Print help text to the console. * Print help text to the console.
*/ */
static void PrintHelp(); static void printHelp();
/** /**
* Print message (to console?). * Print message (to console?).
*/ */
static void PrintMessage(const std::string &message); static void printMessage(const std::string &message);
static void PrintMessage(const char* message); static void printMessage(const char* message);
private: private:
std::vector<std::string> _pathnames; std::vector<std::string> _pathnames;

View File

@ -92,10 +92,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
{ {
Settings& settings = cppcheck->settings(); Settings& settings = cppcheck->settings();
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
const bool success = parser.ParseFromArgs(argc, argv); const bool success = parser.parseFromArgs(argc, argv);
if (success) { if (success) {
if (parser.GetShowVersion() && !parser.GetShowErrorMessages()) { if (parser.getShowVersion() && !parser.getShowErrorMessages()) {
const char * const extraVersion = cppcheck->extraVersion(); const char * const extraVersion = cppcheck->extraVersion();
if (*extraVersion != 0) if (*extraVersion != 0)
std::cout << "Cppcheck " << cppcheck->version() << " (" std::cout << "Cppcheck " << cppcheck->version() << " ("
@ -104,14 +104,14 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
std::cout << "Cppcheck " << cppcheck->version() << std::endl; std::cout << "Cppcheck " << cppcheck->version() << std::endl;
} }
if (parser.GetShowErrorMessages()) { if (parser.getShowErrorMessages()) {
errorlist = true; errorlist = true;
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(); std::cout << ErrorLogger::ErrorMessage::getXMLHeader();
cppcheck->getErrorMessages(); cppcheck->getErrorMessages();
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl; std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
} }
if (parser.ExitAfterPrinting()) { if (parser.exitAfterPrinting()) {
settings.terminate(); settings.terminate();
return true; return true;
} }
@ -138,9 +138,9 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
// Output a warning for the user if he tries to exclude headers // Output a warning for the user if he tries to exclude headers
bool warn = false; bool warn = false;
const std::vector<std::string>& ignored = parser.GetIgnoredPaths(); const std::vector<std::string>& ignored = parser.getIgnoredPaths();
for (std::vector<std::string>::const_iterator i = ignored.cbegin(); i != ignored.cend(); ++i) { for (const std::string &i : ignored) {
if (Path::isHeader(*i)) { if (Path::isHeader(i)) {
warn = true; warn = true;
break; break;
} }
@ -150,7 +150,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
std::cout << "cppcheck: Please use --suppress for ignoring results from the header files." << std::endl; std::cout << "cppcheck: Please use --suppress for ignoring results from the header files." << std::endl;
} }
const std::vector<std::string>& pathnames = parser.GetPathNames(); const std::vector<std::string>& pathnames = parser.getPathNames();
#if defined(_WIN32) #if defined(_WIN32)
// For Windows we want case-insensitive path matching // For Windows we want case-insensitive path matching

View File

@ -154,65 +154,65 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck"}; const char *argv[] = {"cppcheck"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(1, argv)); ASSERT(parser.parseFromArgs(1, argv));
ASSERT_EQUALS(true, parser.GetShowHelp()); ASSERT_EQUALS(true, parser.getShowHelp());
} }
void helpshort() { void helpshort() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-h"}; const char *argv[] = {"cppcheck", "-h"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.parseFromArgs(2, argv));
ASSERT_EQUALS(true, parser.GetShowHelp()); ASSERT_EQUALS(true, parser.getShowHelp());
} }
void helplong() { void helplong() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--help"}; const char *argv[] = {"cppcheck", "--help"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.parseFromArgs(2, argv));
ASSERT_EQUALS(true, parser.GetShowHelp()); ASSERT_EQUALS(true, parser.getShowHelp());
} }
void showversion() { void showversion() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--version"}; const char *argv[] = {"cppcheck", "--version"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.parseFromArgs(2, argv));
ASSERT_EQUALS(true, parser.GetShowVersion()); ASSERT_EQUALS(true, parser.getShowVersion());
} }
void onefile() { void onefile() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "file.cpp"}; const char *argv[] = {"cppcheck", "file.cpp"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.parseFromArgs(2, argv));
ASSERT_EQUALS(1, (int)parser.GetPathNames().size()); ASSERT_EQUALS(1, (int)parser.getPathNames().size());
ASSERT_EQUALS("file.cpp", parser.GetPathNames().at(0)); ASSERT_EQUALS("file.cpp", parser.getPathNames().at(0));
} }
void onepath() { void onepath() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "src"}; const char *argv[] = {"cppcheck", "src"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.parseFromArgs(2, argv));
ASSERT_EQUALS(1, (int)parser.GetPathNames().size()); ASSERT_EQUALS(1, (int)parser.getPathNames().size());
ASSERT_EQUALS("src", parser.GetPathNames().at(0)); ASSERT_EQUALS("src", parser.getPathNames().at(0));
} }
void optionwithoutfile() { void optionwithoutfile() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-v"}; const char *argv[] = {"cppcheck", "-v"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv)); ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
ASSERT_EQUALS(0, (int)parser.GetPathNames().size()); ASSERT_EQUALS(0, (int)parser.getPathNames().size());
} }
void verboseshort() { void verboseshort() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-v", "file.cpp"};
settings.verbose = false; settings.verbose = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.verbose); ASSERT_EQUALS(true, settings.verbose);
} }
@ -220,7 +220,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "file.cpp"}; const char *argv[] = {"cppcheck", "--verbose", "file.cpp"};
settings.verbose = false; settings.verbose = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.verbose); ASSERT_EQUALS(true, settings.verbose);
} }
@ -228,7 +228,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--debug", "file.cpp"}; const char *argv[] = {"cppcheck", "--debug", "file.cpp"};
settings.debug = false; settings.debug = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debug); ASSERT_EQUALS(true, settings.debug);
} }
@ -236,7 +236,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;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debugwarnings); ASSERT_EQUALS(true, settings.debugwarnings);
} }
@ -244,7 +244,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-f", "file.cpp"}; const char *argv[] = {"cppcheck", "-f", "file.cpp"};
settings.force = false; settings.force = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.force); ASSERT_EQUALS(true, settings.force);
} }
@ -252,7 +252,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--force", "file.cpp"}; const char *argv[] = {"cppcheck", "--force", "file.cpp"};
settings.force = false; settings.force = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.force); ASSERT_EQUALS(true, settings.force);
} }
@ -261,20 +261,20 @@ private:
settings.relativePaths = false; settings.relativePaths = false;
const char *argvs[] = {"cppcheck", "-rp", "file.cpp"}; const char *argvs[] = {"cppcheck", "-rp", "file.cpp"};
ASSERT(defParser.ParseFromArgs(3, argvs)); ASSERT(defParser.parseFromArgs(3, argvs));
ASSERT_EQUALS(true, settings.relativePaths); ASSERT_EQUALS(true, settings.relativePaths);
settings.relativePaths = false; settings.relativePaths = false;
const char *argvl[] = {"cppcheck", "--relative-paths", "file.cpp"}; const char *argvl[] = {"cppcheck", "--relative-paths", "file.cpp"};
ASSERT(defParser.ParseFromArgs(3, argvl)); ASSERT(defParser.parseFromArgs(3, argvl));
ASSERT_EQUALS(true, settings.relativePaths); ASSERT_EQUALS(true, settings.relativePaths);
settings.relativePaths = false; settings.relativePaths = false;
settings.basePaths.clear(); settings.basePaths.clear();
const char *argvsp[] = {"cppcheck", "-rp=C:/foo;C:\\bar", "file.cpp"}; const char *argvsp[] = {"cppcheck", "-rp=C:/foo;C:\\bar", "file.cpp"};
ASSERT(defParser.ParseFromArgs(3, argvsp)); ASSERT(defParser.parseFromArgs(3, argvsp));
ASSERT_EQUALS(true, settings.relativePaths); ASSERT_EQUALS(true, settings.relativePaths);
ASSERT_EQUALS(2, settings.basePaths.size()); ASSERT_EQUALS(2, settings.basePaths.size());
ASSERT_EQUALS("C:/foo", settings.basePaths[0]); ASSERT_EQUALS("C:/foo", settings.basePaths[0]);
@ -284,7 +284,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(defParser.ParseFromArgs(3, argvlp)); ASSERT(defParser.parseFromArgs(3, argvlp));
ASSERT_EQUALS(true, settings.relativePaths); ASSERT_EQUALS(true, settings.relativePaths);
ASSERT_EQUALS(2, settings.basePaths.size()); ASSERT_EQUALS(2, settings.basePaths.size());
ASSERT_EQUALS("C:/foo", settings.basePaths[0]); ASSERT_EQUALS("C:/foo", settings.basePaths[0]);
@ -295,7 +295,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-q", "file.cpp"}; const char *argv[] = {"cppcheck", "-q", "file.cpp"};
settings.quiet = false; settings.quiet = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.quiet); ASSERT_EQUALS(true, settings.quiet);
} }
@ -303,7 +303,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "--quiet", "file.cpp"};
settings.quiet = false; settings.quiet = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.quiet); ASSERT_EQUALS(true, settings.quiet);
} }
@ -311,28 +311,28 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D"}; const char *argv[] = {"cppcheck", "-D"};
// Fails since -D has no param // Fails since -D has no param
ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
} }
void defines_noarg2() { void defines_noarg2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
// Fails since -D has no param // Fails since -D has no param
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
} }
void defines_noarg3() { void defines_noarg3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
// Fails since -D has no param // Fails since -D has no param
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
} }
void defines() { void defines() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"}; const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"};
settings.userDefines.clear(); settings.userDefines.clear();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS("_WIN32=1", settings.userDefines); ASSERT_EQUALS("_WIN32=1", settings.userDefines);
} }
@ -340,7 +340,7 @@ private:
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();;
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines); ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
} }
@ -348,7 +348,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();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("DEBUG=1", settings.userDefines); ASSERT_EQUALS("DEBUG=1", settings.userDefines);
} }
@ -356,7 +356,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; // #5137 - defining empty macro const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; // #5137 - defining empty macro
settings.userDefines.clear(); settings.userDefines.clear();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS("DEBUG=", settings.userDefines); ASSERT_EQUALS("DEBUG=", settings.userDefines);
} }
@ -365,38 +365,38 @@ private:
{ {
const char *argv[] = {"cppcheck", "file.cpp"}; const char *argv[] = {"cppcheck", "file.cpp"};
settings.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
ASSERT(defParser.ParseFromArgs(2, argv)); ASSERT(defParser.parseFromArgs(2, argv));
ASSERT_EQUALS(Settings::None, settings.enforcedLang); ASSERT_EQUALS(Settings::None, settings.enforcedLang);
} }
{ {
const char *argv[] = {"cppcheck", "-x", "c++", "file.cpp"}; const char *argv[] = {"cppcheck", "-x", "c++", "file.cpp"};
settings.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang); ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
} }
{ {
const char *argv[] = {"cppcheck", "-x"}; const char *argv[] = {"cppcheck", "-x"};
ASSERT(!defParser.ParseFromArgs(2, argv)); ASSERT(!defParser.parseFromArgs(2, argv));
} }
{ {
const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"}; const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"};
ASSERT(!defParser.ParseFromArgs(4, argv)); ASSERT(!defParser.parseFromArgs(4, argv));
} }
{ {
const char *argv[] = {"cppcheck", "--language=c++", "file.cpp"}; const char *argv[] = {"cppcheck", "--language=c++", "file.cpp"};
settings.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang); ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
} }
{ {
const char *argv[] = {"cppcheck", "--language=c", "file.cpp"}; const char *argv[] = {"cppcheck", "--language=c", "file.cpp"};
settings.enforcedLang = Settings::None; settings.enforcedLang = Settings::None;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(Settings::C, settings.enforcedLang); ASSERT_EQUALS(Settings::C, settings.enforcedLang);
} }
{ {
const char *argv[] = {"cppcheck", "--language=unknownLanguage", "file.cpp"}; const char *argv[] = {"cppcheck", "--language=unknownLanguage", "file.cpp"};
ASSERT(!defParser.ParseFromArgs(3, argv)); ASSERT(!defParser.parseFromArgs(3, argv));
} }
} }
@ -404,14 +404,14 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I"}; const char *argv[] = {"cppcheck", "-I"};
// Fails since -I has no param // Fails since -I has no param
ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
} }
void includes() { void includes() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"}; const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"};
settings.includePaths.clear(); settings.includePaths.clear();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings.includePaths.front()); ASSERT_EQUALS("include/", settings.includePaths.front());
} }
@ -419,7 +419,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();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings.includePaths.front()); ASSERT_EQUALS("include/", settings.includePaths.front());
} }
@ -427,7 +427,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();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("include/", settings.includePaths.front()); ASSERT_EQUALS("include/", settings.includePaths.front());
} }
@ -435,7 +435,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"}; const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
settings.includePaths.clear(); settings.includePaths.clear();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS("include/", settings.includePaths.front()); ASSERT_EQUALS("include/", settings.includePaths.front());
} }
@ -443,7 +443,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();
ASSERT(defParser.ParseFromArgs(6, argv)); ASSERT(defParser.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());
@ -454,14 +454,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();
ASSERT_EQUALS(true, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(true, defParser.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();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.isEnabled(Settings::STYLE)); ASSERT(settings.isEnabled(Settings::STYLE));
ASSERT(settings.isEnabled(Settings::WARNING)); ASSERT(settings.isEnabled(Settings::WARNING));
ASSERT(settings.isEnabled(Settings::UNUSED_FUNCTION)); ASSERT(settings.isEnabled(Settings::UNUSED_FUNCTION));
@ -473,7 +473,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.isEnabled(Settings::STYLE)); ASSERT(settings.isEnabled(Settings::STYLE));
ASSERT(settings.isEnabled(Settings::WARNING)); ASSERT(settings.isEnabled(Settings::WARNING));
ASSERT(settings.isEnabled(Settings::PERFORMANCE)); ASSERT(settings.isEnabled(Settings::PERFORMANCE));
@ -486,7 +486,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(!settings.isEnabled(Settings::STYLE)); ASSERT(!settings.isEnabled(Settings::STYLE));
ASSERT(!settings.isEnabled(Settings::WARNING)); ASSERT(!settings.isEnabled(Settings::WARNING));
ASSERT(settings.isEnabled(Settings::PERFORMANCE)); ASSERT(settings.isEnabled(Settings::PERFORMANCE));
@ -499,7 +499,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(!settings.isEnabled(Settings::STYLE)); ASSERT(!settings.isEnabled(Settings::STYLE));
ASSERT(!settings.isEnabled(Settings::WARNING)); ASSERT(!settings.isEnabled(Settings::WARNING));
ASSERT(!settings.isEnabled(Settings::PERFORMANCE)); ASSERT(!settings.isEnabled(Settings::PERFORMANCE));
@ -512,7 +512,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.isEnabled(Settings::UNUSED_FUNCTION)); ASSERT(settings.isEnabled(Settings::UNUSED_FUNCTION));
} }
@ -520,7 +520,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.isEnabled(Settings::MISSING_INCLUDE)); ASSERT(settings.isEnabled(Settings::MISSING_INCLUDE));
} }
@ -529,7 +529,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"}; const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.isEnabled(Settings::INTERNAL)); ASSERT(settings.isEnabled(Settings::INTERNAL));
} }
#endif #endif
@ -538,7 +538,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();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(!settings.isEnabled(Settings::STYLE)); ASSERT(!settings.isEnabled(Settings::STYLE));
ASSERT(settings.isEnabled(Settings::WARNING)); ASSERT(settings.isEnabled(Settings::WARNING));
ASSERT(!settings.isEnabled(Settings::PERFORMANCE)); ASSERT(!settings.isEnabled(Settings::PERFORMANCE));
@ -551,7 +551,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--inconclusive"}; const char *argv[] = {"cppcheck", "--inconclusive"};
settings.inconclusive = false; settings.inconclusive = false;
ASSERT(defParser.ParseFromArgs(2, argv)); ASSERT(defParser.parseFromArgs(2, argv));
ASSERT_EQUALS(true, settings.inconclusive); ASSERT_EQUALS(true, settings.inconclusive);
} }
@ -559,7 +559,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;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(5, settings.exitCode); ASSERT_EQUALS(5, settings.exitCode);
} }
@ -568,7 +568,7 @@ private:
const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"}; const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"};
settings.exitCode = 0; settings.exitCode = 0;
// Fails since exit code not given // Fails since exit code not given
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
} }
void errorExitcodeStr() { void errorExitcodeStr() {
@ -576,7 +576,7 @@ private:
const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"}; const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"};
settings.exitCode = 0; settings.exitCode = 0;
// Fails since invalid exit code // Fails since invalid exit code
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
} }
void exitcodeSuppressionsOld() { void exitcodeSuppressionsOld() {
@ -584,7 +584,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;
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(4, argv)); TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(4, argv));
} }
void exitcodeSuppressions() { void exitcodeSuppressions() {
@ -592,7 +592,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;
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
} }
void exitcodeSuppressionsNoFile() { void exitcodeSuppressionsNoFile() {
@ -600,14 +600,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;
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, defParser.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"};
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(4, argv)); TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(4, argv));
} }
/* void fileListStdin() { /* void fileListStdin() {
@ -615,20 +615,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"};
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
} */ } */
void inlineSuppr() { void inlineSuppr() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"}; const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"};
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
} }
void jobs() { void jobs() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"};
settings.jobs = 0; settings.jobs = 0;
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS(3, settings.jobs); ASSERT_EQUALS(3, settings.jobs);
} }
@ -637,7 +637,7 @@ private:
const char *argv[] = {"cppcheck", "-j", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "file.cpp"};
settings.jobs = 0; settings.jobs = 0;
// Fails since -j is missing thread count // Fails since -j is missing thread count
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
} }
void jobsInvalid() { void jobsInvalid() {
@ -645,7 +645,7 @@ private:
const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"}; const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"};
settings.jobs = 0; settings.jobs = 0;
// Fails since invalid count given for -j // Fails since invalid count given for -j
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
} }
void maxConfigs() { void maxConfigs() {
@ -653,7 +653,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;
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS(12, settings.maxConfigs); ASSERT_EQUALS(12, settings.maxConfigs);
ASSERT_EQUALS(false, settings.force); ASSERT_EQUALS(false, settings.force);
} }
@ -662,28 +662,28 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"};
// Fails since --max-configs= is missing limit // Fails since --max-configs= is missing limit
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
} }
void maxConfigsInvalid() { void maxConfigsInvalid() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"};
// Fails since invalid count given for --max-configs= // Fails since invalid count given for --max-configs=
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
} }
void maxConfigsTooSmall() { void maxConfigsTooSmall() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"}; const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"};
// Fails since limit must be greater than 0 // Fails since limit must be greater than 0
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
} }
void reportProgressTest() { void reportProgressTest() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"}; const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"};
settings.reportProgress = false; settings.reportProgress = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.reportProgress); ASSERT(settings.reportProgress);
} }
@ -691,7 +691,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;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.standards.posix); ASSERT(settings.standards.posix);
} }
@ -699,7 +699,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;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.standards.c == Standards::C99); ASSERT(settings.standards.c == Standards::C99);
} }
@ -707,7 +707,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;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.standards.cpp == Standards::CPP11); ASSERT(settings.standards.cpp == Standards::CPP11);
} }
@ -715,7 +715,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--platform=win64", "file.cpp"}; const char *argv[] = {"cppcheck", "--platform=win64", "file.cpp"};
settings.platform(Settings::Unspecified); settings.platform(Settings::Unspecified);
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.platformType == Settings::Win64); ASSERT(settings.platformType == Settings::Win64);
} }
@ -723,14 +723,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"};
ASSERT(!defParser.ParseFromArgs(4, argv)); ASSERT(!defParser.parseFromArgs(4, argv));
} }
void suppressions() { void suppressions() {
// TODO: Fails because there is no suppr.txt file! // TODO: Fails because there is no suppr.txt file!
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"};
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
} }
void suppressionsNoFile() { void suppressionsNoFile() {
@ -738,21 +738,21 @@ private:
{ {
CLEAR_REDIRECT_OUTPUT; CLEAR_REDIRECT_OUTPUT;
const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(false, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos); ASSERT_EQUALS(false, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
} }
{ {
CLEAR_REDIRECT_OUTPUT; CLEAR_REDIRECT_OUTPUT;
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"};
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos); ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
} }
{ {
CLEAR_REDIRECT_OUTPUT; CLEAR_REDIRECT_OUTPUT;
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"};
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos); ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
} }
} }
@ -769,7 +769,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1))); ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1)));
} }
@ -777,7 +777,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();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U))); ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
} }
@ -785,7 +785,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar,noConstructor", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppress=uninitvar,noConstructor", "file.cpp"};
settings = Settings(); settings = Settings();
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U))); TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U))); TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U)));
} }
@ -794,7 +794,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=noConstructor", "file.cpp"}; const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=noConstructor", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U))); ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U))); ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U)));
} }
@ -803,7 +803,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.templateFormat.clear(); settings.templateFormat.clear();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings.templateFormat); ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings.templateFormat);
} }
@ -811,7 +811,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
settings.templateFormat.clear(); settings.templateFormat.clear();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\\n{code}", settings.templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\\n{code}", settings.templateFormat);
} }
@ -819,7 +819,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
settings.templateFormat.clear(); settings.templateFormat.clear();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings.templateFormat); ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings.templateFormat);
} }
@ -827,7 +827,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"}; const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
settings.templateFormat.clear(); settings.templateFormat.clear();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings.templateFormat); ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings.templateFormat);
} }
@ -836,7 +836,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;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.xml); ASSERT(settings.xml);
ASSERT_EQUALS(1, settings.xml_version); ASSERT_EQUALS(1, settings.xml_version);
} }
@ -846,7 +846,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;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.xml); ASSERT(settings.xml);
ASSERT_EQUALS(2, settings.xml_version); ASSERT_EQUALS(2, settings.xml_version);
} }
@ -856,7 +856,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;
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT(settings.xml); ASSERT(settings.xml);
ASSERT_EQUALS(2, settings.xml_version); ASSERT_EQUALS(2, settings.xml_version);
} }
@ -866,7 +866,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;
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.parseFromArgs(4, argv));
ASSERT(settings.xml); ASSERT(settings.xml);
ASSERT_EQUALS(2, settings.xml_version); ASSERT_EQUALS(2, settings.xml_version);
} }
@ -875,43 +875,43 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"};
// FAils since unknown XML format version // FAils since unknown XML format version
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
} }
void xmlverinvalid() { void xmlverinvalid() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"}; const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"};
// FAils since unknown XML format version // FAils since unknown XML format version
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
} }
void doc() { void doc() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--doc"}; const char *argv[] = {"cppcheck", "--doc"};
ASSERT(defParser.ParseFromArgs(2, argv)); ASSERT(defParser.parseFromArgs(2, argv));
ASSERT(defParser.ExitAfterPrinting()); ASSERT(defParser.exitAfterPrinting());
} }
void showtime() { void showtime() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--showtime=summary"}; const char *argv[] = {"cppcheck", "--showtime=summary"};
settings.showtime = SHOWTIME_NONE; settings.showtime = SHOWTIME_NONE;
ASSERT(defParser.ParseFromArgs(2, argv)); ASSERT(defParser.parseFromArgs(2, argv));
ASSERT(settings.showtime == SHOWTIME_SUMMARY); ASSERT(settings.showtime == SHOWTIME_SUMMARY);
} }
void errorlist1() { void errorlist1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist"}; const char *argv[] = {"cppcheck", "--errorlist"};
ASSERT(defParser.ParseFromArgs(2, argv)); ASSERT(defParser.parseFromArgs(2, argv));
ASSERT(defParser.GetShowErrorMessages()); ASSERT(defParser.getShowErrorMessages());
} }
void errorlistverbose1() { void errorlistverbose1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "--errorlist"}; const char *argv[] = {"cppcheck", "--verbose", "--errorlist"};
settings.verbose = false; settings.verbose = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.verbose); ASSERT(settings.verbose);
} }
@ -919,7 +919,7 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist", "--verbose"}; const char *argv[] = {"cppcheck", "--errorlist", "--verbose"};
settings.verbose = false; settings.verbose = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.verbose); ASSERT(settings.verbose);
} }
@ -928,8 +928,8 @@ private:
const char *argv[] = {"cppcheck", "-i"}; const char *argv[] = {"cppcheck", "-i"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
// Fails since no ignored path given // Fails since no ignored path given
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv)); ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
ASSERT_EQUALS(0, parser.GetIgnoredPaths().size()); ASSERT_EQUALS(0, parser.getIgnoredPaths().size());
} }
/* /*
@ -937,77 +937,77 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-isrc", "file.cpp"}; const char *argv[] = {"cppcheck", "-isrc", "file.cpp"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size()); ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]); ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
} }
void ignorepaths2() { void ignorepaths2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"}; const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.parseFromArgs(4, argv));
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size()); ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]); ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
} }
void ignorepaths3() { void ignorepaths3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"}; const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv)); ASSERT(parser.parseFromArgs(4, argv));
ASSERT_EQUALS(2, parser.GetIgnoredPaths().size()); ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]); ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]); ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]);
} }
*/ */
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"};
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());
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]); ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]); ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]);
} }
/* /*
void ignorefilepaths1() { void ignorefilepaths1() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"}; const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size()); ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("foo.cpp", parser.GetIgnoredPaths()[0]); ASSERT_EQUALS("foo.cpp", parser.getIgnoredPaths()[0]);
} }
*/ */
void ignorefilepaths2() { void ignorefilepaths2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"}; const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(parser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size()); ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/foo.cpp", parser.GetIgnoredPaths()[0]); ASSERT_EQUALS("src/foo.cpp", parser.getIgnoredPaths()[0]);
} }
void checkconfig() { void checkconfig() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--check-config", "file.cpp"}; const char *argv[] = {"cppcheck", "--check-config", "file.cpp"};
settings.checkConfiguration = false; settings.checkConfiguration = false;
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.checkConfiguration); ASSERT_EQUALS(true, settings.checkConfiguration);
} }
void unknownParam() { void unknownParam() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "--foo", "file.cpp"}; const char *argv[] = {"cppcheck", "--foo", "file.cpp"};
ASSERT(!defParser.ParseFromArgs(3, argv)); ASSERT(!defParser.parseFromArgs(3, argv));
} }
void undefs() { void undefs() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"}; const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"};
settings = Settings(); settings = Settings();
ASSERT(defParser.ParseFromArgs(3, argv)); ASSERT(defParser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, settings.userUndefs.size()); ASSERT_EQUALS(1, settings.userUndefs.size());
ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end()); ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end());
} }
@ -1016,7 +1016,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();
ASSERT(defParser.ParseFromArgs(4, argv)); ASSERT(defParser.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());
@ -1026,21 +1026,21 @@ private:
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U"}; const char *argv[] = {"cppcheck", "-U"};
// Fails since -U has no param // Fails since -U has no param
ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
} }
void undefs_noarg2() { void undefs_noarg2() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"}; const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"};
// Fails since -U has no param // Fails since -U has no param
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
} }
void undefs_noarg3() { void undefs_noarg3() {
REDIRECT; REDIRECT;
const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"}; const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"};
// Fails since -U has no param // Fails since -U has no param
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
} }
}; };