From 7ec14e1ea8b439d6a14025509823056ac2b61a6f Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 16 Nov 2023 16:53:49 +0100 Subject: [PATCH] CmdLineParser: return enum from `parseFromArgs()` instead of using additional member --- cli/cmdlineparser.cpp | 147 ++++++------ cli/cmdlineparser.h | 12 +- test/testcmdlineparser.cpp | 448 +++++++++++++++++++------------------ 3 files changed, 304 insertions(+), 303 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 8aa1fb4d22f5..1dd83f5da920 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -143,15 +143,16 @@ CmdLineParser::CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppress bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) { - const bool success = parseFromArgs(argc, argv); + const Result result = parseFromArgs(argc, argv); - if (success) { - if (exitAfterPrinting()) { + switch (result) { + case Result::Success: + break; + case Result::Exit: Settings::terminate(); return true; - } - } else { - return false; + case Result::Fail: + return false; } // Libraries must be loaded before FileLister is executed to ensure markup files will be @@ -279,7 +280,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) // TODO: normalize/simplify/native all path parameters // TODO: error out on all missing given files/paths -bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) +CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const argv[]) { bool def = false; bool maxconfigs = false; @@ -299,7 +300,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-D' is missing."); - return false; + return Result::Fail; } define = argv[i]; @@ -335,7 +336,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-I' is missing."); - return false; + return Result::Fail; } path = argv[i]; } @@ -363,7 +364,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-U' is missing."); - return false; + return Result::Fail; } undef = argv[i]; @@ -404,7 +405,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--checks-max-time=", 18) == 0) { if (!parseNumberArg(argv[i], 18, mSettings.checksMaxTime, true)) - return false; + return Result::Fail; } else if (std::strcmp(argv[i], "--clang") == 0) { @@ -425,7 +426,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string cfgExcludesFile(23 + argv[i]); if (!addPathsToSet(cfgExcludesFile, mSettings.configExcludePaths)) { mLogger.printError("unable to open config excludes file at '" + cfgExcludesFile + "'"); - return false; + return Result::Fail; } } @@ -436,7 +437,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) if (!Path::isDirectory(mSettings.buildDir)) { mLogger.printError("Directory '" + mSettings.buildDir + "' specified by --cppcheck-build-dir argument has to be existent."); - return false; + return Result::Fail; } } @@ -461,12 +462,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string errmsg = mSettings.removeEnabled(argv[i] + 10); if (!errmsg.empty()) { mLogger.printError(errmsg); - return false; + return Result::Fail; } } // documentation.. else if (std::strcmp(argv[i], "--doc") == 0) { + // TODO: make an exclusive option std::ostringstream doc; // Get documentation.. for (const Check * it : Check::instances()) { @@ -478,8 +480,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } mLogger.printRaw(doc.str()); - mExitAfterPrint = true; - return true; + return Result::Exit; } // dump cppcheck data @@ -491,7 +492,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string errmsg = mSettings.addEnabled(enable_arg); if (!errmsg.empty()) { mLogger.printError(errmsg); - return false; + return Result::Fail; } // when "style" is enabled, also enable "warning", "performance" and "portability" if (enable_arg.find("style") != std::string::npos) { @@ -508,7 +509,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) // print all possible error messages.. else if (std::strcmp(argv[i], "--errorlist") == 0) { // TODO: make this an exclusive option - mExitAfterPrint = true; mSettings.loadCppcheckCfg(); { XMLErrorMessagesLogger xmlLogger; @@ -516,13 +516,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) CppCheck::getErrorMessages(xmlLogger); std::cout << ErrorMessage::getXMLFooter() << std::endl; } - return true; + return Result::Exit; } // --error-exitcode=1 else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) { if (!parseNumberArg(argv[i], 17, mSettings.exitCode)) - return false; + return Result::Fail; } // Exception handling inside cppcheck client @@ -541,7 +541,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string exceptionOutfilename = argv[i] + 21; if (exceptionOutfilename != "stderr" && exceptionOutfilename != "stdout") { mLogger.printError("invalid '--exception-handling' argument"); - return false; + return Result::Fail; } mSettings.exceptionHandling = true; CppCheckExecutor::setExceptionOutput((exceptionOutfilename == "stderr") ? stderr : stdout); @@ -559,12 +559,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) std::ifstream f(filename); if (!f.is_open()) { mLogger.printError("couldn't open the file: \"" + filename + "\"."); - return false; + return Result::Fail; } const std::string errmsg(mSuppressionsNoFail.parseFile(f)); if (!errmsg.empty()) { mLogger.printError(errmsg); - return false; + return Result::Fail; } } @@ -578,7 +578,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string fileList = argv[i] + 12; if (!addFilesToList(fileList, mPathNames)) { mLogger.printError("couldn't open the file: \"" + fileList + "\"."); - return false; + return Result::Fail; } } @@ -595,9 +595,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) // Print help else if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) { // TODO: make this an exclusive option - mExitAfterPrint = true; printHelp(); - return true; + return Result::Exit; } // Ignored paths @@ -609,7 +608,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-i' is missing."); - return false; + return Result::Fail; } path = argv[i]; } @@ -642,7 +641,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string includesFile(16 + argv[i]); if (!addIncludePathsToList(includesFile, mSettings.includePaths)) { mLogger.printError("unable to open includes file at '" + includesFile + "'"); - return false; + return Result::Fail; } } @@ -663,7 +662,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-j' is missing."); - return false; + return Result::Fail; } numberString = argv[i]; @@ -677,20 +676,20 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) std::string err; if (!strToInt(numberString, tmp, &err)) { mLogger.printError("argument to '-j' is not valid - " + err + "."); - return false; + return Result::Fail; } if (tmp == 0) { // TODO: implement get CPU logical core count and use that. // Usually, -j 0 would mean "use all available cores," but // if we get a 0, we just stall and don't do any work. mLogger.printError("argument for '-j' must be greater than 0."); - return false; + return Result::Fail; } if (tmp > 1024) { // Almost nobody has 1024 logical cores, but somebody out // there does. mLogger.printError("argument for '-j' is allowed to be 1024 at max."); - return false; + return Result::Fail; } mSettings.jobs = tmp; } @@ -704,7 +703,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-l' is missing."); - return false; + return Result::Fail; } numberString = argv[i]; @@ -718,12 +717,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) std::string err; if (!strToInt(numberString, tmp, &err)) { mLogger.printError("argument to '-l' is not valid - " + err + "."); - return false; + return Result::Fail; } mSettings.loadAverage = tmp; #else mLogger.printError("Option -l cannot be used as Cppcheck has not been built with fork threading model."); - return false; + return Result::Fail; #endif } @@ -736,7 +735,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) i++; if (i >= argc || argv[i][0] == '-') { mLogger.printError("no language given to '-x' option."); - return false; + return Result::Fail; } str = argv[i]; } @@ -747,7 +746,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings.enforcedLang = Settings::Language::CPP; else { mLogger.printError("unknown language '" + str + "' enforced."); - return false; + return Result::Fail; } } @@ -760,10 +759,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--max-configs=", 14) == 0) { int tmp; if (!parseNumberArg(argv[i], 14, tmp)) - return false; + return Result::Fail; if (tmp < 1) { mLogger.printError("argument to '--max-configs=' must be greater than 0."); - return false; + return Result::Fail; } mSettings.maxConfigs = tmp; @@ -774,7 +773,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) // max ctu depth else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0) { if (!parseNumberArg(argv[i], 16, mSettings.maxCtuDepth)) - return false; + return Result::Fail; } // Write results in file @@ -785,12 +784,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) // is always executed. else if (std::strncmp(argv[i], "--performance-valueflow-max-time=", 33) == 0) { if (!parseNumberArg(argv[i], 33, mSettings.performanceValueFlowMaxTime, true)) - return false; + return Result::Fail; } else if (std::strncmp(argv[i], "--performance-valueflow-max-if-count=", 37) == 0) { if (!parseNumberArg(argv[i], 37, mSettings.performanceValueFlowMaxIfCount, true)) - return false; + return Result::Fail; } // Specify platform @@ -801,7 +800,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::vector paths = {argv[0]}; if (!mSettings.platform.set(platform, errstr, paths)) { mLogger.printError(errstr); - return false; + return Result::Fail; } // TODO: remove @@ -825,7 +824,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) message += plistOutput; message += "'."; mLogger.printError(message); - return false; + return Result::Fail; } if (!endsWith(mSettings.plistOutput,'/')) @@ -847,7 +846,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) if (project.projectType != ImportProject::Type::NONE) { mLogger.printError("multiple --project options are not supported."); - return false; + return Result::Fail; } mSettings.checkAllConfigurations = false; // Can be overridden with --max-configs or --force @@ -874,7 +873,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::vector paths = {projectFile, argv[0]}; if (!mSettings.platform.set(platform, errstr, paths)) { mLogger.printError(errstr); - return false; + return Result::Fail; } } @@ -892,15 +891,15 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } if (projType == ImportProject::Type::MISSING) { mLogger.printError("failed to open project '" + projectFile + "'. The file does not exist."); - return false; + return Result::Fail; } if (projType == ImportProject::Type::UNKNOWN) { mLogger.printError("failed to load project '" + projectFile + "'. The format is unknown."); - return false; + return Result::Fail; } if (projType == ImportProject::Type::FAILURE) { mLogger.printError("failed to load project '" + projectFile + "'. An error occurred."); - return false; + return Result::Fail; } } @@ -933,7 +932,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } } else { mLogger.printError("no paths specified for the '" + std::string(argv[i]) + "' option."); - return false; + return Result::Fail; } } @@ -945,7 +944,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--report-progress=", 18) == 0) { int tmp; if (!parseNumberArg(argv[i], 18, tmp, true)) - return false; + return Result::Fail; mSettings.reportProgress = tmp; } @@ -957,7 +956,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings.rules.emplace_back(std::move(rule)); #else mLogger.printError("Option --rule cannot be used as Cppcheck has not been built with rules support."); - return false; + return Result::Fail; #endif } @@ -1003,11 +1002,11 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } } else { mLogger.printError("unable to load rule-file '" + ruleFile + "' (" + tinyxml2::XMLDocument::ErrorIDToName(err) + ")."); - return false; + return Result::Fail; } #else mLogger.printError("Option --rule-file cannot be used as Cppcheck has not been built with rules support."); - return false; + return Result::Fail; #endif } @@ -1032,11 +1031,11 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings.showtime = SHOWTIME_MODES::SHOWTIME_NONE; else if (showtimeMode.empty()) { mLogger.printError("no mode provided for --showtime"); - return false; + return Result::Fail; } else { mLogger.printError("unrecognized --showtime mode: '" + showtimeMode + "'. Supported modes: file, file-total, summary, top5, top5_file, top5_summary."); - return false; + return Result::Fail; } } @@ -1052,7 +1051,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } else { mLogger.printError("unknown --std value '" + std + "'"); - return false; + return Result::Fail; } } @@ -1061,7 +1060,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string errmsg(mSuppressions.addSuppressionLine(suppression)); if (!errmsg.empty()) { mLogger.printError(errmsg); - return false; + return Result::Fail; } } @@ -1083,12 +1082,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } mLogger.printError(message); - return false; + return Result::Fail; } const std::string errmsg(mSuppressions.parseFile(f)); if (!errmsg.empty()) { mLogger.printError(errmsg); - return false; + return Result::Fail; } } @@ -1097,7 +1096,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) const std::string errmsg(mSuppressions.parseXmlFile(filename)); if (!errmsg.empty()) { mLogger.printError(errmsg); - return false; + return Result::Fail; } } @@ -1135,17 +1134,17 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--template-max-time=", 20) == 0) { if (!parseNumberArg(argv[i], 20, mSettings.templateMaxTime)) - return false; + return Result::Fail; } else if (std::strncmp(argv[i], "--typedef-max-time=", 19) == 0) { if (!parseNumberArg(argv[i], 19, mSettings.typedefMaxTime)) - return false; + return Result::Fail; } else if (std::strncmp(argv[i], "--valueflow-max-iterations=", 27) == 0) { if (!parseNumberArg(argv[i], 27, mSettings.valueFlowMaxIterations)) - return false; + return Result::Fail; } else if (std::strcmp(argv[i], "-v") == 0 || std::strcmp(argv[i], "--verbose") == 0) @@ -1153,7 +1152,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strcmp(argv[i], "--version") == 0) { // TODO: make this an exclusive parameter - mExitAfterPrint = true; mSettings.loadCppcheckCfg(); if (!mSettings.cppcheckCfgProductName.empty()) { mLogger.printRaw(mSettings.cppcheckCfgProductName); @@ -1164,7 +1162,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else mLogger.printRaw(std::string("Cppcheck ") + CppCheck::version()); } - return true; + return Result::Exit; } // Write results in results.xml @@ -1175,11 +1173,11 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--xml-version=", 14) == 0) { int tmp; if (!parseNumberArg(argv[i], 14, tmp)) - return false; + return Result::Fail; if (tmp != 2) { // We only have xml version 2 mLogger.printError("'--xml-version' can only be 2."); - return false; + return Result::Fail; } mSettings.xml_version = tmp; @@ -1192,7 +1190,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) message += argv[i]; message += "\"."; mLogger.printError(message); - return false; + return Result::Fail; } } @@ -1229,20 +1227,19 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } if (argc <= 1) { - mExitAfterPrint = true; printHelp(); - return true; + return Result::Exit; } if (!mPathNames.empty() && project.projectType != ImportProject::Type::NONE) { mLogger.printError("--project cannot be used in conjunction with source files."); - return false; + return Result::Fail; } // Print error only if we have "real" command and expect files - if (!mExitAfterPrint && mPathNames.empty() && project.guiProject.pathNames.empty() && project.fileSettings.empty()) { + if (mPathNames.empty() && project.guiProject.pathNames.empty() && project.fileSettings.empty()) { mLogger.printError("no C or C++ source files found."); - return false; + return Result::Fail; } if (!project.guiProject.pathNames.empty()) @@ -1255,7 +1252,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) if (mSettings.basePaths.empty() && mSettings.relativePaths) mSettings.basePaths = mPathNames; - return true; + return Result::Success; } void CmdLineParser::printHelp() const diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index b93716b76bd5..db3bb963890e 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -57,6 +57,8 @@ class CmdLineParser { */ CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions, Suppressions &suppressionsNoFail); + enum class Result { Success, Exit, Fail }; + /** * @brief Parse command line args and fill settings and file lists * from there. @@ -71,7 +73,7 @@ class CmdLineParser { * Parse given command line. * @return true if command line was ok, false if there was an error. */ - bool parseFromArgs(int argc, const char* const argv[]); + Result parseFromArgs(int argc, const char* const argv[]); /** * Return the path names user gave to command line. @@ -94,13 +96,6 @@ class CmdLineParser { return mFileSettings; } - /** - * Return if we should exit after printing version, help etc. - */ - bool exitAfterPrinting() const { - return mExitAfterPrint; - } - /** * Return a list of paths user wants to ignore. */ @@ -164,7 +159,6 @@ class CmdLineParser { Settings &mSettings; Suppressions &mSuppressions; Suppressions &mSuppressionsNoFail; - bool mExitAfterPrint{}; std::string mVSConfig; }; diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index e1bf241aa7fd..dc54eba807ce 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -104,6 +104,18 @@ class TestCmdlineParser : public TestFixture { // TODO: verify that the redirect output is empty } + // add overload so the enums can be compared without a cast + template + bool assertEquals(const char* const filename, const unsigned int linenr, const T& expected, const U& actual) const + { + return TestFixture::assertEquals(filename, linenr, expected, actual); + } + + bool assertEquals(const char* const filename, const unsigned int linenr, const CmdLineParser::Result& expected, const CmdLineParser::Result& actual) const + { + return TestFixture::assertEquals(filename, linenr, static_cast(expected), static_cast(actual)); + } + void run() override { TEST_CASE(nooptions); TEST_CASE(helpshort); @@ -345,11 +357,10 @@ class TestCmdlineParser : public TestFixture { TEST_CASE(cppcheckBuildDirEmpty); } - void nooptions() { REDIRECT; const char * const argv[] = {"cppcheck"}; - ASSERT(parser->parseFromArgs(1, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(1, argv)); ASSERT(startsWith(logger->str(), "Cppcheck - A tool for static C/C++ code analysis")); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -357,7 +368,7 @@ class TestCmdlineParser : public TestFixture { void helpshort() { REDIRECT; const char * const argv[] = {"cppcheck", "-h"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv)); ASSERT(startsWith(logger->str(), "Cppcheck - A tool for static C/C++ code analysis")); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -365,7 +376,7 @@ class TestCmdlineParser : public TestFixture { void helplong() { REDIRECT; const char * const argv[] = {"cppcheck", "--help"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv)); ASSERT(startsWith(logger->str(), "Cppcheck - A tool for static C/C++ code analysis")); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -373,7 +384,7 @@ class TestCmdlineParser : public TestFixture { void version() { REDIRECT; const char * const argv[] = {"cppcheck", "--version"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("Cppcheck 2.13 dev\n", logger->str()); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -385,7 +396,7 @@ class TestCmdlineParser : public TestFixture { "\"productName\": \"The Product\"" "}\n"); const char * const argv[] = {"cppcheck", "--version"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv)); // TODO: somehow the config is not loaded on some systems (void)logger->str(); //ASSERT_EQUALS("The Product\n", logger->str()); // TODO: include version? ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); @@ -396,7 +407,7 @@ class TestCmdlineParser : public TestFixture { void onefile() { REDIRECT; const char * const argv[] = {"cppcheck", "file.cpp"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(2, argv)); ASSERT_EQUALS(1, (int)parser->getPathNames().size()); ASSERT_EQUALS("file.cpp", parser->getPathNames().at(0)); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); @@ -405,7 +416,7 @@ class TestCmdlineParser : public TestFixture { void onepath() { REDIRECT; const char * const argv[] = {"cppcheck", "src"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(2, argv)); ASSERT_EQUALS(1, (int)parser->getPathNames().size()); ASSERT_EQUALS("src", parser->getPathNames().at(0)); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); @@ -414,7 +425,7 @@ class TestCmdlineParser : public TestFixture { void optionwithoutfile() { REDIRECT; const char * const argv[] = {"cppcheck", "-v"}; - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS(0, (int)parser->getPathNames().size()); ASSERT_EQUALS("cppcheck: error: no C or C++ source files found.\n", logger->str()); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); @@ -424,7 +435,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-v", "file.cpp"}; settings->verbose = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->verbose); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -433,7 +444,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--verbose", "file.cpp"}; settings->verbose = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->verbose); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -442,7 +453,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--debug-simplified", "file.cpp"}; settings->debugSimplified = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->debugSimplified); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -451,7 +462,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--debug-warnings", "file.cpp"}; settings->debugwarnings = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->debugwarnings); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -460,7 +471,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-f", "file.cpp"}; settings->force = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->force); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -469,7 +480,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--force", "file.cpp"}; settings->force = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->force); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -478,7 +489,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; settings->relativePaths = false; const char * const argv[] = {"cppcheck", "-rp", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->relativePaths); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -487,7 +498,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; settings->relativePaths = false; const char * const argv[] = {"cppcheck", "--relative-paths", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->relativePaths); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -497,7 +508,7 @@ class TestCmdlineParser : public TestFixture { settings->relativePaths = false; settings->basePaths.clear(); const char * const argv[] = {"cppcheck", "-rp=C:/foo;C:\\bar", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->relativePaths); ASSERT_EQUALS(2, settings->basePaths.size()); ASSERT_EQUALS("C:/foo", settings->basePaths[0]); @@ -511,7 +522,7 @@ class TestCmdlineParser : public TestFixture { settings->basePaths.clear(); const char * const argv[] = {"cppcheck", "--relative-paths=C:/foo;C:\\bar", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->relativePaths); ASSERT_EQUALS(2, settings->basePaths.size()); ASSERT_EQUALS("C:/foo", settings->basePaths[0]); @@ -523,7 +534,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-q", "file.cpp"}; settings->quiet = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->quiet); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -532,7 +543,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--quiet", "file.cpp"}; settings->quiet = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->quiet); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -541,7 +552,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-D"}; // Fails since -D has no param - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-D' is missing.\n", logger->str()); } @@ -549,7 +560,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-D", "-v", "file.cpp"}; // Fails since -D has no param - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-D' is missing.\n", logger->str()); } @@ -557,7 +568,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"}; // Fails since -D has no param - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-D' is missing.\n", logger->str()); } @@ -565,7 +576,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-D_WIN32", "file.cpp"}; settings->userDefines.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("_WIN32=1", settings->userDefines); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -574,7 +585,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"}; settings->userDefines.clear(); - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings->userDefines); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -583,7 +594,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"}; settings->userDefines.clear(); - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("DEBUG=1", settings->userDefines); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -592,7 +603,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; // #5137 - defining empty macro settings->userDefines.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("DEBUG=", settings->userDefines); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -601,7 +612,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "file.cpp"}; settings->enforcedLang = Settings::Language::None; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(2, argv)); ASSERT_EQUALS(Settings::Language::None, settings->enforcedLang); } @@ -609,21 +620,21 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-x", "c++", "file.cpp"}; settings->enforcedLang = Settings::Language::None; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(Settings::Language::CPP, settings->enforcedLang); } void enforceLanguage3() { REDIRECT; const char * const argv[] = {"cppcheck", "-x"}; - ASSERT(!parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: no language given to '-x' option.\n", logger->str()); } void enforceLanguage4() { REDIRECT; const char * const argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"}; - ASSERT(!parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: no language given to '-x' option.\n", logger->str()); } @@ -631,7 +642,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--language=c++", "file.cpp"}; settings->enforcedLang = Settings::Language::None; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Settings::Language::CPP, settings->enforcedLang); } @@ -639,14 +650,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--language=c", "file.cpp"}; settings->enforcedLang = Settings::Language::None; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Settings::Language::C, settings->enforcedLang); } void enforceLanguage7() { REDIRECT; const char * const argv[] = {"cppcheck", "--language=unknownLanguage", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unknown language 'unknownLanguage' enforced.\n", logger->str()); } @@ -654,7 +665,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-I"}; // Fails since -I has no param - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-I' is missing.\n", logger->str()); } @@ -662,7 +673,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-I", "include", "file.cpp"}; settings->includePaths.clear(); - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("include/", settings->includePaths.front()); } @@ -670,7 +681,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-I", "include/", "file.cpp"}; settings->includePaths.clear(); - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("include/", settings->includePaths.front()); } @@ -678,7 +689,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-I", "include\\", "file.cpp"}; settings->includePaths.clear(); - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("include/", settings->includePaths.front()); } @@ -686,7 +697,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-Iinclude", "file.cpp"}; settings->includePaths.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("include/", settings->includePaths.front()); } @@ -694,7 +705,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"}; settings->includePaths.clear(); - ASSERT(parser->parseFromArgs(6, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(6, argv)); ASSERT_EQUALS("include/", settings->includePaths.front()); settings->includePaths.pop_front(); ASSERT_EQUALS("framework/", settings->includePaths.front()); @@ -706,7 +717,7 @@ class TestCmdlineParser : public TestFixture { "path/sub\n" "path2/sub1\n"); const char * const argv[] = {"cppcheck", "--includes-file=includes.txt", "file.cpp"}; - ASSERT_EQUALS(true, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(2, settings->includePaths.size()); auto it = settings->includePaths.cbegin(); ASSERT_EQUALS("path/sub/", *it++); @@ -716,7 +727,7 @@ class TestCmdlineParser : public TestFixture { void includesFileNoFile() { REDIRECT; const char * const argv[] = {"cppcheck", "--includes-file=fileThatDoesNotExist.txt", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unable to open includes file at 'fileThatDoesNotExist.txt'\n", logger->str()); } @@ -727,7 +738,7 @@ class TestCmdlineParser : public TestFixture { "path2/sub1\n"); const char * const argv[] = {"cppcheck", "--config-excludes-file=excludes.txt", "file.cpp"}; settings->configExcludePaths.clear(); - ASSERT_EQUALS(true, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(2, settings->configExcludePaths.size()); auto it = settings->configExcludePaths.cbegin(); ASSERT_EQUALS("path/sub/", *it++); @@ -737,14 +748,14 @@ class TestCmdlineParser : public TestFixture { void configExcludesFileNoFile() { REDIRECT; const char * const argv[] = {"cppcheck", "--config-excludes-file=fileThatDoesNotExist.txt", "file.cpp"}; - ASSERT_EQUALS( false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unable to open config excludes file at 'fileThatDoesNotExist.txt'\n", logger->str()); } void enabledAll() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=all", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->severity.isEnabled(Severity::style)); ASSERT(settings->severity.isEnabled(Severity::warning)); ASSERT(settings->checks.isEnabled(Checks::unusedFunction)); @@ -755,7 +766,7 @@ class TestCmdlineParser : public TestFixture { void enabledStyle() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=style", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->severity.isEnabled(Severity::style)); ASSERT(settings->severity.isEnabled(Severity::warning)); ASSERT(settings->severity.isEnabled(Severity::performance)); @@ -767,7 +778,7 @@ class TestCmdlineParser : public TestFixture { void enabledPerformance() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=performance", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(!settings->severity.isEnabled(Severity::style)); ASSERT(!settings->severity.isEnabled(Severity::warning)); ASSERT(settings->severity.isEnabled(Severity::performance)); @@ -779,7 +790,7 @@ class TestCmdlineParser : public TestFixture { void enabledPortability() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=portability", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(!settings->severity.isEnabled(Severity::style)); ASSERT(!settings->severity.isEnabled(Severity::warning)); ASSERT(!settings->severity.isEnabled(Severity::performance)); @@ -791,7 +802,7 @@ class TestCmdlineParser : public TestFixture { void enabledInformation() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=information", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->severity.isEnabled(Severity::information)); ASSERT(settings->checks.isEnabled(Checks::missingInclude)); ASSERT_EQUALS("cppcheck: '--enable=information' will no longer implicitly enable 'missingInclude' starting with 2.16. Please enable it explicitly if you require it.\n", logger->str()); @@ -800,14 +811,14 @@ class TestCmdlineParser : public TestFixture { void enabledUnusedFunction() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->checks.isEnabled(Checks::unusedFunction)); } void enabledMissingInclude() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->checks.isEnabled(Checks::missingInclude)); } @@ -815,7 +826,7 @@ class TestCmdlineParser : public TestFixture { void enabledInternal() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=internal", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->checks.isEnabled(Checks::internalCheck)); } #endif @@ -823,7 +834,7 @@ class TestCmdlineParser : public TestFixture { void enabledMultiple() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=missingInclude,portability,warning", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(!settings->severity.isEnabled(Severity::style)); ASSERT(settings->severity.isEnabled(Severity::warning)); ASSERT(!settings->severity.isEnabled(Severity::performance)); @@ -835,21 +846,21 @@ class TestCmdlineParser : public TestFixture { void enabledInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=warning,missingIncludeSystem,style", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: --enable parameter with the unknown name 'missingIncludeSystem'\n", logger->str()); } void enabledError() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=error", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: --enable parameter with the unknown name 'error'\n", logger->str()); } void enabledEmpty() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: --enable parameter is empty\n", logger->str()); } @@ -859,7 +870,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--enable=all", "--disable=all", "file.cpp"}; settings->severity.clear(); settings->checks.clear(); - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(true, settings->severity.isEnabled(Severity::error)); ASSERT_EQUALS(false, settings->severity.isEnabled(Severity::warning)); ASSERT_EQUALS(false, settings->severity.isEnabled(Severity::style)); @@ -876,7 +887,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--enable=all", "--disable=style", "--disable=unusedFunction", "file.cpp"}; settings->severity.clear(); settings->checks.clear(); - ASSERT(parser->parseFromArgs(5, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(5, argv)); ASSERT_EQUALS(true, settings->severity.isEnabled(Severity::error)); ASSERT_EQUALS(true, settings->severity.isEnabled(Severity::warning)); ASSERT_EQUALS(false, settings->severity.isEnabled(Severity::style)); @@ -894,7 +905,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--enable=style", "--disable=performance", "--enable=unusedFunction", "file.cpp"}; settings->severity.clear(); settings->checks.clear(); - ASSERT(parser->parseFromArgs(5, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(5, argv)); ASSERT_EQUALS(true, settings->severity.isEnabled(Severity::error)); ASSERT_EQUALS(true, settings->severity.isEnabled(Severity::warning)); ASSERT_EQUALS(true, settings->severity.isEnabled(Severity::style)); @@ -909,7 +920,7 @@ class TestCmdlineParser : public TestFixture { void disableInformationPartial() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=information", "--disable=missingInclude", "file.cpp"}; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT(settings->severity.isEnabled(Severity::information)); ASSERT(!settings->checks.isEnabled(Checks::missingInclude)); ASSERT_EQUALS("cppcheck: '--enable=information' will no longer implicitly enable 'missingInclude' starting with 2.16. Please enable it explicitly if you require it.\n", logger->str()); @@ -918,7 +929,7 @@ class TestCmdlineParser : public TestFixture { void disableInformationPartial2() { REDIRECT; const char * const argv[] = {"cppcheck", "--enable=missingInclude", "--disable=information", "file.cpp"}; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT(!settings->severity.isEnabled(Severity::information)); ASSERT(settings->checks.isEnabled(Checks::missingInclude)); } @@ -926,21 +937,21 @@ class TestCmdlineParser : public TestFixture { void disableInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--disable=leaks", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: --disable parameter with the unknown name 'leaks'\n", logger->str()); } void disableError() { REDIRECT; const char * const argv[] = {"cppcheck", "--disable=error", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: --disable parameter with the unknown name 'error'\n", logger->str()); } void disableEmpty() { REDIRECT; const char * const argv[] = {"cppcheck", "--disable=", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: --disable parameter is empty\n", logger->str()); } @@ -948,7 +959,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--inconclusive", "file.cpp"}; settings->certainty.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->certainty.isEnabled(Certainty::inconclusive)); } @@ -956,7 +967,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"}; settings->exitCode = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(5, settings->exitCode); } @@ -964,7 +975,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"}; // Fails since exit code not given - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--error-exitcode=' is not valid - not an integer.\n", logger->str()); } @@ -972,14 +983,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"}; // Fails since invalid exit code - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--error-exitcode=' is not valid - not an integer.\n", logger->str()); } void exitcodeSuppressionsOld() { REDIRECT; const char * const argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--exitcode-suppressions\".\n", logger->str()); } @@ -989,7 +1000,7 @@ class TestCmdlineParser : public TestFixture { "uninitvar\n" "unusedFunction\n"); const char * const argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"}; - ASSERT_EQUALS(true, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(2, settings->nofail.getSuppressions().size()); auto it = settings->nofail.getSuppressions().cbegin(); ASSERT_EQUALS("uninitvar", (it++)->errorId); @@ -999,7 +1010,7 @@ class TestCmdlineParser : public TestFixture { void exitcodeSuppressionsNoFile() { REDIRECT; const char * const argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--exitcode-suppressions\".\n", logger->str()); } @@ -1009,7 +1020,7 @@ class TestCmdlineParser : public TestFixture { "file1.c\n" "file2.cpp\n"); const char * const argv[] = {"cppcheck", "--file-list=files.txt", "file.cpp"}; - ASSERT_EQUALS(true, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(3, parser->getPathNames().size()); auto it = parser->getPathNames().cbegin(); ASSERT_EQUALS("file1.c", *it++); @@ -1020,7 +1031,7 @@ class TestCmdlineParser : public TestFixture { void fileListNoFile() { REDIRECT; const char * const argv[] = {"cppcheck", "--file-list=files.txt", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: couldn't open the file: \"files.txt\".\n", logger->str()); } @@ -1035,7 +1046,7 @@ class TestCmdlineParser : public TestFixture { void fileListInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--file-list\".\n", logger->str()); } @@ -1043,7 +1054,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--inline-suppr", "file.cpp"}; settings->inlineSuppressions = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->inlineSuppressions); } @@ -1051,7 +1062,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-j", "3", "file.cpp"}; settings->jobs = 0; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(3, settings->jobs); } @@ -1059,7 +1070,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-j3", "file.cpp"}; settings->jobs = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(3, settings->jobs); } @@ -1067,7 +1078,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-j", "file.cpp"}; // Fails since -j is missing thread count - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-j' is not valid - not an integer.\n", logger->str()); } @@ -1075,21 +1086,21 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-j", "e", "file.cpp"}; // Fails since invalid count given for -j - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-j' is not valid - not an integer.\n", logger->str()); } void jobsNoJobs() { REDIRECT; const char * const argv[] = {"cppcheck", "-j0", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument for '-j' must be greater than 0.\n", logger->str()); } void jobsTooBig() { REDIRECT; const char * const argv[] = {"cppcheck", "-j1025", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument for '-j' is allowed to be 1024 at max.\n", logger->str()); } @@ -1098,7 +1109,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"}; settings->force = false; settings->maxConfigs = 0; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(12, settings->maxConfigs); ASSERT_EQUALS(false, settings->force); } @@ -1107,7 +1118,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--max-configs=", "file.cpp"}; // Fails since --max-configs= is missing limit - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--max-configs=' is not valid - not an integer.\n", logger->str()); } @@ -1115,7 +1126,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--max-configs=e", "file.cpp"}; // Fails since invalid count given for --max-configs= - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--max-configs=' is not valid - not an integer.\n", logger->str()); } @@ -1123,7 +1134,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--max-configs=0", "file.cpp"}; // Fails since limit must be greater than 0 - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--max-configs=' must be greater than 0.\n", logger->str()); } @@ -1131,7 +1142,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--report-progress", "file.cpp"}; settings->reportProgress = -1; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(10, settings->reportProgress); } @@ -1139,7 +1150,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--report-progress=", "file.cpp"}; settings->reportProgress = -1; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--report-progress=' is not valid - not an integer.\n", logger->str()); } @@ -1147,7 +1158,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--report-progress=-1", "file.cpp"}; settings->reportProgress = -1; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--report-progress=' needs to be a positive integer.\n", logger->str()); } @@ -1155,7 +1166,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--report-progress=0", "file.cpp"}; settings->reportProgress = -1; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(0, settings->reportProgress); } @@ -1163,7 +1174,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--report-progress=1", "file.cpp"}; settings->reportProgress = -1; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, settings->reportProgress); } @@ -1171,7 +1182,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--std=c99", "file.cpp"}; settings->standards.c = Standards::C89; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->standards.c == Standards::C99); } @@ -1179,21 +1190,21 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--std=c++11", "file.cpp"}; settings->standards.cpp = Standards::CPP03; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->standards.cpp == Standards::CPP11); } void stdunknown1() { REDIRECT; const char *const argv[] = {"cppcheck", "--std=d++11", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unknown --std value 'd++11'\n", logger->str()); } void stdunknown2() { REDIRECT; const char *const argv[] = {"cppcheck", "--std=cplusplus11", "file.cpp"}; - TODO_ASSERT(!parser->parseFromArgs(3, argv)); + TODO_ASSERT_EQUALS(static_cast(CmdLineParser::Result::Fail), static_cast(CmdLineParser::Result::Success), static_cast(parser->parseFromArgs(3, argv))); TODO_ASSERT_EQUALS("cppcheck: error: unknown --std value 'cplusplus11'\n", "", logger->str()); } @@ -1201,7 +1212,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=win64", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Win64, settings->platform.type); } @@ -1209,7 +1220,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=win32A", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Win32A, settings->platform.type); } @@ -1217,7 +1228,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=win32W", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Win32W, settings->platform.type); } @@ -1225,7 +1236,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix32", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Unix32, settings->platform.type); } @@ -1233,7 +1244,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix32-unsigned", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Unix32, settings->platform.type); } @@ -1241,7 +1252,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix64", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Unix64, settings->platform.type); } @@ -1249,7 +1260,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix64-unsigned", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Unix64, settings->platform.type); } @@ -1257,7 +1268,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=native", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Native, settings->platform.type); } @@ -1265,7 +1276,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unspecified", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Native)); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::Unspecified, settings->platform.type); } @@ -1273,14 +1284,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=avr8", "file.cpp"}; ASSERT(settings->platform.set(Platform::Type::Unspecified)); - ASSERT_EQUALS(true, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(Platform::Type::File, settings->platform.type); } void platformUnknown() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=win128", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized platform: 'win128'.\n", logger->str()); } @@ -1288,7 +1299,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--plist-output=", "file.cpp"}; settings->plistOutput = ""; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->plistOutput == "./"); } @@ -1296,14 +1307,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--plist-output=./cppcheck_reports", "file.cpp"}; // Fails since folder pointed by --plist-output= does not exist - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: plist folder does not exist: 'cppcheck_reports'.\n", logger->str()); } void suppressionsOld() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppressions", "suppr.txt", "file.cpp"}; - ASSERT(!parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--suppressions\".\n", logger->str()); } @@ -1313,7 +1324,7 @@ class TestCmdlineParser : public TestFixture { "uninitvar\n" "unusedFunction\n"); const char * const argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"}; - ASSERT_EQUALS(true, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(2, settings->nomsg.getSuppressions().size()); auto it = settings->nomsg.getSuppressions().cbegin(); ASSERT_EQUALS("uninitvar", (it++)->errorId); @@ -1323,21 +1334,21 @@ class TestCmdlineParser : public TestFixture { void suppressionsNoFile1() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(false, logger->str().find("If you want to pass two files") != std::string::npos); } void suppressionsNoFile2() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, logger->str().find("If you want to pass two files") != std::string::npos); } void suppressionsNoFile3() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"}; - ASSERT_EQUALS(false, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, logger->str().find("If you want to pass two files") != std::string::npos); } @@ -1352,21 +1363,21 @@ class TestCmdlineParser : public TestFixture { void suppressionSingle() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1))); } void suppressionSingleFile() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U))); } void suppressionTwo() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppress=uninitvar,noConstructor", "file.cpp"}; - TODO_ASSERT_EQUALS(true, false, parser->parseFromArgs(3, argv)); + TODO_ASSERT_EQUALS(static_cast(CmdLineParser::Result::Success), static_cast(CmdLineParser::Result::Fail), static_cast(parser->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("noConstructor", "file.cpp", 1U))); TODO_ASSERT_EQUALS("", "cppcheck: error: Failed to add suppression. Invalid id \"uninitvar,noConstructor\"\n", logger->str()); @@ -1375,7 +1386,7 @@ class TestCmdlineParser : public TestFixture { void suppressionTwoSeparate() { REDIRECT; const char * const argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=noConstructor", "file.cpp"}; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(true, settings->nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U))); ASSERT_EQUALS(true, settings->nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U))); } @@ -1385,7 +1396,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template={file}:{line},{severity},{id},{message}", "--template-location={file}:{line}:{column} {info}", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column} {info}", settings->templateLocation); } @@ -1395,7 +1406,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template=gcc", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\n{code}", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation); } @@ -1405,7 +1416,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template=vs", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings->templateFormat); ASSERT_EQUALS("", settings->templateLocation); } @@ -1415,7 +1426,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template=edit", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings->templateFormat); ASSERT_EQUALS("", settings->templateLocation); } @@ -1425,7 +1436,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template=cppcheck1", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{callstack}: ({severity}{inconclusive:, inconclusive}) {message}", settings->templateFormat); ASSERT_EQUALS("", settings->templateLocation); } @@ -1435,7 +1446,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template=daca2", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: note: {info}", settings->templateLocation); ASSERT_EQUALS(true, settings->daca); @@ -1446,7 +1457,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template=selfcheck", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\n{code}", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation); } @@ -1457,7 +1468,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--template=selfchek", "file.cpp"}; settings->templateFormat.clear(); settings->templateLocation.clear(); - TODO_ASSERT(!parser->parseFromArgs(3, argv)); + TODO_ASSERT_EQUALS(static_cast(CmdLineParser::Result::Fail), static_cast(CmdLineParser::Result::Success), static_cast(parser->parseFromArgs(3, argv))); ASSERT_EQUALS("selfchek", settings->templateFormat); ASSERT_EQUALS("", settings->templateLocation); } @@ -1467,7 +1478,7 @@ class TestCmdlineParser : public TestFixture { settings->templateFormat.clear(); settings->templateLocation.clear(); const char* const argv[] = { "cppcheck", "--template", "file.cpp" }; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template\".\n", logger->str()); } @@ -1478,7 +1489,7 @@ class TestCmdlineParser : public TestFixture { settings->templateFormat.clear(); settings->templateLocation.clear(); const char* const argv[] = { "cppcheck", "--template=", "file.cpp" }; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation); } @@ -1486,7 +1497,7 @@ class TestCmdlineParser : public TestFixture { void templateLocationInvalid() { REDIRECT; const char* const argv[] = { "cppcheck", "--template-location", "--template={file}", "file.cpp" }; - ASSERT(!parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template-location\".\n", logger->str()); } @@ -1497,7 +1508,7 @@ class TestCmdlineParser : public TestFixture { settings->templateFormat.clear(); settings->templateLocation.clear(); const char* const argv[] = { "cppcheck", "--template-location=", "file.cpp" }; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation); } @@ -1507,7 +1518,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--xml", "file.cpp"}; settings->xml_version = 1; settings->xml = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->xml); ASSERT_EQUALS(1, settings->xml_version); } @@ -1517,7 +1528,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--xml-version=2", "file.cpp"}; settings->xml_version = 1; settings->xml = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->xml); ASSERT_EQUALS(2, settings->xml_version); } @@ -1527,7 +1538,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"}; settings->xml_version = 1; settings->xml = false; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT(settings->xml); ASSERT_EQUALS(2, settings->xml_version); } @@ -1537,7 +1548,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"}; settings->xml_version = 1; settings->xml = false; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT(settings->xml); ASSERT_EQUALS(2, settings->xml_version); } @@ -1546,7 +1557,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"}; // FAils since unknown XML format version - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: '--xml-version' can only be 2.\n", logger->str()); } @@ -1554,15 +1565,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"}; // FAils since unknown XML format version - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--xml-version=' is not valid - not an integer.\n", logger->str()); } void doc() { REDIRECT; const char * const argv[] = {"cppcheck", "--doc"}; - ASSERT(parser->parseFromArgs(2, argv)); - ASSERT(parser->exitAfterPrinting()); + ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv)); ASSERT(startsWith(logger->str(), "## ")); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -1571,7 +1581,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=summary", "file.cpp"}; settings->showtime = SHOWTIME_MODES::SHOWTIME_NONE; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_SUMMARY); } @@ -1579,7 +1589,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=file", "file.cpp"}; settings->showtime = SHOWTIME_MODES::SHOWTIME_NONE; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_FILE); } @@ -1587,7 +1597,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=file-total", "file.cpp"}; settings->showtime = SHOWTIME_MODES::SHOWTIME_NONE; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL); } @@ -1595,7 +1605,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=top5", "file.cpp"}; settings->showtime = SHOWTIME_MODES::SHOWTIME_NONE; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_TOP5_FILE); ASSERT_EQUALS("cppcheck: --showtime=top5 is deprecated and will be removed in Cppcheck 2.14. Please use --showtime=top5_file or --showtime=top5_summary instead.\n", logger->str()); } @@ -1604,7 +1614,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=top5_file", "file.cpp"}; settings->showtime = SHOWTIME_MODES::SHOWTIME_NONE; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_TOP5_FILE); } @@ -1612,7 +1622,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=top5_summary", "file.cpp"}; settings->showtime = SHOWTIME_MODES::SHOWTIME_NONE; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY); } @@ -1620,28 +1630,28 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=none", "file.cpp"}; settings->showtime = SHOWTIME_MODES::SHOWTIME_FILE; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_NONE); } void showtimeEmpty() { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: no mode provided for --showtime\n", logger->str()); } void showtimeInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--showtime=top10", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized --showtime mode: 'top10'. Supported modes: file, file-total, summary, top5, top5_file, top5_summary.\n", logger->str()); } void errorlist() { REDIRECT; const char * const argv[] = {"cppcheck", "--errorlist"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("", logger->str()); // empty since it is logged via ErrorLogger ASSERT(startsWith(GET_REDIRECT_OUTPUT, "\n")); @@ -1653,7 +1663,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-i"}; // Fails since no ignored path given - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-i' is missing.\n", logger->str()); } @@ -1663,7 +1673,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--exception-handling", "file.cpp"}; settings->exceptionHandling = false; CppCheckExecutor::setExceptionOutput(stderr); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->exceptionHandling); ASSERT_EQUALS(stderr, CppCheckExecutor::getExceptionOutput()); } @@ -1673,7 +1683,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--exception-handling=stderr", "file.cpp"}; settings->exceptionHandling = false; CppCheckExecutor::setExceptionOutput(stdout); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->exceptionHandling); ASSERT_EQUALS(stderr, CppCheckExecutor::getExceptionOutput()); } @@ -1683,7 +1693,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--exception-handling=stdout", "file.cpp"}; settings->exceptionHandling = false; CppCheckExecutor::setExceptionOutput(stderr); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->exceptionHandling); ASSERT_EQUALS(stdout, CppCheckExecutor::getExceptionOutput()); } @@ -1691,28 +1701,28 @@ class TestCmdlineParser : public TestFixture { void exceptionhandlingInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--exception-handling=exfile"}; - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: invalid '--exception-handling' argument\n", logger->str()); } void exceptionhandlingInvalid2() { REDIRECT; const char * const argv[] = {"cppcheck", "--exception-handling-foo"}; - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--exception-handling-foo\".\n", logger->str()); } #else void exceptionhandlingNotSupported() { REDIRECT; const char * const argv[] = {"cppcheck", "--exception-handling", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: Option --exception-handling is not supported since Cppcheck has not been built with any exception handling enabled.\n", logger->str()); } void exceptionhandlingNotSupported2() { REDIRECT; const char * const argv[] = {"cppcheck", "--exception-handling=stderr", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: Option --exception-handling is not supported since Cppcheck has not been built with any exception handling enabled.\n", logger->str()); } #endif @@ -1722,7 +1732,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--clang", "file.cpp"}; settings->clang = false; settings->clangExecutable = "exe"; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->clang); ASSERT_EQUALS("exe", settings->clangExecutable); } @@ -1732,7 +1742,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--clang=clang-14", "file.cpp"}; settings->clang = false; settings->clangExecutable = ""; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->clang); ASSERT_EQUALS("clang-14", settings->clangExecutable); } @@ -1740,7 +1750,7 @@ class TestCmdlineParser : public TestFixture { void clangInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--clang-foo"}; - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--clang-foo\".\n", logger->str()); } @@ -1748,7 +1758,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--valueflow-max-iterations=0", "file.cpp"}; settings->valueFlowMaxIterations = SIZE_MAX; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(0, settings->valueFlowMaxIterations); } @@ -1756,28 +1766,28 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--valueflow-max-iterations=11", "file.cpp"}; settings->valueFlowMaxIterations = SIZE_MAX; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(11, settings->valueFlowMaxIterations); } void valueFlowMaxIterationsInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--valueflow-max-iterations"}; - ASSERT(!parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--valueflow-max-iterations\".\n", logger->str()); } void valueFlowMaxIterationsInvalid2() { REDIRECT; const char * const argv[] = {"cppcheck", "--valueflow-max-iterations=seven"}; - ASSERT(!parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--valueflow-max-iterations=' is not valid - not an integer.\n", logger->str()); } void valueFlowMaxIterationsInvalid3() { REDIRECT; const char * const argv[] = {"cppcheck", "--valueflow-max-iterations=-1"}; - ASSERT(!parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--valueflow-max-iterations=' is not valid - needs to be positive.\n", logger->str()); } @@ -1785,21 +1795,21 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--checks-max-time=12", "file.cpp"}; settings->checksMaxTime = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(12, settings->checksMaxTime); } void checksMaxTime2() { REDIRECT; const char * const argv[] = {"cppcheck", "--checks-max-time=-1", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--checks-max-time=' needs to be a positive integer.\n", logger->str()); } void checksMaxTimeInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--checks-max-time=one", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--checks-max-time=' is not valid - not an integer.\n", logger->str()); } @@ -1808,7 +1818,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-l", "12", "file.cpp"}; settings->loadAverage = 0; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(12, settings->loadAverage); } @@ -1816,21 +1826,21 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-l12", "file.cpp"}; settings->loadAverage = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(12, settings->loadAverage); } void loadAverageInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "-l", "one", "file.cpp"}; - ASSERT(!parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-l' is not valid - not an integer.\n", logger->str()); } #else void loadAverageNotSupported() { REDIRECT; const char * const argv[] = {"cppcheck", "-l", "12", "file.cpp"}; - ASSERT(!parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: Option -l cannot be used as Cppcheck has not been built with fork threading model.\n", logger->str()); } #endif @@ -1839,14 +1849,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--max-ctu-depth=12", "file.cpp"}; settings->maxCtuDepth = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(12, settings->maxCtuDepth); } void maxCtuDepthInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--max-ctu-depth=one", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--max-ctu-depth=' is not valid - not an integer.\n", logger->str()); } @@ -1854,14 +1864,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--performance-valueflow-max-time=12", "file.cpp"}; settings->performanceValueFlowMaxTime = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(12, settings->performanceValueFlowMaxTime); } void performanceValueflowMaxTimeInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--performance-valueflow-max-time=one", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--performance-valueflow-max-time=' is not valid - not an integer.\n", logger->str()); } @@ -1869,14 +1879,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--performance-valueflow-max-if-count=12", "file.cpp"}; settings->performanceValueFlowMaxIfCount = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(12, settings->performanceValueFlowMaxIfCount); } void performanceValueFlowMaxIfCountInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--performance-valueflow-max-if-count=one", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--performance-valueflow-max-if-count=' is not valid - not an integer.\n", logger->str()); } @@ -1884,21 +1894,21 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--template-max-time=12", "file.cpp"}; settings->templateMaxTime = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(12, settings->templateMaxTime); } void templateMaxTimeInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--template-max-time=one", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--template-max-time=' is not valid - not an integer.\n", logger->str()); } void templateMaxTimeInvalid2() { REDIRECT; const char * const argv[] = {"cppcheck", "--template-max-time=-1", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--template-max-time=' is not valid - needs to be positive.\n", logger->str()); } @@ -1906,7 +1916,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--typedef-max-time=12", "file.cpp"}; settings->typedefMaxTime = 0; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(12, settings->typedefMaxTime); ASSERT_EQUALS("", logger->str()); } @@ -1914,14 +1924,14 @@ class TestCmdlineParser : public TestFixture { void typedefMaxTimeInvalid() { REDIRECT; const char * const argv[] = {"cppcheck", "--typedef-max-time=one", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--typedef-max-time=' is not valid - not an integer.\n", logger->str()); } void typedefMaxTimeInvalid2() { REDIRECT; const char * const argv[] = {"cppcheck", "--typedef-max-time=-1", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: argument to '--typedef-max-time=' is not valid - needs to be positive.\n", logger->str()); } @@ -1934,7 +1944,7 @@ class TestCmdlineParser : public TestFixture { "\n" ""); const char * const argv[] = {"cppcheck", "--project=project.cppcheck"}; - ASSERT(parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(2, argv)); ASSERT_EQUALS(1, parser->getPathNames().size()); auto it = parser->getPathNames().cbegin(); ASSERT_EQUALS("dir", *it); @@ -1944,7 +1954,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; ScopedFile file("project.cppcheck", ""); const char * const argv[] = {"cppcheck", "--project=project.cppcheck", "--project=project.cppcheck", "file.cpp"}; - ASSERT(!parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: multiple --project options are not supported.\n", logger->str()); } @@ -1952,28 +1962,28 @@ class TestCmdlineParser : public TestFixture { REDIRECT; ScopedFile file("project.cppcheck", ""); const char * const argv[] = {"cppcheck", "--project=project.cppcheck", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: --project cannot be used in conjunction with source files.\n", logger->str()); } void projectEmpty() { REDIRECT; const char * const argv[] = {"cppcheck", "--project=", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: failed to open project ''. The file does not exist.\n", logger->str()); } void projectMissing() { REDIRECT; const char * const argv[] = {"cppcheck", "--project=project.cppcheck", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: failed to open project 'project.cppcheck'. The file does not exist.\n", logger->str()); } void projectNoPaths() { ScopedFile file("project.cppcheck", ""); const char * const argv[] = {"cppcheck", "--project=project.cppcheck"}; - ASSERT(!parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: no C or C++ source files found.\n", logger->str()); } @@ -1981,7 +1991,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--addon=misra", "file.cpp"}; settings->addons.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, settings->addons.size()); ASSERT_EQUALS("misra", *settings->addons.cbegin()); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); @@ -2002,7 +2012,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--fsigned-char", "file.cpp"}; settings->platform.defaultSign = '\0'; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS('s', settings->platform.defaultSign); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -2011,7 +2021,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=avr8", "--fsigned-char", "file.cpp"}; settings->platform.defaultSign = '\0'; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS('s', settings->platform.defaultSign); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -2020,7 +2030,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--funsigned-char", "file.cpp"}; settings->platform.defaultSign = '\0'; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS('u', settings->platform.defaultSign); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -2029,7 +2039,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=mips32", "--funsigned-char", "file.cpp"}; settings->platform.defaultSign = '\0'; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS('u', settings->platform.defaultSign); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -2038,7 +2048,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--fsigned-char", "--funsigned-char", "file.cpp"}; settings->platform.defaultSign = '\0'; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS('u', settings->platform.defaultSign); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); } @@ -2047,7 +2057,7 @@ class TestCmdlineParser : public TestFixture { void rule() { REDIRECT; const char * const argv[] = {"cppcheck", "--rule=.+", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, settings->rules.size()); auto it = settings->rules.cbegin(); ASSERT_EQUALS(".+", it->pattern); @@ -2056,7 +2066,7 @@ class TestCmdlineParser : public TestFixture { void ruleNotSupported() { REDIRECT; const char * const argv[] = {"cppcheck", "--rule=.+", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: Option --rule cannot be used as Cppcheck has not been built with rules support.\n", logger->str()); } #endif @@ -2071,7 +2081,7 @@ class TestCmdlineParser : public TestFixture { "\n" ""); const char * const argv[] = {"cppcheck", "--rule-file=rule.xml", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, settings->rules.size()); auto it = settings->rules.cbegin(); ASSERT_EQUALS(".+", it->pattern); @@ -2080,14 +2090,14 @@ class TestCmdlineParser : public TestFixture { void ruleFileEmpty() { REDIRECT; const char * const argv[] = {"cppcheck", "--rule-file=", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unable to load rule-file '' (XML_ERROR_FILE_NOT_FOUND).\n", logger->str()); } void ruleFileMissing() { REDIRECT; const char * const argv[] = {"cppcheck", "--rule-file=rule.xml", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unable to load rule-file 'rule.xml' (XML_ERROR_FILE_NOT_FOUND).\n", logger->str()); } @@ -2095,14 +2105,14 @@ class TestCmdlineParser : public TestFixture { REDIRECT; ScopedFile file("rule.xml", ""); const char * const argv[] = {"cppcheck", "--rule-file=rule.xml", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unable to load rule-file 'rule.xml' (XML_ERROR_EMPTY_DOCUMENT).\n", logger->str()); } #else void ruleFileNotSupported() { REDIRECT; const char * const argv[] = {"cppcheck", "--rule-file=rule.xml", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: Option --rule-file cannot be used as Cppcheck has not been built with rules support.\n", logger->str()); } #endif @@ -2111,7 +2121,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--library=posix", "file.cpp"}; settings->libraries.clear(); - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, settings->libraries.size()); ASSERT_EQUALS("posix", *settings->libraries.cbegin()); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); @@ -2121,7 +2131,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--library=posix2", "file.cpp"}; settings->libraries.clear(); - ASSERT(!parser->fillSettingsFromArgs(3, argv)); + ASSERT_EQUALS(false, parser->fillSettingsFromArgs(3, argv)); ASSERT_EQUALS(1, settings->libraries.size()); ASSERT_EQUALS("posix2", *settings->libraries.cbegin()); ASSERT_EQUALS("cppcheck: Failed to load library configuration file 'posix2'. File not found\n", logger->str()); @@ -2131,7 +2141,7 @@ class TestCmdlineParser : public TestFixture { void ignorepaths1() { REDIRECT; const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, parser->getIgnoredPaths().size()); ASSERT_EQUALS("src", parser->getIgnoredPaths()[0]); } @@ -2139,7 +2149,7 @@ class TestCmdlineParser : public TestFixture { void ignorepaths2() { REDIRECT; const char * const argv[] = {"cppcheck", "-i", "src", "file.cpp"}; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(1, parser->getIgnoredPaths().size()); ASSERT_EQUALS("src", parser->getIgnoredPaths()[0]); } @@ -2147,7 +2157,7 @@ class TestCmdlineParser : public TestFixture { void ignorepaths3() { REDIRECT; const char * const argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"}; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(2, parser->getIgnoredPaths().size()); ASSERT_EQUALS("src", parser->getIgnoredPaths()[0]); ASSERT_EQUALS("module", parser->getIgnoredPaths()[1]); @@ -2156,7 +2166,7 @@ class TestCmdlineParser : public TestFixture { void ignorepaths4() { REDIRECT; const char * const argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"}; - ASSERT(parser->parseFromArgs(6, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(6, argv)); ASSERT_EQUALS(2, parser->getIgnoredPaths().size()); ASSERT_EQUALS("src", parser->getIgnoredPaths()[0]); ASSERT_EQUALS("module", parser->getIgnoredPaths()[1]); @@ -2165,7 +2175,7 @@ class TestCmdlineParser : public TestFixture { void ignorefilepaths1() { REDIRECT; const char * const argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, parser->getIgnoredPaths().size()); ASSERT_EQUALS("foo.cpp", parser->getIgnoredPaths()[0]); } @@ -2173,7 +2183,7 @@ class TestCmdlineParser : public TestFixture { void ignorefilepaths2() { REDIRECT; const char * const argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, parser->getIgnoredPaths().size()); ASSERT_EQUALS("src/foo.cpp", parser->getIgnoredPaths()[0]); } @@ -2182,21 +2192,21 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--check-config", "file.cpp"}; settings->checkConfiguration = false; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(true, settings->checkConfiguration); } void unknownParam() { REDIRECT; const char * const argv[] = {"cppcheck", "--foo", "file.cpp"}; - ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--foo\".\n", logger->str()); } void undefs() { REDIRECT; const char * const argv[] = {"cppcheck", "-U_WIN32", "file.cpp"}; - ASSERT(parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT_EQUALS(1, settings->userUndefs.size()); ASSERT(settings->userUndefs.find("_WIN32") != settings->userUndefs.end()); } @@ -2204,7 +2214,7 @@ class TestCmdlineParser : public TestFixture { void undefs2() { REDIRECT; const char * const argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"}; - ASSERT(parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); ASSERT_EQUALS(2, settings->userUndefs.size()); ASSERT(settings->userUndefs.find("_WIN32") != settings->userUndefs.end()); ASSERT(settings->userUndefs.find("NODEBUG") != settings->userUndefs.end()); @@ -2214,7 +2224,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-U"}; // Fails since -U has no param - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-U' is missing.\n", logger->str()); } @@ -2222,7 +2232,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-U", "-v", "file.cpp"}; // Fails since -U has no param - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-U' is missing.\n", logger->str()); } @@ -2230,27 +2240,27 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"}; // Fails since -U has no param - ASSERT_EQUALS(false, parser->parseFromArgs(4, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(4, argv)); ASSERT_EQUALS("cppcheck: error: argument to '-U' is missing.\n", logger->str()); } void cppcheckBuildDirExistent() { REDIRECT; const char * const argv[] = {"cppcheck", "--cppcheck-build-dir=.", "file.cpp"}; - ASSERT_EQUALS(true, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); } void cppcheckBuildDirNonExistent() { REDIRECT; const char * const argv[] = {"cppcheck", "--cppcheck-build-dir=non-existent-path"}; - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: Directory 'non-existent-path' specified by --cppcheck-build-dir argument has to be existent.\n", logger->str()); } void cppcheckBuildDirEmpty() { REDIRECT; const char * const argv[] = {"cppcheck", "--cppcheck-build-dir="}; - ASSERT_EQUALS(false, parser->parseFromArgs(2, argv)); + ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv)); ASSERT_EQUALS("cppcheck: error: Directory '' specified by --cppcheck-build-dir argument has to be existent.\n", logger->str()); } };