diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index d6c792645c1e..f90dd7b6ab5c 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -422,11 +422,18 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a return Result::Exit; } + if (std::strcmp(argv[i], "--filesdir") == 0) { +#ifdef FILESDIR + mLogger.printRaw(FILESDIR); // TODO: should not include newline +#endif + return Result::Exit; + } + if (std::strcmp(argv[i], "--version") == 0) { if (!loadCppcheckCfg()) return Result::Fail; const std::string version = getVersion(); - mLogger.printRaw(version); + mLogger.printRaw(version); // TODO: should not include newline return Result::Exit; } } @@ -1723,6 +1730,7 @@ void CmdLineParser::printHelp() const " --file-list= Specify the files to check in a text file. Add one\n" " filename per line. When file is '-,' the file list will\n" " be read from standard input.\n" + " --filesdir Print the built-in FILESDIR.\n" " -f, --force Force checking of all configurations in files. If used\n" " together with '--max-configs=', the last option is the\n" " one that is effective.\n" diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 33d57ead69be..3932f8edf3f7 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -241,7 +241,7 @@ namespace { void printRaw(const std::string &message) override { - std::cout << message << std::endl; + std::cout << message << std::endl; // TODO: should not append newline } }; diff --git a/man/cppcheck.1.xml b/man/cppcheck.1.xml index 138f54700362..1265e0f35112 100644 --- a/man/cppcheck.1.xml +++ b/man/cppcheck.1.xml @@ -123,6 +123,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ + + + @@ -356,6 +359,14 @@ Example: '-UDEBUG' Specify the files to check in a text file. One filename per line. When file is -, the file list will be read from standard input. + + + + + + Print the built-in FILESDIR. + + diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 8dea8cbaaeff..0009c42d109f 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -65,7 +65,7 @@ class TestCmdlineParser : public TestFixture { void printRaw(const std::string &message) override { - printInternal(message + '\n'); + printInternal(message + '\n'); // TODO: should not append newline } std::string str() @@ -430,6 +430,7 @@ class TestCmdlineParser : public TestFixture { TEST_CASE(debugClangOutput); TEST_CASE(debugXmlMultiple); TEST_CASE(debugNormalXmlMultiple); + TEST_CASE(filesdir); TEST_CASE(ignorepaths1); TEST_CASE(ignorepaths2); @@ -2964,6 +2965,17 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS("cppcheck: error: printing debug output in XML format does not support multiple input files.\n", logger->str()); } + void filesdir() { + REDIRECT; + const char * const argv[] = {"cppcheck", "--filesdir"}; + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv)); +#ifdef FILESDIR + ASSERT_EQUALS(std::string(FILESDIR) + '\n', logger->str()); +#else + ASSERT_EQUALS("", logger->str()); +#endif + } + void ignorepaths1() { REDIRECT; const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};