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