Fix #3510 (Improve error message for --suppressions-list)
http://sourceforge.net/apps/trac/cppcheck/ticket/3510 Print additional info to error message if we suspect that multiple files were given.
This commit is contained in:
parent
34105cb17e
commit
da09adc583
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
@ -178,6 +179,15 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
std::string message("cppcheck: Couldn't open the file: \"");
|
||||
message += std::string(filename);
|
||||
message += "\".";
|
||||
if (count(filename.begin(), filename.end(), ',') > 0 ||
|
||||
count(filename.begin(), filename.end(), '.') > 1) {
|
||||
// If user tried to pass multiple files (we can only guess that)
|
||||
// e.g. like this: --suppressions-list=a.txt,b.txt
|
||||
// print more detailed error message to tell user how he can solve the problem
|
||||
message += "\nIf you want to pass two files, you can do it e.g. like this:";
|
||||
message += "\n cppcheck --suppressions-list=a.txt --suppressions-list=b.txt file.cpp";
|
||||
}
|
||||
|
||||
PrintMessage(message);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,17 @@ public:
|
|||
output << _out.str();
|
||||
}
|
||||
|
||||
/** Return what would be printed to cout. See also clearOutput() */
|
||||
std::string getOutput() {
|
||||
return _out.str();
|
||||
}
|
||||
|
||||
/** Normally called after getOutput() to prevent same text to be returned
|
||||
twice. */
|
||||
void clearOutput() {
|
||||
_out.str("");
|
||||
}
|
||||
|
||||
private:
|
||||
std::stringstream _out;
|
||||
std::stringstream _err;
|
||||
|
@ -58,5 +69,7 @@ private:
|
|||
};
|
||||
|
||||
#define REDIRECT RedirectOutputError redir;
|
||||
#define GET_REDIRECT_OUTPUT redir.getOutput()
|
||||
#define CLEAR_REDIRECT_OUTPUT redir.clearOutput()
|
||||
|
||||
#endif
|
||||
|
|
|
@ -665,12 +665,33 @@ private:
|
|||
}
|
||||
|
||||
void suppressionsNoFile() {
|
||||
// TODO: Fails because there is no suppr.txt file!
|
||||
REDIRECT;
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=", "file.cpp"};
|
||||
Settings settings;
|
||||
CmdLineParser parser(&settings);
|
||||
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(false, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr,b.suppr", "file.cpp"};
|
||||
Settings settings;
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
CLEAR_REDIRECT_OUTPUT;
|
||||
const char *argv[] = {"cppcheck", "--suppressions-list=a.suppr b.suppr", "file.cpp"};
|
||||
Settings settings;
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(true, GET_REDIRECT_OUTPUT.find("If you want to pass two files") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
void suppressionSingle() {
|
||||
|
|
Loading…
Reference in New Issue