Skip to content

Commit 313cec4

Browse files
authored
fixed #12811 - added CLI option --filesdir to show the built-in FILESDIR / added TODOs (#7200)
1 parent b1bbada commit 313cec4

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

cli/cmdlineparser.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,18 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
422422
return Result::Exit;
423423
}
424424

425+
if (std::strcmp(argv[i], "--filesdir") == 0) {
426+
#ifdef FILESDIR
427+
mLogger.printRaw(FILESDIR); // TODO: should not include newline
428+
#endif
429+
return Result::Exit;
430+
}
431+
425432
if (std::strcmp(argv[i], "--version") == 0) {
426433
if (!loadCppcheckCfg())
427434
return Result::Fail;
428435
const std::string version = getVersion();
429-
mLogger.printRaw(version);
436+
mLogger.printRaw(version); // TODO: should not include newline
430437
return Result::Exit;
431438
}
432439
}

cli/cppcheckexecutor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ namespace {
241241

242242
void printRaw(const std::string &message) override
243243
{
244-
std::cout << message << std::endl;
244+
std::cout << message << std::endl; // TODO: should not append newline
245245
}
246246
};
247247

man/cppcheck.1.xml

+11
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
123123
<arg choice="opt">
124124
<option>--file-list=&lt;file&gt;</option>
125125
</arg>
126+
<arg choice="opt">
127+
<option>--filesdir</option>
128+
</arg>
126129
<arg choice="opt">
127130
<option>--force</option>
128131
</arg>
@@ -356,6 +359,14 @@ Example: '-UDEBUG'</para>
356359
<para>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.</para>
357360
</listitem>
358361
</varlistentry>
362+
<varlistentry>
363+
<term>
364+
<option>--filesdir</option>
365+
</term>
366+
<listitem>
367+
<para>Print the built-in FILESDIR.</para>
368+
</listitem>
369+
</varlistentry>
359370
<varlistentry>
360371
<term>
361372
<option>-f</option>

test/testcmdlineparser.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class TestCmdlineParser : public TestFixture {
6565

6666
void printRaw(const std::string &message) override
6767
{
68-
printInternal(message + '\n');
68+
printInternal(message + '\n'); // TODO: should not append newline
6969
}
7070

7171
std::string str()
@@ -444,6 +444,7 @@ class TestCmdlineParser : public TestFixture {
444444
TEST_CASE(checkHeaders);
445445
TEST_CASE(noCheckHeaders);
446446
TEST_CASE(noCheckHeaders2);
447+
TEST_CASE(filesdir);
447448

448449
TEST_CASE(ignorepaths1);
449450
TEST_CASE(ignorepaths2);
@@ -3012,6 +3013,17 @@ class TestCmdlineParser : public TestFixture {
30123013
ASSERT_EQUALS(false, settings->checkHeaders);
30133014
}
30143015

3016+
void filesdir() {
3017+
REDIRECT;
3018+
const char * const argv[] = {"cppcheck", "--filesdir"};
3019+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parseFromArgs(argv));
3020+
#ifdef FILESDIR
3021+
ASSERT_EQUALS(std::string(FILESDIR) + '\n', logger->str());
3022+
#else
3023+
ASSERT_EQUALS("", logger->str());
3024+
#endif
3025+
}
3026+
30153027
void ignorepaths1() {
30163028
REDIRECT;
30173029
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

0 commit comments

Comments
 (0)