Skip to content

Commit 57fd879

Browse files
committed
CmdLineParser: cppcheck.cfg was not loaded from executable folder for exclusive options
1 parent 0cf0c33 commit 57fd879

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ test/testclangimport.o: test/testclangimport.cpp lib/addoninfo.h lib/check.h lib
728728
test/testclass.o: test/testclass.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
729729
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclass.cpp
730730

731-
test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h test/redirect.h
731+
test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h test/redirect.h
732732
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcmdlineparser.cpp
733733

734734
test/testcolor.o: test/testcolor.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h

cli/cmdlineparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
282282
// TODO: error out on all missing given files/paths
283283
CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const argv[])
284284
{
285+
mSettings.exename = Path::getCurrentExecutablePath(argv[0]);
286+
285287
if (argc <= 1) {
286288
printHelp();
287289
return Result::Exit;
@@ -345,8 +347,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
345347

346348
ImportProject project;
347349

348-
mSettings.exename = Path::getCurrentExecutablePath(argv[0]);
349-
350350
for (int i = 1; i < argc; i++) {
351351
if (argv[i][0] == '-') {
352352
// User define

test/testcmdlineparser.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "cppcheckexecutor.h"
2323
#include "errortypes.h"
2424
#include "helpers.h"
25+
#include "path.h"
2526
#include "platform.h"
2627
#include "redirect.h"
2728
#include "settings.h"
@@ -417,7 +418,7 @@ class TestCmdlineParser : public TestFixture {
417418

418419
void versionWithCfg() {
419420
REDIRECT;
420-
ScopedFile file("cppcheck.cfg",
421+
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
421422
"{\n"
422423
"\"productName\": \"The Product\""
423424
"}\n");
@@ -440,7 +441,7 @@ class TestCmdlineParser : public TestFixture {
440441

441442
void versionWithInvalidCfg() {
442443
REDIRECT;
443-
ScopedFile file("cppcheck.cfg",
444+
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
444445
"{\n");
445446
const char * const argv[] = {"cppcheck", "--version"};
446447
ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv));
@@ -1711,7 +1712,7 @@ class TestCmdlineParser : public TestFixture {
17111712

17121713
void errorlistWithCfg() {
17131714
REDIRECT;
1714-
ScopedFile file("cppcheck.cfg",
1715+
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
17151716
R"({"productName": "The Product"}\n)");
17161717
const char * const argv[] = {"cppcheck", "--errorlist"};
17171718
ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv));
@@ -1730,7 +1731,7 @@ class TestCmdlineParser : public TestFixture {
17301731

17311732
void errorlistWithInvalidCfg() {
17321733
REDIRECT;
1733-
ScopedFile file("cppcheck.cfg",
1734+
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
17341735
"{\n");
17351736
const char * const argv[] = {"cppcheck", "--errorlist"};
17361737
ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv));
@@ -2345,7 +2346,7 @@ class TestCmdlineParser : public TestFixture {
23452346

23462347
void invalidCppcheckCfg() {
23472348
REDIRECT;
2348-
ScopedFile file("cppcheck.cfg",
2349+
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
23492350
"{\n");
23502351
const char * const argv[] = {"cppcheck", "test.cpp"};
23512352
ASSERT_EQUALS(CmdLineParser::Result::Fail, parser->parseFromArgs(2, argv));

0 commit comments

Comments
 (0)