Fixed #3617 (CLI: '-DMACRO' should be considered as '-DMACRO=1')

This commit is contained in:
Daniel Marjamäki 2012-07-05 19:35:41 +02:00
parent 0bbf2ecd0c
commit 7122aeff58
2 changed files with 15 additions and 2 deletions

View File

@ -330,6 +330,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
define = 2 + argv[i];
}
// No "=", append a "=1"
if (define.find("=") == std::string::npos)
define += "=1";
if (!_settings->userDefines.empty())
_settings->userDefines += ";";
_settings->userDefines += define;

View File

@ -336,7 +336,7 @@ private:
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("_WIN32", settings.userDefines);
ASSERT_EQUALS("_WIN32=1", settings.userDefines);
}
void defines2() {
@ -345,7 +345,7 @@ private:
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("_WIN32;NODEBUG", settings.userDefines);
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
}
void defines3() {
@ -354,6 +354,15 @@ private:
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(4, argv));
ASSERT_EQUALS("DEBUG=1", settings.userDefines);
}
void defines4() {
REDIRECT;
const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS("DEBUG", settings.userDefines);
}