2010-09-06 21:31:06 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2012-01-01 00:05:37 +01:00
|
|
|
* Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
|
2010-09-06 21:31:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "testsuite.h"
|
|
|
|
#include "cmdlineparser.h"
|
|
|
|
#include "settings.h"
|
2010-09-26 05:19:30 +02:00
|
|
|
#include "redirect.h"
|
2010-09-06 21:31:06 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
class TestCmdlineParser : public TestFixture {
|
2010-09-06 21:31:06 +02:00
|
|
|
public:
|
|
|
|
TestCmdlineParser() : TestFixture("TestCmdlineParser")
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void run() {
|
2010-09-06 21:31:06 +02:00
|
|
|
TEST_CASE(nooptions);
|
|
|
|
TEST_CASE(helpshort);
|
|
|
|
TEST_CASE(helplong);
|
|
|
|
TEST_CASE(showversion);
|
2010-09-06 22:16:52 +02:00
|
|
|
TEST_CASE(onefile);
|
|
|
|
TEST_CASE(onepath);
|
|
|
|
TEST_CASE(optionwithoutfile);
|
|
|
|
TEST_CASE(verboseshort);
|
|
|
|
TEST_CASE(verboselong);
|
|
|
|
TEST_CASE(debug);
|
|
|
|
TEST_CASE(debugwarnings);
|
|
|
|
TEST_CASE(forceshort);
|
|
|
|
TEST_CASE(forcelong);
|
2012-04-06 10:49:21 +02:00
|
|
|
TEST_CASE(relativePaths);
|
2010-09-06 22:16:52 +02:00
|
|
|
TEST_CASE(quietshort);
|
|
|
|
TEST_CASE(quietlong);
|
2011-01-17 20:03:22 +01:00
|
|
|
TEST_CASE(defines_noarg);
|
2011-01-17 20:19:27 +01:00
|
|
|
TEST_CASE(defines_noarg2);
|
|
|
|
TEST_CASE(defines_noarg3);
|
2010-09-08 17:02:22 +02:00
|
|
|
TEST_CASE(defines);
|
|
|
|
TEST_CASE(defines2);
|
2010-09-08 17:42:28 +02:00
|
|
|
TEST_CASE(defines3);
|
2012-08-01 20:18:03 +02:00
|
|
|
//TEST_CASE(defines4);
|
2010-09-08 17:02:22 +02:00
|
|
|
TEST_CASE(includesnopath);
|
|
|
|
TEST_CASE(includes);
|
2011-01-11 20:03:18 +01:00
|
|
|
TEST_CASE(includesslash);
|
|
|
|
TEST_CASE(includesbackslash);
|
|
|
|
TEST_CASE(includesnospace);
|
2010-09-08 17:02:22 +02:00
|
|
|
TEST_CASE(includes2);
|
2011-10-22 21:24:23 +02:00
|
|
|
TEST_CASE(includesFile);
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(enabledAll);
|
|
|
|
TEST_CASE(enabledStyle);
|
2011-09-04 20:42:35 +02:00
|
|
|
TEST_CASE(enabledPerformance);
|
|
|
|
TEST_CASE(enabledPortability);
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(enabledUnusedFunction);
|
|
|
|
TEST_CASE(enabledMissingInclude);
|
2011-10-29 12:47:12 +02:00
|
|
|
#ifndef NDEBUG
|
2011-10-28 22:39:46 +02:00
|
|
|
TEST_CASE(enabledInternal);
|
2011-10-29 12:47:12 +02:00
|
|
|
#endif
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(errorExitcode);
|
|
|
|
TEST_CASE(errorExitcodeMissing);
|
|
|
|
TEST_CASE(errorExitcodeStr);
|
2011-01-29 18:04:52 +01:00
|
|
|
TEST_CASE(exitcodeSuppressionsOld); // TODO: Create and test real suppression file
|
|
|
|
TEST_CASE(exitcodeSuppressions);
|
|
|
|
TEST_CASE(exitcodeSuppressionsNoFile);
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(fileList); // TODO: Create and test real file listing file
|
2011-09-30 07:35:23 +02:00
|
|
|
// TEST_CASE(fileListStdin); // Disabled since hangs the test run
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(inlineSuppr);
|
|
|
|
TEST_CASE(jobs);
|
|
|
|
TEST_CASE(jobsMissingCount);
|
|
|
|
TEST_CASE(jobsInvalid);
|
2011-10-05 07:37:43 +02:00
|
|
|
TEST_CASE(maxConfigs);
|
|
|
|
TEST_CASE(maxConfigsMissingCount);
|
|
|
|
TEST_CASE(maxConfigsInvalid);
|
|
|
|
TEST_CASE(maxConfigsTooSmall);
|
2011-09-17 16:55:59 +02:00
|
|
|
TEST_CASE(reportProgressTest); // "Test" suffix to avoid hiding the parent's reportProgress
|
2011-08-17 20:08:55 +02:00
|
|
|
TEST_CASE(stdposix);
|
2011-10-06 08:10:51 +02:00
|
|
|
TEST_CASE(stdc99);
|
2011-10-16 12:54:58 +02:00
|
|
|
TEST_CASE(stdcpp11);
|
2011-01-28 12:18:07 +01:00
|
|
|
TEST_CASE(suppressionsOld); // TODO: Create and test real suppression file
|
2011-07-29 21:00:24 +02:00
|
|
|
TEST_CASE(suppressions);
|
|
|
|
TEST_CASE(suppressionsNoFile);
|
|
|
|
TEST_CASE(suppressionSingle);
|
|
|
|
TEST_CASE(suppressionSingleFile);
|
2011-09-13 16:55:00 +02:00
|
|
|
TEST_CASE(suppressionTwo);
|
|
|
|
TEST_CASE(suppressionTwoSeparate);
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(templates);
|
|
|
|
TEST_CASE(templatesGcc);
|
|
|
|
TEST_CASE(templatesVs);
|
2011-10-29 23:26:35 +02:00
|
|
|
TEST_CASE(templatesEdit);
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(xml);
|
2011-02-02 13:04:50 +01:00
|
|
|
TEST_CASE(xmlver1);
|
2011-01-27 13:25:10 +01:00
|
|
|
TEST_CASE(xmlver2);
|
|
|
|
TEST_CASE(xmlver2both);
|
|
|
|
TEST_CASE(xmlver2both2);
|
2011-02-02 12:33:57 +01:00
|
|
|
TEST_CASE(xmlverunknown);
|
|
|
|
TEST_CASE(xmlverinvalid);
|
2011-01-27 10:14:08 +01:00
|
|
|
TEST_CASE(errorlist1);
|
2011-07-29 21:00:24 +02:00
|
|
|
TEST_CASE(errorlistverbose1);
|
|
|
|
TEST_CASE(errorlistverbose2);
|
|
|
|
TEST_CASE(ignorepathsnopath);
|
2011-08-06 18:18:20 +02:00
|
|
|
|
|
|
|
// Disabling these tests since they use relative paths to the
|
|
|
|
// testrunner executable.
|
|
|
|
//TEST_CASE(ignorepaths1);
|
|
|
|
//TEST_CASE(ignorepaths2);
|
|
|
|
//TEST_CASE(ignorepaths3);
|
|
|
|
//TEST_CASE(ignorepaths4);
|
|
|
|
//TEST_CASE(ignorefilepaths1);
|
|
|
|
//TEST_CASE(ignorefilepaths2);
|
|
|
|
|
2011-07-29 21:00:24 +02:00
|
|
|
TEST_CASE(checkconfig);
|
2010-12-04 13:13:44 +01:00
|
|
|
TEST_CASE(unknownParam);
|
2011-11-30 20:24:01 +01:00
|
|
|
|
|
|
|
TEST_CASE(undefs_noarg);
|
|
|
|
TEST_CASE(undefs_noarg2);
|
|
|
|
TEST_CASE(undefs_noarg3);
|
|
|
|
TEST_CASE(undefs);
|
|
|
|
TEST_CASE(undefs2);
|
2010-09-06 21:31:06 +02:00
|
|
|
}
|
|
|
|
|
2010-12-04 13:13:44 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void nooptions() {
|
2010-09-06 21:31:06 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(1, argv));
|
|
|
|
ASSERT_EQUALS(true, parser.GetShowHelp());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void helpshort() {
|
2010-09-06 21:31:06 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-h"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(2, argv));
|
|
|
|
ASSERT_EQUALS(true, parser.GetShowHelp());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void helplong() {
|
2010-09-06 21:31:06 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--help"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(2, argv));
|
|
|
|
ASSERT_EQUALS(true, parser.GetShowHelp());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void showversion() {
|
2010-09-06 21:31:06 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--version"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(2, argv));
|
|
|
|
ASSERT_EQUALS(true, parser.GetShowVersion());
|
|
|
|
}
|
2010-09-06 22:16:52 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onefile() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(2, argv));
|
2011-01-01 09:16:31 +01:00
|
|
|
ASSERT_EQUALS(1, (int)parser.GetPathNames().size());
|
2010-09-06 22:16:52 +02:00
|
|
|
ASSERT_EQUALS("file.cpp", parser.GetPathNames().at(0));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onepath() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "src"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(2, argv));
|
2011-01-01 09:16:31 +01:00
|
|
|
ASSERT_EQUALS(1, (int)parser.GetPathNames().size());
|
2010-09-06 22:16:52 +02:00
|
|
|
ASSERT_EQUALS("src", parser.GetPathNames().at(0));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void optionwithoutfile() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-v"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
|
2011-01-01 09:16:31 +01:00
|
|
|
ASSERT_EQUALS(0, (int)parser.GetPathNames().size());
|
2010-09-06 22:16:52 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void verboseshort() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "-v", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings._verbose);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void verboselong() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "--verbose", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings._verbose);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void debug() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "--debug", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings.debug);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void debugwarnings() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings.debugwarnings);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void forceshort() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "-f", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings._force);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void forcelong() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "--force", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings._force);
|
|
|
|
}
|
|
|
|
|
2012-04-06 10:49:21 +02:00
|
|
|
void relativePaths() {
|
|
|
|
REDIRECT;
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
|
|
|
|
const char *argvs[] = {"cppcheck", "-rp", "file.cpp"};
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argvs));
|
|
|
|
ASSERT_EQUALS(true, settings._relativePaths);
|
|
|
|
|
|
|
|
settings._relativePaths = false;
|
|
|
|
|
|
|
|
const char *argvl[] = {"cppcheck", "--relative-paths", "file.cpp"};
|
|
|
|
ASSERT(parser.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(parser.ParseFromArgs(3, argvsp));
|
|
|
|
ASSERT_EQUALS(true, settings._relativePaths);
|
|
|
|
ASSERT_EQUALS(2, settings._basePaths.size());
|
|
|
|
ASSERT_EQUALS("C:/foo", settings._basePaths[0]);
|
|
|
|
ASSERT_EQUALS("C:/bar", settings._basePaths[1]);
|
|
|
|
|
|
|
|
settings._relativePaths = false;
|
|
|
|
settings._basePaths.clear();
|
|
|
|
|
|
|
|
const char *argvlp[] = {"cppcheck", "--relative-paths=C:/foo;C:\\bar", "file.cpp"};
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argvlp));
|
|
|
|
ASSERT_EQUALS(true, settings._relativePaths);
|
|
|
|
ASSERT_EQUALS(2, settings._basePaths.size());
|
|
|
|
ASSERT_EQUALS("C:/foo", settings._basePaths[0]);
|
|
|
|
ASSERT_EQUALS("C:/bar", settings._basePaths[1]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void quietshort() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "-q", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings._errorsOnly);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void quietlong() {
|
2010-09-06 22:16:52 +02:00
|
|
|
REDIRECT;
|
2010-09-06 23:12:24 +02:00
|
|
|
const char *argv[] = {"cppcheck", "--quiet", "file.cpp"};
|
2010-09-06 22:16:52 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings._errorsOnly);
|
|
|
|
}
|
2010-09-08 17:02:22 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void defines_noarg() {
|
2011-01-17 20:03:22 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-D"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since -D has no param
|
2011-01-17 20:03:22 +01:00
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void defines_noarg2() {
|
2011-01-17 20:19:27 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since -D has no param
|
2011-01-17 20:19:27 +01:00
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void defines_noarg3() {
|
2011-01-17 20:19:27 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since -D has no param
|
2011-01-17 20:19:27 +01:00
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void defines() {
|
2010-09-08 17:02:22 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
2012-07-05 19:35:41 +02:00
|
|
|
ASSERT_EQUALS("_WIN32=1", settings.userDefines);
|
2010-09-08 17:02:22 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void defines2() {
|
2010-09-08 17:02:22 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
2012-07-05 19:35:41 +02:00
|
|
|
ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines);
|
2010-09-08 17:02:22 +02:00
|
|
|
}
|
2010-09-08 17:42:28 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void defines3() {
|
2010-09-08 17:42:28 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
2012-07-05 19:35:41 +02:00
|
|
|
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));
|
2010-09-08 17:42:28 +02:00
|
|
|
ASSERT_EQUALS("DEBUG", settings.userDefines);
|
|
|
|
}
|
2010-09-08 17:02:22 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void includesnopath() {
|
2010-09-08 17:02:22 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-I", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since -I has no param
|
2010-09-08 17:02:22 +02:00
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void includes() {
|
2010-09-08 17:02:22 +02:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"};
|
2010-09-08 17:02:22 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-01-29 18:16:23 +01:00
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS("include/", settings._includePaths.front());
|
2010-09-08 17:02:22 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void includesslash() {
|
2011-01-11 20:03:18 +01:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"};
|
2011-01-11 20:03:18 +01:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-01-29 18:16:23 +01:00
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS("include/", settings._includePaths.front());
|
2011-01-11 20:03:18 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void includesbackslash() {
|
2011-01-11 20:03:18 +01:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"};
|
2011-01-11 20:03:18 +01:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-01-29 18:16:23 +01:00
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS("include/", settings._includePaths.front());
|
2011-01-11 20:03:18 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void includesnospace() {
|
2011-01-11 20:03:18 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS("include/", settings._includePaths.front());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void includes2() {
|
2010-09-08 17:02:22 +02:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"};
|
2010-09-08 17:02:22 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-01-29 18:16:23 +01:00
|
|
|
ASSERT(parser.ParseFromArgs(6, argv));
|
|
|
|
ASSERT_EQUALS("include/", settings._includePaths.front());
|
2010-09-08 17:02:22 +02:00
|
|
|
settings._includePaths.pop_front();
|
2011-01-29 18:16:23 +01:00
|
|
|
ASSERT_EQUALS("framework/", settings._includePaths.front());
|
2010-09-08 17:02:22 +02:00
|
|
|
}
|
2010-12-04 13:13:44 +01:00
|
|
|
|
2011-10-23 10:11:43 +02:00
|
|
|
void includesFile() {
|
2011-10-22 21:24:23 +02:00
|
|
|
// TODO: Fails since cannot open the file
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-10-23 10:21:55 +02:00
|
|
|
ASSERT_EQUALS(true, parser.ParseFromArgs(3, argv));
|
2011-10-22 21:24:23 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void enabledAll() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
2011-08-07 09:28:08 +02:00
|
|
|
ASSERT(settings.isEnabled("style"));
|
2010-12-04 13:13:44 +01:00
|
|
|
ASSERT(settings.isEnabled("unusedFunction"));
|
|
|
|
ASSERT(settings.isEnabled("missingInclude"));
|
2011-10-28 22:39:46 +02:00
|
|
|
ASSERT(!settings.isEnabled("internal"));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void enabledStyle() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
2011-08-07 09:28:08 +02:00
|
|
|
ASSERT(settings.isEnabled("style"));
|
2011-09-04 20:42:35 +02:00
|
|
|
ASSERT(settings.isEnabled("performance"));
|
|
|
|
ASSERT(settings.isEnabled("portability"));
|
|
|
|
ASSERT(!settings.isEnabled("unusedFunction"));
|
|
|
|
ASSERT(!settings.isEnabled("missingInclude"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void enabledPerformance() {
|
2011-09-04 20:42:35 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(!settings.isEnabled("style"));
|
|
|
|
ASSERT(settings.isEnabled("performance"));
|
|
|
|
ASSERT(!settings.isEnabled("portability"));
|
|
|
|
ASSERT(!settings.isEnabled("unusedFunction"));
|
|
|
|
ASSERT(!settings.isEnabled("missingInclude"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void enabledPortability() {
|
2011-09-04 20:42:35 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(!settings.isEnabled("style"));
|
|
|
|
ASSERT(!settings.isEnabled("performance"));
|
|
|
|
ASSERT(settings.isEnabled("portability"));
|
|
|
|
ASSERT(!settings.isEnabled("unusedFunction"));
|
|
|
|
ASSERT(!settings.isEnabled("missingInclude"));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void enabledUnusedFunction() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings.isEnabled("unusedFunction"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void enabledMissingInclude() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings.isEnabled("missingInclude"));
|
|
|
|
}
|
|
|
|
|
2011-10-29 12:47:12 +02:00
|
|
|
#ifndef NDEBUG
|
2011-10-28 22:39:46 +02:00
|
|
|
void enabledInternal() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings.isEnabled("internal"));
|
|
|
|
}
|
2011-10-29 12:47:12 +02:00
|
|
|
#endif
|
2011-10-28 22:39:46 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void errorExitcode() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(5, settings._exitCode);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void errorExitcodeMissing() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since exit code not given
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void errorExitcodeStr() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since invalid exit code
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void exitcodeSuppressionsOld() {
|
2011-01-29 18:04:52 +01:00
|
|
|
// TODO: Fails since cannot open the file
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv));
|
2011-01-29 18:04:52 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void exitcodeSuppressions() {
|
2011-05-04 20:00:22 +02:00
|
|
|
// TODO: Fails since cannot open the file
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
2011-01-29 18:04:52 +01:00
|
|
|
const char *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
|
2011-01-29 18:04:52 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void exitcodeSuppressionsNoFile() {
|
2011-05-04 20:00:22 +02:00
|
|
|
// TODO: Fails since cannot open the file
|
2011-01-29 18:04:52 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"};
|
2010-12-04 13:13:44 +01:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void fileList() {
|
2011-05-04 20:00:22 +02:00
|
|
|
// TODO: Fails since cannot open the file
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"};
|
2010-12-04 13:13:44 +01:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
2011-09-30 01:23:30 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void fileListStdin() {
|
2011-09-27 08:02:58 +02:00
|
|
|
// TODO: Give it some stdin to read from, fails because the list of
|
|
|
|
// files in stdin (_pathnames) is empty
|
2011-09-27 03:43:39 +02:00
|
|
|
REDIRECT;
|
2011-09-27 08:02:58 +02:00
|
|
|
const char *argv[] = {"cppcheck", "--file-list=-", "file.cpp"};
|
2011-09-27 03:43:39 +02:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-09-27 08:02:58 +02:00
|
|
|
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
|
2011-09-27 03:43:39 +02:00
|
|
|
}
|
2010-12-04 13:13:44 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void inlineSuppr() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void jobs() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"};
|
2010-12-04 13:13:44 +01:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-01-29 18:16:23 +01:00
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
ASSERT_EQUALS(3, settings._jobs);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void jobsMissingCount() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-j", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since -j is missing thread count
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void jobsInvalid() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"};
|
2010-12-04 13:13:44 +01:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since invalid count given for -j
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-05 07:37:43 +02:00
|
|
|
void maxConfigs() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS(12, settings._maxConfigs);
|
2011-10-22 11:11:54 +02:00
|
|
|
ASSERT_EQUALS(false, settings._force);
|
2011-10-05 07:37:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void maxConfigsMissingCount() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
// Fails since --max-configs= is missing limit
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
|
|
|
}
|
|
|
|
|
|
|
|
void maxConfigsInvalid() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
// Fails since invalid count given for --max-configs=
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
|
|
|
}
|
|
|
|
|
|
|
|
void maxConfigsTooSmall() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
// Fails since limit must be greater than 0
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
2011-10-22 11:11:54 +02:00
|
|
|
}
|
2011-10-05 07:37:43 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void reportProgressTest() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
2012-01-02 07:42:39 +01:00
|
|
|
ASSERT(settings.reportProgress);
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void stdposix() {
|
2011-08-17 20:08:55 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
2011-10-22 09:45:48 +02:00
|
|
|
ASSERT(settings.standards.posix);
|
2011-08-17 20:08:55 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void stdc99() {
|
2011-10-06 08:10:51 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
2011-10-22 09:45:48 +02:00
|
|
|
ASSERT(settings.standards.c99);
|
2011-10-06 08:10:51 +02:00
|
|
|
}
|
|
|
|
|
2011-10-16 12:54:58 +02:00
|
|
|
void stdcpp11() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
2011-10-22 09:45:48 +02:00
|
|
|
ASSERT(settings.standards.cpp11);
|
2011-10-16 12:54:58 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void suppressionsOld() {
|
2011-01-28 12:18:07 +01:00
|
|
|
// TODO: Fails because there is no suppr.txt file!
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
2011-01-29 18:16:23 +01:00
|
|
|
const char *argv[] = {"cppcheck", "--suppressions", "suppr.txt", "file.cpp"};
|
2010-12-04 13:13:44 +01:00
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-01-29 18:16:23 +01:00
|
|
|
ASSERT(!parser.ParseFromArgs(4, argv));
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void suppressions() {
|
2011-01-28 12:18:07 +01:00
|
|
|
// TODO: Fails because there is no suppr.txt file!
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
|
2011-01-28 12:18:07 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void suppressionsNoFile() {
|
2011-01-28 12:18:07 +01:00
|
|
|
REDIRECT;
|
2012-01-12 21:21:51 +01:00
|
|
|
{
|
|
|
|
CLEAR_REDIRECT_OUTPUT;
|
|
|
|
const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT_EQUALS(false, parser.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"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT_EQUALS(false, parser.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"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
|
|
|
}
|
2011-01-28 12:18:07 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void suppressionSingle() {
|
2011-02-16 10:26:40 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void suppressionSingleFile() {
|
2011-02-16 10:26:40 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void suppressionTwo() {
|
2011-09-13 16:55:00 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--suppress=uninitvar,unnecessaryQualification", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
|
|
|
|
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
|
|
|
|
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void suppressionTwoSeparate() {
|
2011-09-13 16:55:00 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=unnecessaryQualification", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
|
|
|
|
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void templates() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings._outputFormat);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void templatesGcc() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings._outputFormat);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void templatesVs() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings._outputFormat);
|
|
|
|
}
|
|
|
|
|
2011-10-29 23:26:35 +02:00
|
|
|
void templatesEdit() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings._outputFormat);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void xml() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--xml", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings._xml);
|
2011-01-27 13:25:10 +01:00
|
|
|
ASSERT_EQUALS(1, settings._xml_version);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void xmlver1() {
|
2011-02-02 13:04:50 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings._xml);
|
|
|
|
ASSERT_EQUALS(1, settings._xml_version);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void xmlver2() {
|
2011-01-27 13:25:10 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings._xml);
|
|
|
|
ASSERT_EQUALS(2, settings._xml_version);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void xmlver2both() {
|
2011-01-27 13:25:10 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT(settings._xml);
|
|
|
|
ASSERT_EQUALS(2, settings._xml_version);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void xmlver2both2() {
|
2011-01-27 13:25:10 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT(settings._xml);
|
|
|
|
ASSERT_EQUALS(2, settings._xml_version);
|
2010-12-04 13:13:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void xmlverunknown() {
|
2011-02-02 12:33:57 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// FAils since unknown XML format version
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
|
2011-02-02 12:33:57 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void xmlverinvalid() {
|
2011-02-02 12:33:57 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// FAils since unknown XML format version
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
|
2011-02-02 12:33:57 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void errorlist1() {
|
2011-01-27 10:14:08 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--errorlist"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(2, argv));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void errorlistverbose1() {
|
2011-01-27 10:14:08 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--verbose", "--errorlist"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings._verbose);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void errorlistverbose2() {
|
2011-01-27 10:14:08 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--errorlist", "--verbose"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT(settings._verbose);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void ignorepathsnopath() {
|
2011-01-31 14:25:51 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-i"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
2011-05-04 20:00:22 +02:00
|
|
|
// Fails since no ignored path given
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
|
2011-01-31 14:25:51 +01:00
|
|
|
ASSERT_EQUALS(0, parser.GetIgnoredPaths().size());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void ignorepaths1() {
|
2011-01-31 14:25:51 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-isrc", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
|
|
|
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void ignorepaths2() {
|
2011-01-31 14:25:51 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(4, argv));
|
|
|
|
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
|
|
|
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void ignorepaths3() {
|
2011-01-31 14:25:51 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void ignorepaths4() {
|
2011-01-31 14:25:51 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void ignorefilepaths1() {
|
2011-02-03 13:43:42 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
|
|
|
ASSERT_EQUALS("foo.cpp", parser.GetIgnoredPaths()[0]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void ignorefilepaths2() {
|
2011-02-03 13:43:42 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
|
|
|
ASSERT_EQUALS("src/foo.cpp", parser.GetIgnoredPaths()[0]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void checkconfig() {
|
2011-05-04 20:07:02 +02:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--check-config", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(true, settings.checkConfiguration);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void unknownParam() {
|
2010-12-04 13:13:44 +01:00
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "--foo", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(!parser.ParseFromArgs(3, argv));
|
|
|
|
}
|
2011-11-30 20:24:01 +01:00
|
|
|
|
|
|
|
void undefs() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.ParseFromArgs(3, argv));
|
|
|
|
ASSERT_EQUALS(1, settings.userUndefs.size());
|
|
|
|
ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
void undefs2() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
ASSERT(parser.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());
|
|
|
|
}
|
|
|
|
|
|
|
|
void undefs_noarg() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-U"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
// Fails since -U has no param
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
|
|
|
|
}
|
|
|
|
|
|
|
|
void undefs_noarg2() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
// Fails since -U has no param
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
|
|
|
|
}
|
|
|
|
|
|
|
|
void undefs_noarg3() {
|
|
|
|
REDIRECT;
|
|
|
|
const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"};
|
|
|
|
Settings settings;
|
|
|
|
CmdLineParser parser(&settings);
|
|
|
|
// Fails since -U has no param
|
|
|
|
ASSERT_EQUALS(false, parser.ParseFromArgs(4, argv));
|
|
|
|
}
|
2010-09-06 21:31:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestCmdlineParser)
|