From e7cffba74b9121ddf897c7df99e091a3f41ce88f Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 1 Jul 2024 14:17:14 +0200 Subject: [PATCH] fixed #12811 - added CLI option `--filesdir` to show the built-in `FILESDIR` / added TODOs --- cli/cmdlineparser.cpp | 9 ++++++++- cli/cppcheckexecutor.cpp | 2 +- man/cppcheck.1.xml | 11 +++++++++++ test/testcmdlineparser.cpp | 14 +++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index b63e9ec0591..bbf237a539a 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; } } diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index de799cace7f..4beca5055be 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 138f5470036..1265e0f3511 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 5485f97d45e..bc536c453c5 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() @@ -444,6 +444,7 @@ class TestCmdlineParser : public TestFixture { TEST_CASE(checkHeaders); TEST_CASE(noCheckHeaders); TEST_CASE(noCheckHeaders2); + TEST_CASE(filesdir); TEST_CASE(ignorepaths1); TEST_CASE(ignorepaths2); @@ -3012,6 +3013,17 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS(false, settings->checkHeaders); } + void filesdir() { + REDIRECT; + const char * const argv[] = {"cppcheck", "--filesdir"}; + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parseFromArgs(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"};