From ad03c97a6eb4cd38f1f25cdb4398ccf51ee6d9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 8 Sep 2010 17:42:28 +0200 Subject: [PATCH] cmdlineparser: allow space between -D and define name. ticket: #2036 --- cli/cmdlineparser.cpp | 5 ++++- test/testcmdlineparser.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 090b812fc..5875fd904 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -182,7 +182,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) { if (!_settings->userDefines.empty()) _settings->userDefines += ";"; - _settings->userDefines += 2 + argv[i]; + if (strcmp(argv[i], "-D") == 0) + _settings->userDefines += argv[++i]; + else + _settings->userDefines += 2 + argv[i]; } // Include paths diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index e18c15c45..5ee6efed0 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -85,6 +85,7 @@ private: TEST_CASE(quietlong); TEST_CASE(defines); TEST_CASE(defines2); + TEST_CASE(defines3); TEST_CASE(includesnopath); TEST_CASE(includes); TEST_CASE(includes2); @@ -262,6 +263,16 @@ private: ASSERT_EQUALS("_WIN32;NODEBUG", settings.userDefines); } + void defines3() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(4, argv)); + ASSERT_EQUALS("DEBUG", settings.userDefines); + } + void includesnopath() { REDIRECT;