Skip to content

Commit 24714db

Browse files
authored
refs #14226 - CppCheckExecutor: removed need for test class friend declaration / cleaned up member access (danmar#8148)
1 parent c221f52 commit 24714db

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

cli/cppcheckexecutor.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ struct Suppressions;
3939
*/
4040
class CppCheckExecutor {
4141
public:
42-
friend class TestSuppressions;
43-
4442
/**
4543
* Constructor
4644
*/
@@ -61,17 +59,16 @@ class CppCheckExecutor {
6159
*/
6260
int check(int argc, const char* const argv[]);
6361

64-
private:
62+
protected:
6563

6664
/**
6765
* Execute a shell command and read the output from it. Returns exitcode of the executed command,.
6866
*/
6967
static int executeCommand(std::string exe, std::vector<std::string> args, std::string redirect, std::string &output_);
7068

71-
protected:
72-
7369
static bool reportUnmatchedSuppressions(const Settings &settings, const SuppressionList& suppressions, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);
7470

71+
private:
7572
/**
7673
* Wrapper around check_internal
7774
* - installs optional platform dependent signal handling

test/testsuppressions.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class TestSuppressions : public TestFixture {
4646

4747
private:
4848

49+
class CppCheckExecutorTest final : public CppCheckExecutor
50+
{
51+
friend class TestSuppressions;
52+
};
53+
4954
const std::string templateFormat{"{callstack}: ({severity}) {inconclusive:inconclusive: }{message}"};
5055

5156
void run() override {
@@ -289,7 +294,7 @@ class TestSuppressions : public TestFixture {
289294
SingleExecutor executor(cppCheck, filelist, fileSettings, settings, supprs, *this, nullptr);
290295
unsigned int exitCode = executor.check();
291296

292-
const bool err = CppCheckExecutor::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this);
297+
const bool err = CppCheckExecutorTest::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this);
293298
if (err && exitCode == 0)
294299
exitCode = 1;
295300

@@ -335,10 +340,10 @@ class TestSuppressions : public TestFixture {
335340
if (useFS)
336341
filelist.clear();
337342

338-
ThreadExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutor::executeCommand);
343+
ThreadExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutorTest::executeCommand);
339344
unsigned int exitCode = executor.check();
340345

341-
const bool err = CppCheckExecutor::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this);
346+
const bool err = CppCheckExecutorTest::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this);
342347
if (err && exitCode == 0)
343348
exitCode = 1;
344349

@@ -385,10 +390,10 @@ class TestSuppressions : public TestFixture {
385390
if (useFS)
386391
filelist.clear();
387392

388-
ProcessExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutor::executeCommand);
393+
ProcessExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutorTest::executeCommand);
389394
unsigned int exitCode = executor.check();
390395

391-
const bool err = CppCheckExecutor::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this);
396+
const bool err = CppCheckExecutorTest::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this);
392397
if (err && exitCode == 0)
393398
exitCode = 1;
394399

@@ -1534,7 +1539,7 @@ class TestSuppressions : public TestFixture {
15341539
// No unmatched suppression
15351540
{
15361541
SuppressionList suppressions;
1537-
ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
1542+
ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
15381543
ASSERT_EQUALS("", errout_str());
15391544
}
15401545

@@ -1543,7 +1548,7 @@ class TestSuppressions : public TestFixture {
15431548
SuppressionList suppressions;
15441549
addCheckedSuppression(suppressions, {"abc", "a.c", 10U});
15451550
addCheckedSuppression(suppressions, {"unmatchedSuppression", "*", SuppressionList::Suppression::NO_LINE});
1546-
ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
1551+
ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
15471552
ASSERT_EQUALS("", errout_str());
15481553
}
15491554

@@ -1552,7 +1557,7 @@ class TestSuppressions : public TestFixture {
15521557
SuppressionList suppressions;
15531558
addCheckedSuppression(suppressions, {"abc", "a.c", 10U});
15541559
addCheckedSuppression(suppressions, {"unmatchedSuppression", "", SuppressionList::Suppression::NO_LINE});
1555-
ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
1560+
ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
15561561
ASSERT_EQUALS("", errout_str());
15571562
}
15581563

@@ -1561,7 +1566,7 @@ class TestSuppressions : public TestFixture {
15611566
SuppressionList suppressions;
15621567
addCheckedSuppression(suppressions, {"abc", "a.c", 10U});
15631568
addCheckedSuppression(suppressions, {"unmatchedSuppression", "a.c", SuppressionList::Suppression::NO_LINE});
1564-
ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
1569+
ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
15651570
ASSERT_EQUALS("", errout_str());
15661571
}
15671572

@@ -1570,7 +1575,7 @@ class TestSuppressions : public TestFixture {
15701575
SuppressionList suppressions;
15711576
addCheckedSuppression(suppressions, {"abc", "a.c", 10U});
15721577
addCheckedSuppression(suppressions, {"unmatchedSuppression", "a.c", 10U});
1573-
ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
1578+
ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
15741579
ASSERT_EQUALS("", errout_str());
15751580
}
15761581

@@ -1579,7 +1584,7 @@ class TestSuppressions : public TestFixture {
15791584
SuppressionList suppressions;
15801585
addCheckedSuppression(suppressions, {"abc", "a.c", 10U});
15811586
addCheckedSuppression(suppressions, {"unmatchedSuppression", "b.c", SuppressionList::Suppression::NO_LINE});
1582-
ASSERT_EQUALS(true, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
1587+
ASSERT_EQUALS(true, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
15831588
ASSERT_EQUALS("[a.c:10:0]: (information) Unmatched suppression: abc [unmatchedSuppression]\n", errout_str());
15841589
}
15851590

@@ -1588,7 +1593,7 @@ class TestSuppressions : public TestFixture {
15881593
SuppressionList suppressions;
15891594
addCheckedSuppression(suppressions, {"abc", "a.c", 10U});
15901595
addCheckedSuppression(suppressions, {"unmatchedSuppression", "a.c", 1U});
1591-
ASSERT_EQUALS(true, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
1596+
ASSERT_EQUALS(true, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this));
15921597
ASSERT_EQUALS("[a.c:10:0]: (information) Unmatched suppression: abc [unmatchedSuppression]\n", errout_str());
15931598
}
15941599
}

0 commit comments

Comments
 (0)