Merge branch 'master' of https://www.github.com/danmar/cppcheck
This commit is contained in:
commit
92fd0595b1
|
@ -102,17 +102,17 @@ CmdLineParser::CmdLineParser(Settings *settings)
|
|||
{
|
||||
}
|
||||
|
||||
void CmdLineParser::PrintMessage(const std::string &message)
|
||||
void CmdLineParser::printMessage(const std::string &message)
|
||||
{
|
||||
std::cout << message << std::endl;
|
||||
}
|
||||
|
||||
void CmdLineParser::PrintMessage(const char* message)
|
||||
void CmdLineParser::printMessage(const char* message)
|
||||
{
|
||||
std::cout << message << std::endl;
|
||||
}
|
||||
|
||||
bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||
bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||
{
|
||||
bool def = false;
|
||||
bool maxconfigs = false;
|
||||
|
@ -168,7 +168,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
} else {
|
||||
i++;
|
||||
if (i >= argc || argv[i][0] == '-') {
|
||||
PrintMessage("cppcheck: No language given to '-x' option.");
|
||||
printMessage("cppcheck: No language given to '-x' option.");
|
||||
return false;
|
||||
}
|
||||
str = argv[i];
|
||||
|
@ -179,7 +179,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
else if (str == "c++")
|
||||
_settings->enforcedLang = Settings::CPP;
|
||||
else {
|
||||
PrintMessage("cppcheck: Unknown language '" + str + "' enforced.");
|
||||
printMessage("cppcheck: Unknown language '" + str + "' enforced.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -191,12 +191,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
|
||||
std::ifstream f(filename);
|
||||
if (!f.is_open()) {
|
||||
PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
|
||||
printMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
|
||||
return false;
|
||||
}
|
||||
const std::string errmsg(_settings->nofail.parseFile(f));
|
||||
if (!errmsg.empty()) {
|
||||
PrintMessage(errmsg);
|
||||
printMessage(errmsg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -218,12 +218,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
message += "\n cppcheck --suppressions-list=a.txt --suppressions-list=b.txt file.cpp";
|
||||
}
|
||||
|
||||
PrintMessage(message);
|
||||
printMessage(message);
|
||||
return false;
|
||||
}
|
||||
const std::string errmsg(_settings->nomsg.parseFile(f));
|
||||
if (!errmsg.empty()) {
|
||||
PrintMessage(errmsg);
|
||||
printMessage(errmsg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
const char * filename = argv[i] + 15;
|
||||
const std::string errmsg(_settings->nomsg.parseXmlFile(filename));
|
||||
if (!errmsg.empty()) {
|
||||
PrintMessage(errmsg);
|
||||
printMessage(errmsg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
const std::string suppression = argv[i]+11;
|
||||
const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression));
|
||||
if (!errmsg.empty()) {
|
||||
PrintMessage(errmsg);
|
||||
printMessage(errmsg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
paths.erase(0, pos + 1);
|
||||
}
|
||||
} else {
|
||||
PrintMessage("cppcheck: No paths specified for the '" + std::string(argv[i]) + "' option.");
|
||||
printMessage("cppcheck: No paths specified for the '" + std::string(argv[i]) + "' option.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -303,13 +303,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
|
||||
std::istringstream iss(numberString);
|
||||
if (!(iss >> _settings->xml_version)) {
|
||||
PrintMessage("cppcheck: argument to '--xml-version' is not a number.");
|
||||
printMessage("cppcheck: argument to '--xml-version' is not a number.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_settings->xml_version != 2) {
|
||||
// We only have xml version 2
|
||||
PrintMessage("cppcheck: '--xml-version' can only be 2.");
|
||||
printMessage("cppcheck: '--xml-version' can only be 2.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
|
||||
const std::string errmsg = _settings->addEnabled(argv[i] + 9);
|
||||
if (!errmsg.empty()) {
|
||||
PrintMessage(errmsg);
|
||||
printMessage(errmsg);
|
||||
return false;
|
||||
}
|
||||
// when "style" is enabled, also enable "warning", "performance" and "portability"
|
||||
|
@ -351,7 +351,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
std::istringstream iss(temp);
|
||||
if (!(iss >> _settings->exitCode)) {
|
||||
_settings->exitCode = 0;
|
||||
PrintMessage("cppcheck: Argument must be an integer. Try something like '--error-exitcode=1'.");
|
||||
printMessage("cppcheck: Argument must be an integer. Try something like '--error-exitcode=1'.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
if (std::strcmp(argv[i], "-D") == 0) {
|
||||
++i;
|
||||
if (i >= argc || argv[i][0] == '-') {
|
||||
PrintMessage("cppcheck: argument to '-D' is missing.");
|
||||
printMessage("cppcheck: argument to '-D' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
if (std::strcmp(argv[i], "-U") == 0) {
|
||||
++i;
|
||||
if (i >= argc || argv[i][0] == '-') {
|
||||
PrintMessage("cppcheck: argument to '-U' is missing.");
|
||||
printMessage("cppcheck: argument to '-U' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
if (std::strcmp(argv[i], "-I") == 0) {
|
||||
++i;
|
||||
if (i >= argc || argv[i][0] == '-') {
|
||||
PrintMessage("cppcheck: argument to '-I' is missing.");
|
||||
printMessage("cppcheck: argument to '-I' is missing.");
|
||||
return false;
|
||||
}
|
||||
path = argv[i];
|
||||
|
@ -470,7 +470,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
if (std::strcmp(argv[i], "-i") == 0) {
|
||||
++i;
|
||||
if (i >= argc || argv[i][0] == '-') {
|
||||
PrintMessage("cppcheck: argument to '-i' is missing.");
|
||||
printMessage("cppcheck: argument to '-i' is missing.");
|
||||
return false;
|
||||
}
|
||||
path = argv[i];
|
||||
|
@ -507,7 +507,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
if (std::strstr(argv[i], ".sln") || std::strstr(argv[i], ".vcxproj")) {
|
||||
if (!CppCheckExecutor::tryLoadLibrary(_settings->library, argv[0], "windows.cfg")) {
|
||||
// This shouldn't happen normally.
|
||||
PrintMessage("cppcheck: Failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
|
||||
printMessage("cppcheck: Failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -538,23 +538,42 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
// Output formatter
|
||||
else if (std::strcmp(argv[i], "--template") == 0 ||
|
||||
std::strncmp(argv[i], "--template=", 11) == 0) {
|
||||
// "--template path/"
|
||||
// "--template format"
|
||||
if (argv[i][10] == '=')
|
||||
_settings->outputFormat = argv[i] + 11;
|
||||
_settings->templateFormat = argv[i] + 11;
|
||||
else if ((i+1) < argc && argv[i+1][0] != '-') {
|
||||
++i;
|
||||
_settings->outputFormat = argv[i];
|
||||
_settings->templateFormat = argv[i];
|
||||
} else {
|
||||
PrintMessage("cppcheck: argument to '--template' is missing.");
|
||||
printMessage("cppcheck: argument to '--template' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_settings->outputFormat == "gcc")
|
||||
_settings->outputFormat = "{file}:{line}: {severity}: {message}";
|
||||
else if (_settings->outputFormat == "vs")
|
||||
_settings->outputFormat = "{file}({line}): {severity}: {message}";
|
||||
else if (_settings->outputFormat == "edit")
|
||||
_settings->outputFormat = "{file} +{line}: {severity}: {message}";
|
||||
if (_settings->templateFormat == "gcc") {
|
||||
//_settings->templateFormat = "{file}:{line}: {severity}: {message}";
|
||||
_settings->templateFormat = "{file}:{line}:{column}: warning: {message} [{id}]\\n{code}";
|
||||
_settings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
|
||||
} else if (_settings->templateFormat == "daca2") {
|
||||
_settings->templateFormat = "{file}:{line}:{column}: {inconclusive:inconclusive }{severity}: {message} [{id}]\\n{code}";
|
||||
_settings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
|
||||
} else if (_settings->templateFormat == "vs")
|
||||
_settings->templateFormat = "{file}({line}): {severity}: {message}";
|
||||
else if (_settings->templateFormat == "edit")
|
||||
_settings->templateFormat = "{file} +{line}: {severity}: {message}";
|
||||
}
|
||||
|
||||
else if (std::strcmp(argv[i], "--template-location") == 0 ||
|
||||
std::strncmp(argv[i], "--template-location=", 20) == 0) {
|
||||
// "--template-location format"
|
||||
if (argv[i][19] == '=')
|
||||
_settings->templateLocation = argv[i] + 20;
|
||||
else if ((i+1) < argc && argv[i+1][0] != '-') {
|
||||
++i;
|
||||
_settings->templateLocation = argv[i];
|
||||
} else {
|
||||
printMessage("cppcheck: argument to '--template' is missing.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Checking threads
|
||||
|
@ -565,7 +584,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
if (std::strcmp(argv[i], "-j") == 0) {
|
||||
++i;
|
||||
if (i >= argc || argv[i][0] == '-') {
|
||||
PrintMessage("cppcheck: argument to '-j' is missing.");
|
||||
printMessage("cppcheck: argument to '-j' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -578,14 +597,14 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
|
||||
std::istringstream iss(numberString);
|
||||
if (!(iss >> _settings->jobs)) {
|
||||
PrintMessage("cppcheck: argument to '-j' is not a number.");
|
||||
printMessage("cppcheck: argument to '-j' is not a number.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_settings->jobs > 10000) {
|
||||
// This limit is here just to catch typos. If someone has
|
||||
// need for more jobs, this value should be increased.
|
||||
PrintMessage("cppcheck: argument for '-j' is allowed to be 10000 at max.");
|
||||
printMessage("cppcheck: argument for '-j' is allowed to be 10000 at max.");
|
||||
return false;
|
||||
}
|
||||
} else if (std::strncmp(argv[i], "-l", 2) == 0) {
|
||||
|
@ -595,7 +614,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
if (std::strcmp(argv[i], "-l") == 0) {
|
||||
++i;
|
||||
if (i >= argc || argv[i][0] == '-') {
|
||||
PrintMessage("cppcheck: argument to '-l' is missing.");
|
||||
printMessage("cppcheck: argument to '-l' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -608,7 +627,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
|
||||
std::istringstream iss(numberString);
|
||||
if (!(iss >> _settings->loadAverage)) {
|
||||
PrintMessage("cppcheck: argument to '-l' is not a number.");
|
||||
printMessage("cppcheck: argument to '-l' is not a number.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -652,7 +671,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
std::string message("cppcheck: error: unrecognized showtime mode: \"");
|
||||
message += showtimeMode;
|
||||
message += "\". Supported modes: file, summary, top5.";
|
||||
PrintMessage(message);
|
||||
printMessage(message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -726,7 +745,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
std::string message("cppcheck: error: unrecognized platform: \"");
|
||||
message += platform;
|
||||
message += "\".";
|
||||
PrintMessage(message);
|
||||
printMessage(message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -737,12 +756,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
|
||||
std::istringstream iss(14+argv[i]);
|
||||
if (!(iss >> _settings->maxConfigs)) {
|
||||
PrintMessage("cppcheck: argument to '--max-configs=' is not a number.");
|
||||
printMessage("cppcheck: argument to '--max-configs=' is not a number.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_settings->maxConfigs < 1) {
|
||||
PrintMessage("cppcheck: argument to '--max-configs=' must be greater than 0.");
|
||||
printMessage("cppcheck: argument to '--max-configs=' must be greater than 0.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -761,7 +780,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
std::string message("cppcheck: error: unrecognized command line option: \"");
|
||||
message += argv[i];
|
||||
message += "\".";
|
||||
PrintMessage(message);
|
||||
printMessage(message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -782,7 +801,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
_settings->maxConfigs = 1U;
|
||||
|
||||
if (_settings->isEnabled(Settings::UNUSED_FUNCTION) && _settings->jobs > 1) {
|
||||
PrintMessage("cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.");
|
||||
printMessage("cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.");
|
||||
}
|
||||
|
||||
if (argc <= 1) {
|
||||
|
@ -791,13 +810,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
}
|
||||
|
||||
if (_showHelp) {
|
||||
PrintHelp();
|
||||
printHelp();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Print error only if we have "real" command and expect files
|
||||
if (!_exitAfterPrint && _pathnames.empty() && _settings->project.fileSettings.empty()) {
|
||||
PrintMessage("cppcheck: No C or C++ source files found.");
|
||||
printMessage("cppcheck: No C or C++ source files found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -808,7 +827,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
return true;
|
||||
}
|
||||
|
||||
void CmdLineParser::PrintHelp()
|
||||
void CmdLineParser::printHelp()
|
||||
{
|
||||
std::cout << "Cppcheck - A tool for static C/C++ code analysis\n"
|
||||
"\n"
|
||||
|
@ -1008,11 +1027,40 @@ void CmdLineParser::PrintHelp()
|
|||
" --suppressions-list=<file>\n"
|
||||
" Suppress warnings listed in the file. Each suppression\n"
|
||||
" is in the same format as <spec> above.\n"
|
||||
" --template='<text>' Format the error messages. E.g.\n"
|
||||
" --template='<text>' Format the error messages. Available fields:\n"
|
||||
" {file} file name\n"
|
||||
" {line} line number\n"
|
||||
" {column} column number\n"
|
||||
" {callstack} show a callstack. Example:\n"
|
||||
" [file.c:1] -> [file.c:100]\n"
|
||||
" {inconlusive:text} if warning is inconclusive, text\n"
|
||||
" is written\n"
|
||||
" {severity} severity\n"
|
||||
" {message} warning message\n"
|
||||
" {id} warning id\n"
|
||||
" {code} show the real code\n"
|
||||
" \\t insert tab\n"
|
||||
" \\n insert newline\n"
|
||||
" \\r insert carriage return\n"
|
||||
" Example formats:\n"
|
||||
" '{file}:{line},{severity},{id},{message}' or\n"
|
||||
" '{file}({line}):({severity}) {message}' or\n"
|
||||
" '{callstack} {message}'\n"
|
||||
" Pre-defined templates: gcc, vs, edit.\n"
|
||||
" --template-location='<text>'\n"
|
||||
" Format error message location. If this is not provided\n"
|
||||
" then no extra location info is shown.\n"
|
||||
" Available fields:\n"
|
||||
" {file} file name\n"
|
||||
" {line} line number\n"
|
||||
" {column} column number\n"
|
||||
" {info} location info\n"
|
||||
" {code} show the real code\n"
|
||||
" \\t insert tab\n"
|
||||
" \\n insert newline\n"
|
||||
" \\r insert carriage return\n"
|
||||
" Example format (gcc-like):\n"
|
||||
" '{file}:{line}:{column}: note: {info}\\n{code}'\n"
|
||||
" -v, --verbose Output more detailed error information.\n"
|
||||
" --version Print out version number.\n"
|
||||
" --xml Write results in xml format to error stream (stderr).\n"
|
||||
|
|
|
@ -49,47 +49,47 @@ public:
|
|||
* Parse given command line.
|
||||
* @return true if command line was ok, false if there was an error.
|
||||
*/
|
||||
bool ParseFromArgs(int argc, const char* const argv[]);
|
||||
bool parseFromArgs(int argc, const char* const argv[]);
|
||||
|
||||
/**
|
||||
* Return if user wanted to see program version.
|
||||
*/
|
||||
bool GetShowVersion() const {
|
||||
bool getShowVersion() const {
|
||||
return _showVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if user wanted to see list of error messages.
|
||||
*/
|
||||
bool GetShowErrorMessages() const {
|
||||
bool getShowErrorMessages() const {
|
||||
return _showErrorMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path names user gave to command line.
|
||||
*/
|
||||
const std::vector<std::string>& GetPathNames() const {
|
||||
const std::vector<std::string>& getPathNames() const {
|
||||
return _pathnames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if help is shown to user.
|
||||
*/
|
||||
bool GetShowHelp() const {
|
||||
bool getShowHelp() const {
|
||||
return _showHelp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if we should exit after printing version, help etc.
|
||||
*/
|
||||
bool ExitAfterPrinting() const {
|
||||
bool exitAfterPrinting() const {
|
||||
return _exitAfterPrint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of paths user wants to ignore.
|
||||
*/
|
||||
const std::vector<std::string>& GetIgnoredPaths() const {
|
||||
const std::vector<std::string>& getIgnoredPaths() const {
|
||||
return _ignoredPaths;
|
||||
}
|
||||
|
||||
|
@ -98,13 +98,13 @@ protected:
|
|||
/**
|
||||
* Print help text to the console.
|
||||
*/
|
||||
static void PrintHelp();
|
||||
static void printHelp();
|
||||
|
||||
/**
|
||||
* Print message (to console?).
|
||||
*/
|
||||
static void PrintMessage(const std::string &message);
|
||||
static void PrintMessage(const char* message);
|
||||
static void printMessage(const std::string &message);
|
||||
static void printMessage(const char* message);
|
||||
|
||||
private:
|
||||
std::vector<std::string> _pathnames;
|
||||
|
|
|
@ -92,10 +92,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
|||
{
|
||||
Settings& settings = cppcheck->settings();
|
||||
CmdLineParser parser(&settings);
|
||||
const bool success = parser.ParseFromArgs(argc, argv);
|
||||
const bool success = parser.parseFromArgs(argc, argv);
|
||||
|
||||
if (success) {
|
||||
if (parser.GetShowVersion() && !parser.GetShowErrorMessages()) {
|
||||
if (parser.getShowVersion() && !parser.getShowErrorMessages()) {
|
||||
const char * const extraVersion = cppcheck->extraVersion();
|
||||
if (*extraVersion != 0)
|
||||
std::cout << "Cppcheck " << cppcheck->version() << " ("
|
||||
|
@ -104,14 +104,14 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
|||
std::cout << "Cppcheck " << cppcheck->version() << std::endl;
|
||||
}
|
||||
|
||||
if (parser.GetShowErrorMessages()) {
|
||||
if (parser.getShowErrorMessages()) {
|
||||
errorlist = true;
|
||||
std::cout << ErrorLogger::ErrorMessage::getXMLHeader();
|
||||
cppcheck->getErrorMessages();
|
||||
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
|
||||
}
|
||||
|
||||
if (parser.ExitAfterPrinting()) {
|
||||
if (parser.exitAfterPrinting()) {
|
||||
settings.terminate();
|
||||
return true;
|
||||
}
|
||||
|
@ -138,9 +138,9 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
|||
|
||||
// Output a warning for the user if he tries to exclude headers
|
||||
bool warn = false;
|
||||
const std::vector<std::string>& ignored = parser.GetIgnoredPaths();
|
||||
for (std::vector<std::string>::const_iterator i = ignored.cbegin(); i != ignored.cend(); ++i) {
|
||||
if (Path::isHeader(*i)) {
|
||||
const std::vector<std::string>& ignored = parser.getIgnoredPaths();
|
||||
for (const std::string &i : ignored) {
|
||||
if (Path::isHeader(i)) {
|
||||
warn = true;
|
||||
break;
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
|||
std::cout << "cppcheck: Please use --suppress for ignoring results from the header files." << std::endl;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& pathnames = parser.GetPathNames();
|
||||
const std::vector<std::string>& pathnames = parser.getPathNames();
|
||||
|
||||
#if defined(_WIN32)
|
||||
// For Windows we want case-insensitive path matching
|
||||
|
@ -1040,7 +1040,7 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
|
|||
} else if (_settings->xml) {
|
||||
reportErr(msg.toXML());
|
||||
} else {
|
||||
reportErr(msg.toString(_settings->verbose, _settings->outputFormat));
|
||||
reportErr(msg.toString(_settings->verbose, _settings->templateFormat, _settings->templateLocation));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ protected:
|
|||
ErrorPath errorPath;
|
||||
if (!value) {
|
||||
errorPath.emplace_back(errtok,bug);
|
||||
} else if (_settings->verbose || _settings->xml || _settings->outputFormat == "daca2") {
|
||||
} else if (_settings->verbose || _settings->xml || !_settings->templateLocation.empty()) {
|
||||
errorPath = value->errorPath;
|
||||
errorPath.emplace_back(errtok,bug);
|
||||
} else {
|
||||
|
|
|
@ -93,7 +93,7 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
|
|||
}
|
||||
|
||||
std::list<ErrorPathItem> errorPath;
|
||||
if (_settings->xml || _settings->outputFormat == "daca2") {
|
||||
if (_settings->xml || !_settings->templateLocation.empty()) {
|
||||
for (std::size_t i = 0; i < index.size(); ++i) {
|
||||
const ErrorPath &e = getErrorPath(tok, &index[i], "");
|
||||
for (ErrorPath::const_iterator it = e.begin(); it != e.end(); ++it) {
|
||||
|
|
|
@ -444,15 +444,15 @@ static std::string readCode(const std::string &file, unsigned int linenr, unsign
|
|||
const std::string::size_type endPos = line.find_last_not_of("\r\n\t ");
|
||||
if (endPos + 1 < line.size())
|
||||
line.erase(endPos + 1);
|
||||
return line + endl + std::string(column,' ') + '^';
|
||||
return line + endl + std::string((column>0 ? column-1 : column), ' ') + '^';
|
||||
}
|
||||
|
||||
std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string &outputFormat) const
|
||||
std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string &templateFormat, const std::string &templateLocation) const
|
||||
{
|
||||
// Save this ErrorMessage in plain text.
|
||||
|
||||
// No template is given
|
||||
if (outputFormat.empty()) {
|
||||
if (templateFormat.empty()) {
|
||||
std::ostringstream text;
|
||||
if (!_callStack.empty())
|
||||
text << callStackToString(_callStack) << ": ";
|
||||
|
@ -466,76 +466,77 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
|||
return text.str();
|
||||
}
|
||||
|
||||
else if (outputFormat == "daca2") {
|
||||
// This is a clang-like output format for daca2
|
||||
std::ostringstream text;
|
||||
if (_callStack.empty()) {
|
||||
text << "nofile:0:0: ";
|
||||
} else {
|
||||
const ErrorLogger::ErrorMessage::FileLocation &loc = _callStack.back();
|
||||
text << loc.getfile() << ':' << loc.line << ':' << loc.col << ": ";
|
||||
// template is given. Reformat the output according to it
|
||||
std::string result = templateFormat;
|
||||
// Support a few special characters to allow to specific formatting, see http://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=4&t=494&sid=21715d362c0dbafd3791da4d9522f814
|
||||
// Substitution should be done first so messages from cppcheck never get translated.
|
||||
findAndReplace(result, "\\b", "\b");
|
||||
findAndReplace(result, "\\n", "\n");
|
||||
findAndReplace(result, "\\r", "\r");
|
||||
findAndReplace(result, "\\t", "\t");
|
||||
|
||||
findAndReplace(result, "{id}", _id);
|
||||
if (result.find("{inconclusive:") != std::string::npos) {
|
||||
const std::string::size_type pos1 = result.find("{inconclusive:");
|
||||
const std::string::size_type pos2 = result.find("}", pos1+1);
|
||||
const std::string replaceFrom = result.substr(pos1,pos2-pos1+1);
|
||||
const std::string replaceWith = result.substr(pos1+14, pos2-pos1-14);
|
||||
findAndReplace(result, replaceFrom, replaceWith);
|
||||
}
|
||||
findAndReplace(result, "{severity}", Severity::toString(_severity));
|
||||
findAndReplace(result, "{message}", verbose ? _verboseMessage : _shortMessage);
|
||||
findAndReplace(result, "{callstack}", _callStack.empty() ? emptyString : callStackToString(_callStack));
|
||||
if (!_callStack.empty()) {
|
||||
findAndReplace(result, "{file}", _callStack.back().getfile());
|
||||
findAndReplace(result, "{line}", MathLib::toString(_callStack.back().line));
|
||||
findAndReplace(result, "{column}", MathLib::toString(_callStack.back().col));
|
||||
if (result.find("{code}") != std::string::npos) {
|
||||
const std::string::size_type pos = result.find("\r");
|
||||
const char *endl;
|
||||
if (pos == std::string::npos)
|
||||
endl = "\n";
|
||||
else if (pos+1 < result.size() && result[pos+1] == '\n')
|
||||
endl = "\r\n";
|
||||
else
|
||||
endl = "\r";
|
||||
findAndReplace(result, "{code}", readCode(_callStack.back().getfile(), _callStack.back().line, _callStack.back().col, endl));
|
||||
}
|
||||
|
||||
if (_inconclusive)
|
||||
text << "inconclusive ";
|
||||
text << Severity::toString(_severity) << ": ";
|
||||
|
||||
text << (verbose ? _verboseMessage : _shortMessage)
|
||||
<< " [" << _id << ']';
|
||||
|
||||
if (_callStack.size() <= 1U)
|
||||
return text.str();
|
||||
|
||||
for (std::list<FileLocation>::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc)
|
||||
text << std::endl
|
||||
<< loc->getfile()
|
||||
<< ':'
|
||||
<< loc->line
|
||||
<< ':'
|
||||
<< loc->col
|
||||
<< ": note: "
|
||||
<< (loc->getinfo().empty() ? _shortMessage : loc->getinfo());
|
||||
return text.str();
|
||||
} else {
|
||||
findAndReplace(result, "{file}", "nofile");
|
||||
findAndReplace(result, "{line}", "0");
|
||||
findAndReplace(result, "{column}", "0");
|
||||
findAndReplace(result, "{code}", emptyString);
|
||||
}
|
||||
|
||||
// template is given. Reformat the output according to it
|
||||
else {
|
||||
std::string result = outputFormat;
|
||||
// Support a few special characters to allow to specific formatting, see http://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=4&t=494&sid=21715d362c0dbafd3791da4d9522f814
|
||||
// Substitution should be done first so messages from cppcheck never get translated.
|
||||
findAndReplace(result, "\\b", "\b");
|
||||
findAndReplace(result, "\\n", "\n");
|
||||
findAndReplace(result, "\\r", "\r");
|
||||
findAndReplace(result, "\\t", "\t");
|
||||
if (!templateLocation.empty() && _callStack.size() >= 2U) {
|
||||
for (const FileLocation &fileLocation : _callStack) {
|
||||
std::string text = templateLocation;
|
||||
|
||||
findAndReplace(result, "{id}", _id);
|
||||
findAndReplace(result, "{severity}", Severity::toString(_severity));
|
||||
findAndReplace(result, "{message}", verbose ? _verboseMessage : _shortMessage);
|
||||
findAndReplace(result, "{callstack}", _callStack.empty() ? emptyString : callStackToString(_callStack));
|
||||
if (!_callStack.empty()) {
|
||||
findAndReplace(result, "{file}", _callStack.back().getfile());
|
||||
findAndReplace(result, "{line}", MathLib::toString(_callStack.back().line));
|
||||
findAndReplace(result, "{column}", MathLib::toString(_callStack.back().col));
|
||||
if (result.find("{code}") != std::string::npos) {
|
||||
const std::string::size_type pos = result.find("\r");
|
||||
findAndReplace(text, "\\b", "\b");
|
||||
findAndReplace(text, "\\n", "\n");
|
||||
findAndReplace(text, "\\r", "\r");
|
||||
findAndReplace(text, "\\t", "\t");
|
||||
|
||||
findAndReplace(text, "{file}", fileLocation.getfile());
|
||||
findAndReplace(text, "{line}", MathLib::toString(fileLocation.line));
|
||||
findAndReplace(text, "{column}", MathLib::toString(fileLocation.col));
|
||||
findAndReplace(text, "{info}", fileLocation.getinfo().empty() ? _shortMessage : fileLocation.getinfo());
|
||||
if (text.find("{code}") != std::string::npos) {
|
||||
const std::string::size_type pos = text.find("\r");
|
||||
const char *endl;
|
||||
if (pos == std::string::npos)
|
||||
endl = "\n";
|
||||
else if (pos+1 < result.size() && result[pos+1] == '\n')
|
||||
else if (pos+1 < text.size() && text[pos+1] == '\n')
|
||||
endl = "\r\n";
|
||||
else
|
||||
endl = "\r";
|
||||
findAndReplace(result, "{code}", readCode(_callStack.back().getfile(), _callStack.back().line, _callStack.back().col, endl));
|
||||
findAndReplace(text, "{code}", readCode(fileLocation.getfile(), fileLocation.line, fileLocation.col, endl));
|
||||
}
|
||||
} else {
|
||||
findAndReplace(result, "{file}", emptyString);
|
||||
findAndReplace(result, "{line}", emptyString);
|
||||
findAndReplace(result, "{column}", emptyString);
|
||||
findAndReplace(result, "{code}", emptyString);
|
||||
result += '\n' + text;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ErrorLogger::reportUnmatchedSuppressions(const std::list<Suppressions::Suppression> &unmatched)
|
||||
|
|
|
@ -256,11 +256,13 @@ public:
|
|||
/**
|
||||
* Format the error message into a string.
|
||||
* @param verbose use verbose message
|
||||
* @param outputFormat Empty string to use default output format
|
||||
* @param templateFormat Empty string to use default output format
|
||||
* or template to be used. E.g. "{file}:{line},{severity},{id},{message}"
|
||||
* @param templateLocation Format Empty string to use default output format
|
||||
* or template to be used. E.g. "{file}:{line},{info}"
|
||||
* @return formatted string
|
||||
*/
|
||||
std::string toString(bool verbose, const std::string &outputFormat = emptyString) const;
|
||||
std::string toString(bool verbose, const std::string &templateFormat = emptyString, const std::string &templateLocation = emptyString) const;
|
||||
|
||||
std::string serialize() const;
|
||||
bool deserialize(const std::string &data);
|
||||
|
|
|
@ -158,7 +158,11 @@ public:
|
|||
|
||||
/** @brief The output format in which the errors are printed in text mode,
|
||||
e.g. "{severity} {file}:{line} {message} {id}" */
|
||||
std::string outputFormat;
|
||||
std::string templateFormat;
|
||||
|
||||
/** @brief The output format in which the error locations are printed in
|
||||
* text mode, e.g. "{file}:{line} {info}" */
|
||||
std::string templateLocation;
|
||||
|
||||
/** @brief show timing information (--showtime=file|summary|top5) */
|
||||
SHOWTIME_MODES showtime;
|
||||
|
|
|
@ -154,65 +154,65 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(1, argv));
|
||||
ASSERT_EQUALS(true, parser.GetShowHelp());
|
||||
ASSERT(parser.parseFromArgs(1, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||
}
|
||||
|
||||
void helpshort() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-h"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.GetShowHelp());
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||
}
|
||||
|
||||
void helplong() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--help"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.GetShowHelp());
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||
}
|
||||
|
||||
void showversion() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--version"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.GetShowVersion());
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, parser.getShowVersion());
|
||||
}
|
||||
|
||||
void onefile() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(1, (int)parser.GetPathNames().size());
|
||||
ASSERT_EQUALS("file.cpp", parser.GetPathNames().at(0));
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
||||
ASSERT_EQUALS("file.cpp", parser.getPathNames().at(0));
|
||||
}
|
||||
|
||||
void onepath() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "src"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(1, (int)parser.GetPathNames().size());
|
||||
ASSERT_EQUALS("src", parser.GetPathNames().at(0));
|
||||
ASSERT(parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
||||
ASSERT_EQUALS("src", parser.getPathNames().at(0));
|
||||
}
|
||||
|
||||
void optionwithoutfile() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-v"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(0, (int)parser.GetPathNames().size());
|
||||
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(0, (int)parser.getPathNames().size());
|
||||
}
|
||||
|
||||
void verboseshort() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-v", "file.cpp"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.verbose);
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--verbose", "file.cpp"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.verbose);
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--debug", "file.cpp"};
|
||||
settings.debug = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.debug);
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"};
|
||||
settings.debugwarnings = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.debugwarnings);
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-f", "file.cpp"};
|
||||
settings.force = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.force);
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--force", "file.cpp"};
|
||||
settings.force = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.force);
|
||||
}
|
||||
|
||||
|
@ -261,20 +261,20 @@ private:
|
|||
settings.relativePaths = false;
|
||||
|
||||
const char *argvs[] = {"cppcheck", "-rp", "file.cpp"};
|
||||
ASSERT(defParser.ParseFromArgs(3, argvs));
|
||||
ASSERT(defParser.parseFromArgs(3, argvs));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
|
||||
settings.relativePaths = false;
|
||||
|
||||
const char *argvl[] = {"cppcheck", "--relative-paths", "file.cpp"};
|
||||
ASSERT(defParser.ParseFromArgs(3, argvl));
|
||||
ASSERT(defParser.parseFromArgs(3, argvl));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
|
||||
settings.relativePaths = false;
|
||||
settings.basePaths.clear();
|
||||
|
||||
const char *argvsp[] = {"cppcheck", "-rp=C:/foo;C:\\bar", "file.cpp"};
|
||||
ASSERT(defParser.ParseFromArgs(3, argvsp));
|
||||
ASSERT(defParser.parseFromArgs(3, argvsp));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
ASSERT_EQUALS(2, settings.basePaths.size());
|
||||
ASSERT_EQUALS("C:/foo", settings.basePaths[0]);
|
||||
|
@ -284,7 +284,7 @@ private:
|
|||
settings.basePaths.clear();
|
||||
|
||||
const char *argvlp[] = {"cppcheck", "--relative-paths=C:/foo;C:\\bar", "file.cpp"};
|
||||
ASSERT(defParser.ParseFromArgs(3, argvlp));
|
||||
ASSERT(defParser.parseFromArgs(3, argvlp));
|
||||
ASSERT_EQUALS(true, settings.relativePaths);
|
||||
ASSERT_EQUALS(2, settings.basePaths.size());
|
||||
ASSERT_EQUALS("C:/foo", settings.basePaths[0]);
|
||||
|
@ -295,7 +295,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-q", "file.cpp"};
|
||||
settings.quiet = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.quiet);
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--quiet", "file.cpp"};
|
||||
settings.quiet = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.quiet);
|
||||
}
|
||||
|
||||
|
@ -311,28 +311,28 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D"};
|
||||
// Fails since -D has no param
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
|
||||
void defines_noarg2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
|
||||
// Fails since -D has no param
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void defines_noarg3() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
|
||||
// Fails since -D has no param
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void defines() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"};
|
||||
settings.userDefines.clear();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS("_WIN32=1", settings.userDefines);
|
||||
}
|
||||
|
||||
|
@ -340,7 +340,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"};
|
||||
settings.userDefines.clear();;
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"};
|
||||
settings.userDefines.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("DEBUG=1", settings.userDefines);
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; // #5137 - defining empty macro
|
||||
settings.userDefines.clear();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS("DEBUG=", settings.userDefines);
|
||||
}
|
||||
|
||||
|
@ -365,38 +365,38 @@ private:
|
|||
{
|
||||
const char *argv[] = {"cppcheck", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.ParseFromArgs(2, argv));
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(Settings::None, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "-x", "c++", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "-x"};
|
||||
ASSERT(!defParser.ParseFromArgs(2, argv));
|
||||
ASSERT(!defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "-x", "--inconclusive", "file.cpp"};
|
||||
ASSERT(!defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(!defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--language=c++", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::CPP, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--language=c", "file.cpp"};
|
||||
settings.enforcedLang = Settings::None;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::C, settings.enforcedLang);
|
||||
}
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--language=unknownLanguage", "file.cpp"};
|
||||
ASSERT(!defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(!defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,14 +404,14 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I"};
|
||||
// Fails since -I has no param
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
|
||||
void includes() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
}
|
||||
|
||||
|
@ -435,7 +435,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT(defParser.ParseFromArgs(6, argv));
|
||||
ASSERT(defParser.parseFromArgs(6, argv));
|
||||
ASSERT_EQUALS("include/", settings.includePaths.front());
|
||||
settings.includePaths.pop_front();
|
||||
ASSERT_EQUALS("framework/", settings.includePaths.front());
|
||||
|
@ -454,14 +454,14 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"};
|
||||
settings.includePaths.clear();
|
||||
ASSERT_EQUALS(true, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void enabledAll() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::STYLE));
|
||||
ASSERT(settings.isEnabled(Settings::WARNING));
|
||||
ASSERT(settings.isEnabled(Settings::UNUSED_FUNCTION));
|
||||
|
@ -473,7 +473,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::STYLE));
|
||||
ASSERT(settings.isEnabled(Settings::WARNING));
|
||||
ASSERT(settings.isEnabled(Settings::PERFORMANCE));
|
||||
|
@ -486,7 +486,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(!settings.isEnabled(Settings::STYLE));
|
||||
ASSERT(!settings.isEnabled(Settings::WARNING));
|
||||
ASSERT(settings.isEnabled(Settings::PERFORMANCE));
|
||||
|
@ -499,7 +499,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(!settings.isEnabled(Settings::STYLE));
|
||||
ASSERT(!settings.isEnabled(Settings::WARNING));
|
||||
ASSERT(!settings.isEnabled(Settings::PERFORMANCE));
|
||||
|
@ -512,7 +512,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::UNUSED_FUNCTION));
|
||||
}
|
||||
|
||||
|
@ -520,7 +520,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::MISSING_INCLUDE));
|
||||
}
|
||||
|
||||
|
@ -529,7 +529,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.isEnabled(Settings::INTERNAL));
|
||||
}
|
||||
#endif
|
||||
|
@ -538,7 +538,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--enable=missingInclude,portability,warning", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(!settings.isEnabled(Settings::STYLE));
|
||||
ASSERT(settings.isEnabled(Settings::WARNING));
|
||||
ASSERT(!settings.isEnabled(Settings::PERFORMANCE));
|
||||
|
@ -551,7 +551,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--inconclusive"};
|
||||
settings.inconclusive = false;
|
||||
ASSERT(defParser.ParseFromArgs(2, argv));
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(true, settings.inconclusive);
|
||||
}
|
||||
|
||||
|
@ -559,7 +559,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(5, settings.exitCode);
|
||||
}
|
||||
|
||||
|
@ -568,7 +568,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
// Fails since exit code not given
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void errorExitcodeStr() {
|
||||
|
@ -576,7 +576,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
// Fails since invalid exit code
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void exitcodeSuppressionsOld() {
|
||||
|
@ -584,7 +584,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(4, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void exitcodeSuppressions() {
|
||||
|
@ -592,7 +592,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void exitcodeSuppressionsNoFile() {
|
||||
|
@ -600,14 +600,14 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"};
|
||||
settings.exitCode = 0;
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void fileList() {
|
||||
// TODO: Fails since cannot open the file
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"};
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(4, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
/* void fileListStdin() {
|
||||
|
@ -615,20 +615,20 @@ private:
|
|||
// files in stdin (_pathnames) is empty
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--file-list=-", "file.cpp"};
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
} */
|
||||
|
||||
void inlineSuppr() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"};
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void jobs() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"};
|
||||
settings.jobs = 0;
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(3, settings.jobs);
|
||||
}
|
||||
|
||||
|
@ -637,7 +637,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "-j", "file.cpp"};
|
||||
settings.jobs = 0;
|
||||
// Fails since -j is missing thread count
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void jobsInvalid() {
|
||||
|
@ -645,7 +645,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"};
|
||||
settings.jobs = 0;
|
||||
// Fails since invalid count given for -j
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void maxConfigs() {
|
||||
|
@ -653,7 +653,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"};
|
||||
settings.force = false;
|
||||
settings.maxConfigs = 12;
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(12, settings.maxConfigs);
|
||||
ASSERT_EQUALS(false, settings.force);
|
||||
}
|
||||
|
@ -662,28 +662,28 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"};
|
||||
// Fails since --max-configs= is missing limit
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void maxConfigsInvalid() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"};
|
||||
// Fails since invalid count given for --max-configs=
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void maxConfigsTooSmall() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"};
|
||||
// Fails since limit must be greater than 0
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void reportProgressTest() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"};
|
||||
settings.reportProgress = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.reportProgress);
|
||||
}
|
||||
|
||||
|
@ -691,7 +691,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"};
|
||||
settings.standards.posix = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.standards.posix);
|
||||
}
|
||||
|
||||
|
@ -699,7 +699,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"};
|
||||
settings.standards.c = Standards::C89;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.standards.c == Standards::C99);
|
||||
}
|
||||
|
||||
|
@ -707,7 +707,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"};
|
||||
settings.standards.cpp = Standards::CPP03;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.standards.cpp == Standards::CPP11);
|
||||
}
|
||||
|
||||
|
@ -715,7 +715,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--platform=win64", "file.cpp"};
|
||||
settings.platform(Settings::Unspecified);
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.platformType == Settings::Win64);
|
||||
}
|
||||
|
||||
|
@ -723,14 +723,14 @@ private:
|
|||
// TODO: Fails because there is no suppr.txt file!
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions", "suppr.txt", "file.cpp"};
|
||||
ASSERT(!defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(!defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void suppressions() {
|
||||
// TODO: Fails because there is no suppr.txt file!
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"};
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void suppressionsNoFile() {
|
||||
|
@ -738,21 +738,21 @@ private:
|
|||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"};
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"};
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
@ -769,7 +769,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1)));
|
||||
}
|
||||
|
||||
|
@ -777,7 +777,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
|
||||
}
|
||||
|
||||
|
@ -785,7 +785,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar,noConstructor", "file.cpp"};
|
||||
settings = Settings();
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.parseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
|
||||
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U)));
|
||||
}
|
||||
|
@ -794,7 +794,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=noConstructor", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U)));
|
||||
}
|
||||
|
@ -802,33 +802,33 @@ private:
|
|||
void templates() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "file.cpp"};
|
||||
settings.outputFormat.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings.outputFormat);
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings.templateFormat);
|
||||
}
|
||||
|
||||
void templatesGcc() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
|
||||
settings.outputFormat.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings.outputFormat);
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\\n{code}", settings.templateFormat);
|
||||
}
|
||||
|
||||
void templatesVs() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
|
||||
settings.outputFormat.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings.outputFormat);
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings.templateFormat);
|
||||
}
|
||||
|
||||
void templatesEdit() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
|
||||
settings.outputFormat.clear();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings.outputFormat);
|
||||
settings.templateFormat.clear();
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings.templateFormat);
|
||||
}
|
||||
|
||||
void xml() {
|
||||
|
@ -836,7 +836,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "--xml", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.xml);
|
||||
ASSERT_EQUALS(1, settings.xml_version);
|
||||
}
|
||||
|
@ -846,7 +846,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.xml);
|
||||
ASSERT_EQUALS(2, settings.xml_version);
|
||||
}
|
||||
|
@ -856,7 +856,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT(settings.xml);
|
||||
ASSERT_EQUALS(2, settings.xml_version);
|
||||
}
|
||||
|
@ -866,7 +866,7 @@ private:
|
|||
const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"};
|
||||
settings.xml_version = 1;
|
||||
settings.xml = false;
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT(settings.xml);
|
||||
ASSERT_EQUALS(2, settings.xml_version);
|
||||
}
|
||||
|
@ -875,43 +875,43 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"};
|
||||
// FAils since unknown XML format version
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void xmlverinvalid() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"};
|
||||
// FAils since unknown XML format version
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void doc() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--doc"};
|
||||
ASSERT(defParser.ParseFromArgs(2, argv));
|
||||
ASSERT(defParser.ExitAfterPrinting());
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT(defParser.exitAfterPrinting());
|
||||
}
|
||||
|
||||
void showtime() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--showtime=summary"};
|
||||
settings.showtime = SHOWTIME_NONE;
|
||||
ASSERT(defParser.ParseFromArgs(2, argv));
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT(settings.showtime == SHOWTIME_SUMMARY);
|
||||
}
|
||||
|
||||
void errorlist1() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--errorlist"};
|
||||
ASSERT(defParser.ParseFromArgs(2, argv));
|
||||
ASSERT(defParser.GetShowErrorMessages());
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
ASSERT(defParser.getShowErrorMessages());
|
||||
}
|
||||
|
||||
void errorlistverbose1() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--verbose", "--errorlist"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.verbose);
|
||||
}
|
||||
|
||||
|
@ -919,7 +919,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--errorlist", "--verbose"};
|
||||
settings.verbose = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.verbose);
|
||||
}
|
||||
|
||||
|
@ -928,8 +928,8 @@ private:
|
|||
const char *argv[] = {"cppcheck", "-i"};
|
||||
CmdLineParser parser(&settings);
|
||||
// Fails since no ignored path given
|
||||
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(0, parser.GetIgnoredPaths().size());
|
||||
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(0, parser.getIgnoredPaths().size());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -937,77 +937,77 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-isrc", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||
ASSERT(parser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
|
||||
}
|
||||
|
||||
void ignorepaths2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||
ASSERT(parser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
|
||||
}
|
||||
|
||||
void ignorepaths3() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(2, parser.GetIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||
ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]);
|
||||
ASSERT(parser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
|
||||
ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]);
|
||||
}
|
||||
*/
|
||||
void ignorepaths4() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(6, argv));
|
||||
ASSERT_EQUALS(2, parser.GetIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||
ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]);
|
||||
ASSERT(parser.parseFromArgs(6, argv));
|
||||
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
|
||||
ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]);
|
||||
}
|
||||
/*
|
||||
void ignorefilepaths1() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
||||
ASSERT_EQUALS("foo.cpp", parser.GetIgnoredPaths()[0]);
|
||||
ASSERT(parser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
ASSERT_EQUALS("foo.cpp", parser.getIgnoredPaths()[0]);
|
||||
}
|
||||
*/
|
||||
void ignorefilepaths2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/foo.cpp", parser.GetIgnoredPaths()[0]);
|
||||
ASSERT(parser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||
ASSERT_EQUALS("src/foo.cpp", parser.getIgnoredPaths()[0]);
|
||||
}
|
||||
|
||||
void checkconfig() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--check-config", "file.cpp"};
|
||||
settings.checkConfiguration = false;
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, settings.checkConfiguration);
|
||||
}
|
||||
|
||||
void unknownParam() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--foo", "file.cpp"};
|
||||
ASSERT(!defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(!defParser.parseFromArgs(3, argv));
|
||||
}
|
||||
|
||||
void undefs() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(3, argv));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(1, settings.userUndefs.size());
|
||||
ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end());
|
||||
}
|
||||
|
@ -1016,7 +1016,7 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT(defParser.parseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(2, settings.userUndefs.size());
|
||||
ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end());
|
||||
ASSERT(settings.userUndefs.find("NODEBUG") != settings.userUndefs.end());
|
||||
|
@ -1026,21 +1026,21 @@ private:
|
|||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U"};
|
||||
// Fails since -U has no param
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(2, argv));
|
||||
}
|
||||
|
||||
void undefs_noarg2() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"};
|
||||
// Fails since -U has no param
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
|
||||
void undefs_noarg3() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"};
|
||||
// Fails since -U has no param
|
||||
ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(false, defParser.parseFromArgs(4, argv));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue