Fixed #1212 (Allow giving used defines in command line)

This commit is contained in:
Daniel Marjamki 2010-05-16 07:38:29 +02:00
parent d7b117402c
commit 14b27f97fa
3 changed files with 31 additions and 1 deletions

View File

@ -367,6 +367,14 @@ bool CppCheck::parseFromArgs(int argc, const char* const argv[])
}
}
// User define
else if (strncmp(argv[i], "-D", 2) == 0)
{
if (!_settings.userDefines.empty())
_settings.userDefines += ";";
_settings.userDefines += 2 + argv[i];
}
// Include paths
else if (strcmp(argv[i], "-I") == 0 || strncmp(argv[i], "-I", 2) == 0)
{
@ -632,6 +640,12 @@ unsigned int CppCheck::check()
preprocessor.preprocess(fin, filedata, configurations, fname, _settings._includePaths);
}
if (!_settings.userDefines.empty())
{
configurations.clear();
configurations.push_back(_settings.userDefines);
}
int checkCount = 0;
for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it)
{

View File

@ -156,7 +156,6 @@ public:
* @return true if this error is suppressed.
*/
bool isSuppressed(const std::string &errorId, const std::string &file, unsigned int line);
};
/** @brief suppress message (--suppressions) */
@ -164,6 +163,9 @@ public:
/** @brief suppress exitcode */
Suppressions nofail;
/** @brief defines given by the user */
std::string userDefines;
};
/// @}

View File

@ -65,6 +65,8 @@ private:
TEST_CASE(parseOutputtingInvalidArgs);
TEST_CASE(parseArgsAndCheck);
TEST_CASE(parseArgsAndCheckSettings);
TEST_CASE(userdefines);
}
bool argCheck(int argc, const char *argv[])
@ -406,6 +408,18 @@ private:
CppCheck cppCheck(*this);
cppCheck.getErrorMessages();
}
void userdefines()
{
{
const char *argv[] = {"cppcheck", "-DA", "-DB"};
Settings settings;
ASSERT_EQUALS(true, argCheckReturnSettings(3, argv, settings));
ASSERT_EQUALS("A;B", settings.userDefines);
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", output.str());
}
}
};
REGISTER_TEST(TestCppcheck)