From d334a02801b52a6d5d372d05e03f619049fd5840 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 29 Jan 2011 19:04:52 +0200 Subject: [PATCH] Make --exitcode-suppressions option consistent. The --exitcode-suppressions option was inconsistent with other long options by taking the filename as separate argument. Now it expects format --exitcode-suppressions=filename.txt like other long options. Ticket: #1837 (--suppresions file.txt inconsistent) --- cli/cmdlineparser.cpp | 30 ++++++++++++++++++++++-------- test/testcmdlineparser.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index a333804a8..c3eaa5764 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -104,20 +104,34 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) } // Filter errors - else if (strcmp(argv[i], "--exitcode-suppressions") == 0) + else if (strncmp(argv[i], "--exitcode-suppressions", 23) == 0) { - ++i; + std::string filename; - if (i >= argc) + // exitcode-suppressions filename.txt + // Deprecated + if (strcmp(argv[i], "--exitcode-suppressions") == 0) { - PrintMessage("cppcheck: No file specified for the --exitcode-suppressions option"); - return false; + ++i; + + if (i >= argc || strncmp(argv[i], "-", 1) == 0 || + strncmp(argv[i], "--", 2) == 0) + { + PrintMessage("cppcheck: No filename specified for the --exitcode-suppressions option"); + return false; + } + filename = argv[i]; + } + // exitcode-suppressions=filename.txt + else + { + filename = 24 + argv[i]; } - std::ifstream f(argv[i]); + std::ifstream f(filename.c_str()); if (!f.is_open()) { - PrintMessage("cppcheck: Couldn't open the file \"" + std::string(argv[i]) + "\""); + PrintMessage("cppcheck: Couldn't open the file \"" + std::string(filename) + "\""); return false; } const std::string errmsg(_settings->nofail.parseFile(f)); @@ -565,7 +579,7 @@ void CmdLineParser::PrintHelp() " provided. Note that your operating system can\n" " modify this value, e.g. 256 can become 0.\n" " --errorlist Print a list of all error messages in XML format.\n" - " --exitcode-suppressions file\n" + " --exitcode-suppressions=file\n" " Used when certain messages should be displayed but\n" " should not cause a non-zero exitcode.\n" " --file-list=file Specify the files to check in a text file. One Filename per line.\n" diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index c9bac0429..6b9bdf75c 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -65,7 +65,9 @@ private: TEST_CASE(errorExitcode); TEST_CASE(errorExitcodeMissing); TEST_CASE(errorExitcodeStr); - TEST_CASE(exitcodeSuppressions); // TODO: Create and test real suppression file + TEST_CASE(exitcodeSuppressionsOld); // TODO: Create and test real suppression file + TEST_CASE(exitcodeSuppressions); + TEST_CASE(exitcodeSuppressionsNoFile); TEST_CASE(fileList); // TODO: Create and test real file listing file TEST_CASE(inlineSuppr); TEST_CASE(jobs); @@ -429,10 +431,29 @@ private: ASSERT(!parser.ParseFromArgs(3, argv)); } + void exitcodeSuppressionsOld() + { + // TODO: Fails since cannot open the file + REDIRECT; + const char *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(!parser.ParseFromArgs(4, argv)); + } + void exitcodeSuppressions() { REDIRECT; - const char *argv[] = {"cppcheck", "--error-exitcode-suppressions suppr.txt", "file.cpp"}; + const char *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(!parser.ParseFromArgs(3, argv)); + } + + void exitcodeSuppressionsNoFile() + { + REDIRECT; + const char *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"}; Settings settings; CmdLineParser parser(&settings); ASSERT(!parser.ParseFromArgs(3, argv));