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;