Skip to content

Commit 5e137d8

Browse files
committed
testrunner: do not use global check instances
1 parent f7f0549 commit 5e137d8

20 files changed

Lines changed: 87 additions & 100 deletions

test/fixture.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#define fixtureH
2222

2323
#include "check.h"
24-
#include "checks.h"
2524
#include "color.h"
2625
#include "config.h"
2726
#include "errorlogger.h"
@@ -33,7 +32,6 @@
3332
#include <cstddef>
3433
#include <cstdint>
3534
#include <exception>
36-
#include <list>
3735
#include <memory>
3836
#include <set>
3937
#include <sstream>
@@ -136,21 +134,13 @@ class TestFixture : public ErrorLogger {
136134

137135
void processOptions(const options& args);
138136

139-
template<typename T>
140-
static T& getCheck()
137+
static Check& getCheck(Check& check)
141138
{
142-
for (Check *check : CheckInstances::get()) {
143-
//cppcheck-suppress useStlAlgorithm
144-
if (T* c = dynamic_cast<T*>(check))
145-
return *c;
146-
}
147-
throw std::runtime_error("instance not found");
139+
return check;
148140
}
149141

150-
template<typename T>
151-
static void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
142+
static void runChecks(Check& check, const Tokenizer &tokenizer, ErrorLogger *errorLogger)
152143
{
153-
Check& check = getCheck<T>();
154144
check.runChecks(tokenizer, errorLogger);
155145
}
156146

test/testassert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class TestAssert : public TestFixture {
3939
SimpleTokenizer tokenizer(settings, *this);
4040
ASSERT_LOC(tokenizer.tokenize(code), file, line);
4141

42-
// Check..
43-
runChecks<CheckAssert>(tokenizer, this);
42+
CheckAssert check;
43+
runChecks(check, tokenizer, this);
4444
}
4545

4646
void run() override {

test/testautovariables.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class TestAutoVariables : public TestFixture {
4747
SimpleTokenizer tokenizer(settings1, *this, options.cpp);
4848
ASSERT_LOC(tokenizer.tokenize(code), file, line);
4949

50-
runChecks<CheckAutoVariables>(tokenizer, this);
50+
CheckAutoVariables check;
51+
runChecks(check, tokenizer, this);
5152
}
5253

5354
void run() override {

test/testbool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class TestBool : public TestFixture {
8888
SimpleTokenizer tokenizer(settings, *this, options.cpp);
8989
ASSERT_LOC(tokenizer.tokenize(code), file, line);
9090

91-
// Check...
92-
runChecks<CheckBool>(tokenizer, this);
91+
CheckBool check;
92+
runChecks(check, tokenizer, this);
9393
}
9494

9595

test/testbufferoverrun.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class TestBufferOverrun : public TestFixture {
5656
SimpleTokenizer tokenizer(settings, *this, cpp);
5757
ASSERT_LOC(tokenizer.tokenize(code), file, line);
5858

59-
// Check for buffer overruns..
60-
runChecks<CheckBufferOverrun>(tokenizer, this);
59+
CheckBufferOverrun check;
60+
runChecks(check, tokenizer, this);
6161
}
6262

6363
// TODO: get rid of this
@@ -66,8 +66,8 @@ class TestBufferOverrun : public TestFixture {
6666
SimpleTokenizer tokenizer(settings0_i, *this);
6767
ASSERT_LOC(tokenizer.tokenize(code), file, line);
6868

69-
// Check for buffer overruns..
70-
runChecks<CheckBufferOverrun>(tokenizer, this);
69+
CheckBufferOverrun check;
70+
runChecks(check, tokenizer, this);
7171
}
7272

7373
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
@@ -79,8 +79,8 @@ class TestBufferOverrun : public TestFixture {
7979
// Tokenizer..
8080
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
8181

82-
// Check for buffer overruns..
83-
runChecks<CheckBufferOverrun>(tokenizer, this);
82+
CheckBufferOverrun check;
83+
runChecks(check, tokenizer, this);
8484
}
8585

8686
void run() override {
@@ -5169,7 +5169,8 @@ class TestBufferOverrun : public TestFixture {
51695169

51705170
void getErrorMessages() {
51715171
// Ticket #2292: segmentation fault when using --errorlist
5172-
const Check& c = getCheck<CheckBufferOverrun>();
5172+
CheckBufferOverrun check;
5173+
const Check& c = getCheck(check);
51735174
c.getErrorMessages(this, nullptr);
51745175
// we are not interested in the output - just consume it
51755176
ignore_errout();
@@ -5362,9 +5363,9 @@ class TestBufferOverrun : public TestFixture {
53625363

53635364
CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);
53645365

5365-
// Check code..
53665366
std::list<Check::FileInfo*> fileInfo;
5367-
Check& c = getCheck<CheckBufferOverrun>();
5367+
CheckBufferOverrun check;
5368+
Check& c = getCheck(check);
53685369
fileInfo.push_back(c.getFileInfo(tokenizer, settings0, ""));
53695370
c.analyseWholeProgram(*ctu, fileInfo, settings0, *this); // TODO: check result
53705371
while (!fileInfo.empty()) {

test/testclass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9278,7 +9278,8 @@ class TestClass : public TestFixture {
92789278

92799279

92809280
void ctu(const std::vector<std::string> &code) {
9281-
Check &check = getCheck<CheckClass>();
9281+
CheckClass checkClass;
9282+
Check &check = getCheck(checkClass);
92829283

92839284
// getFileInfo
92849285
std::list<Check::FileInfo*> fileInfo;
@@ -9330,8 +9331,8 @@ class TestClass : public TestFixture {
93309331
SimpleTokenizer tokenizer(settings1, *this);
93319332
ASSERT_LOC(tokenizer.tokenize(code), file, line);
93329333

9333-
// Check..
9334-
const Check& c = getCheck<CheckClass>();
9334+
CheckClass check;
9335+
const Check& c = getCheck(check);
93359336
Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, "");
93369337

93379338
delete fileInfo;

test/testcondition.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class TestCondition : public TestFixture {
149149
// Tokenizer..
150150
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
151151

152-
// Run checks..
153-
runChecks<CheckCondition>(tokenizer, this);
152+
CheckCondition check;
153+
runChecks(check, tokenizer, this);
154154
}
155155

156156
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
@@ -162,8 +162,8 @@ class TestCondition : public TestFixture {
162162
// Tokenizer..
163163
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
164164

165-
// Run checks..
166-
runChecks<CheckCondition>(tokenizer, this);
165+
CheckCondition check;
166+
runChecks(check, tokenizer, this);
167167
}
168168

169169
void assignAndCompare() {
@@ -527,7 +527,8 @@ class TestCondition : public TestFixture {
527527
SimpleTokenizer tokenizer(settings1, *this);
528528
ASSERT_LOC(tokenizer.tokenize(code), file, line);
529529

530-
runChecks<CheckCondition>(tokenizer, this);
530+
CheckCondition check;
531+
runChecks(check, tokenizer, this);
531532
}
532533

533534
void multicompare() {

test/testexceptionsafety.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class TestExceptionSafety : public TestFixture {
7575
SimpleTokenizer tokenizer(settings1, *this);
7676
ASSERT_LOC(tokenizer.tokenize(code), file, line);
7777

78-
// Check char variable usage..
79-
runChecks<CheckExceptionSafety>(tokenizer, this);
78+
CheckExceptionSafety check;
79+
runChecks(check, tokenizer, this);
8080
}
8181

8282
void destructors() {

test/testfunctions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ class TestFunctions : public TestFixture {
132132
SimpleTokenizer tokenizer(s, *this, cpp);
133133
ASSERT_LOC(tokenizer.tokenize(code), file, line);
134134

135-
runChecks<CheckFunctions>(tokenizer, this);
135+
CheckFunctions check;
136+
runChecks(check, tokenizer, this);
136137
}
137138

138139
void prohibitedFunctions_posix() {

test/testinternal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class TestInternal : public TestFixture {
5656
SimpleTokenizer tokenizer(settings, *this);
5757
ASSERT_LOC(tokenizer.tokenize(code), file, line);
5858

59-
// Check..
60-
runChecks<CheckInternal>(tokenizer, this);
59+
CheckInternal check;
60+
runChecks(check, tokenizer, this);
6161
}
6262

6363
void simplePatternInTokenMatch() {

0 commit comments

Comments
 (0)