Skip to content

Commit e9acdd4

Browse files
committed
read cppcheck.cfg before the CLI options
1 parent b22c658 commit e9acdd4

File tree

3 files changed

+5
-25
lines changed

3 files changed

+5
-25
lines changed

cli/cmdlineparser.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
321321
// default to --check-level=normal from CLI for now
322322
mSettings.setCheckLevel(Settings::CheckLevel::normal);
323323

324-
// TODO: this is duplicated in gui/mainwindows.cpp
325-
{
326-
// only read cppcheck.cfg if the product name has not been set yet
327-
// this is hack so we can unit test this - should never happen in production
328-
if (mSettings.cppcheckCfgProductName.empty())
329-
{
330-
// load config to determine if we are premium - do not apply any other settings
331-
Settings s;
332-
s.exename = mSettings.exename;
333-
Suppressions supprs;
334-
// TODO: errorhandling
335-
Settings::loadCppcheckCfg(s, supprs, mSettings.debuglookup || mSettings.debuglookupConfig);
336-
mSettings.cppcheckCfgProductName = s.cppcheckCfgProductName;
337-
}
338-
mSettings.premium = startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
339-
}
324+
if (!loadCppcheckCfg())
325+
return Result::Fail;
326+
327+
mSettings.premium = startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
340328

341329
if (argc <= 1) {
342330
printHelp(mSettings.premium);
@@ -363,8 +351,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
363351

364352
// print all possible error messages..
365353
if (std::strcmp(argv[i], "--errorlist") == 0) {
366-
if (!loadCppcheckCfg())
367-
return Result::Fail;
368354
{
369355
XMLErrorMessagesLogger xmlLogger;
370356
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName, 2);
@@ -388,8 +374,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
388374
}
389375

390376
if (std::strcmp(argv[i], "--version") == 0) {
391-
if (!loadCppcheckCfg())
392-
return Result::Fail;
393377
const std::string version = getVersion();
394378
mLogger.printRaw(version); // TODO: should not include newline
395379
return Result::Exit;
@@ -1563,9 +1547,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
15631547
}
15641548
}
15651549

1566-
if (!loadCppcheckCfg())
1567-
return Result::Fail;
1568-
15691550
// TODO: bail out?
15701551
if (!executorAuto && mSettings.useSingleJob())
15711552
mLogger.printMessage("'--executor' has no effect as only a single job will be used.");

gui/mainwindow.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
131131
mSelectLanguageActions(new QActionGroup(this)),
132132
mSelectReportActions(new QActionGroup(this))
133133
{
134-
// TODO: this is duplicated in cli/cmdlineparser.cpp
135134
{
136135
Settings tempSettings;
137136
tempSettings.exename = QCoreApplication::applicationFilePath().toStdString();

test/cli/other_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ def test_config_override(tmpdir):
17441744
exitcode, stdout, stderr, exe = cppcheck_ex(['-q', '--safety', test_file], cwd=tmpdir, cppcheck_exe=exe, remove_checkers_report=False)
17451745
assert exitcode == 0, stdout if stdout else stderr
17461746
assert stdout.splitlines() == []
1747-
assert stderr.splitlines() == []
1747+
assert 'checkersReport' in stderr
17481748

17491749

17501750
def test_checkers_report(tmpdir):

0 commit comments

Comments
 (0)