Skip to content

Commit 5692009

Browse files
committed
testrunner: cleaned up some macros and related function signatures [skip ci]
1 parent 2c5b872 commit 5692009

File tree

7 files changed

+67
-69
lines changed

7 files changed

+67
-69
lines changed

test/testcondition.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,16 @@ class TestCondition : public TestFixture {
515515
errout_str());
516516
}
517517

518-
#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)
518+
#define checkPureFunction(...) checkPureFunction_(__FILE__, __LINE__, __VA_ARGS__)
519+
template<size_t size>
520+
void checkPureFunction_(const char* file, int line, const char (&code)[size]) {
521+
// Tokenize..
522+
SimpleTokenizer tokenizer(settings1, *this);
523+
ASSERT_LOC(tokenizer.tokenize(code), file, line);
524+
525+
runChecks<CheckCondition>(tokenizer, this);
526+
}
527+
519528
void multicompare() {
520529
check("void foo(int x)\n"
521530
"{\n"
@@ -574,15 +583,6 @@ class TestCondition : public TestFixture {
574583
ASSERT_EQUALS("", errout_str());
575584
}
576585

577-
template<size_t size>
578-
void checkPureFunction_(const char (&code)[size], const char* file, int line) {
579-
// Tokenize..
580-
SimpleTokenizer tokenizer(settings1, *this);
581-
ASSERT_LOC(tokenizer.tokenize(code), file, line);
582-
583-
runChecks<CheckCondition>(tokenizer, this);
584-
}
585-
586586
void overlappingElseIfCondition() {
587587
check("void f(int a, int &b) {\n"
588588
" if (a) { b = 1; }\n"

test/testerrorlogger.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ class TestErrorLogger : public TestFixture {
314314
}
315315
}
316316

317-
#define testReportType(reportType, severity, errorId, expectedClassification, expectedGuideline) \
318-
testReportType_(__FILE__, __LINE__, reportType, severity, errorId, expectedClassification, expectedGuideline)
317+
#define testReportType(...) testReportType_(__FILE__, __LINE__, __VA_ARGS__)
319318
void testReportType_(const char *file, int line, ReportType reportType, Severity severity, const std::string &errorId,
320319
const std::string &expectedClassification, const std::string &expectedGuideline) const
321320
{

test/testgarbage.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,6 @@ class TestGarbage : public TestFixture {
276276
}
277277

278278
#define checkCodeInternal(...) checkCodeInternal_(__FILE__, __LINE__, __VA_ARGS__)
279-
template<size_t size>
280-
std::string checkCode(const char (&code)[size], bool cpp = true) {
281-
// double the tests - run each example as C as well as C++
282-
283-
// run alternate check first. It should only ensure stability - so we catch exceptions here.
284-
try {
285-
(void)checkCodeInternal(code, !cpp);
286-
} catch (const InternalError&) {}
287-
288-
return checkCodeInternal(code, cpp);
289-
}
290-
291279
template<size_t size>
292280
std::string checkCodeInternal_(const char* file, int line, const char (&code)[size], bool cpp) {
293281
// tokenize..
@@ -302,6 +290,18 @@ class TestGarbage : public TestFixture {
302290
return tokenizer.tokens()->stringifyList(false, false, false, true, false, nullptr, nullptr);
303291
}
304292

293+
template<size_t size>
294+
std::string checkCode(const char (&code)[size], bool cpp = true) {
295+
// double the tests - run each example as C as well as C++
296+
297+
// run alternate check first. It should only ensure stability - so we catch exceptions here.
298+
try {
299+
(void)checkCodeInternal(code, !cpp);
300+
} catch (const InternalError&) {}
301+
302+
return checkCodeInternal(code, cpp);
303+
}
304+
305305
#define getSyntaxError(...) getSyntaxError_(__FILE__, __LINE__, __VA_ARGS__)
306306
template<size_t size>
307307
std::string getSyntaxError_(const char* file, int line, const char (&code)[size]) {

test/testlibrary.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,14 @@ class TestLibrary : public TestFixture {
10121012
}
10131013
}
10141014

1015-
#define LOADLIBERROR(xmldata, errorcode) loadLibError(xmldata, errorcode, __FILE__, __LINE__)
1015+
#define LOADLIBERROR(...) loadLibError(__FILE__, __LINE__, __VA_ARGS__)
1016+
template<std::size_t size>
1017+
void loadLibError(const char* file, unsigned line, const char (&xmldata)[size], Library::ErrorCode errorcode) const {
1018+
Library library;
1019+
Library::Error liberr;
1020+
assertEquals(file, line, true, LibraryHelper::loadxmldata(library, liberr, xmldata, size-1));
1021+
assertEquals(file, line, true, errorcode == liberr.errorcode);
1022+
}
10161023

10171024
void version() const {
10181025
{
@@ -1053,14 +1060,6 @@ class TestLibrary : public TestFixture {
10531060
}
10541061
}
10551062

1056-
template<std::size_t size>
1057-
void loadLibError(const char (&xmldata)[size], Library::ErrorCode errorcode, const char* file, unsigned line) const {
1058-
Library library;
1059-
Library::Error liberr;
1060-
assertEquals(file, line, true, LibraryHelper::loadxmldata(library, liberr, xmldata, size-1));
1061-
assertEquals(file, line, true, errorcode == liberr.errorcode);
1062-
}
1063-
10641063
#define LOADLIB_ERROR_INVALID_RANGE(valid) LOADLIBERROR("<?xml version=\"1.0\"?>\n" \
10651064
"<def>\n" \
10661065
"<function name=\"f\">\n" \

test/testnullpointer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4617,9 +4617,9 @@ class TestNullPointer : public TestFixture {
46174617
ASSERT_EQUALS("", errout_str());
46184618
}
46194619

4620-
#define ctu(code) ctu_(code, __FILE__, __LINE__)
4620+
#define ctu(...) ctu_(__FILE__, __LINE__, __VA_ARGS__)
46214621
template<size_t size>
4622-
void ctu_(const char (&code)[size], const char* file, int line) {
4622+
void ctu_(const char* file, int line, const char (&code)[size]) {
46234623
// Tokenize..
46244624
SimpleTokenizer tokenizer(settings, *this);
46254625
ASSERT_LOC(tokenizer.tokenize(code), file, line);

test/testuninitvar.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,6 +3591,17 @@ class TestUninitVar : public TestFixture {
35913591
}
35923592

35933593
#define valueFlowUninit(...) valueFlowUninit_(__FILE__, __LINE__, __VA_ARGS__)
3594+
template<size_t size>
3595+
void valueFlowUninit_(const char* file, int line, const char (&code)[size], bool cpp = true)
3596+
{
3597+
SimpleTokenizer tokenizer(settings, *this, cpp);
3598+
ASSERT_LOC(tokenizer.tokenize(code), file, line);
3599+
3600+
// Check for redundant code..
3601+
CheckUninitVar checkuninitvar(&tokenizer, &settings, this);
3602+
(checkuninitvar.valueFlowUninit)();
3603+
}
3604+
35943605
void valueFlowUninit2_value()
35953606
{
35963607
valueFlowUninit("void f() {\n"
@@ -5467,18 +5478,27 @@ class TestUninitVar : public TestFixture {
54675478
TODO_ASSERT_EQUALS("", "[test.c:4:14]: (error) Uninitialized variable: d [legacyUninitvar]\n", errout_str());
54685479
}
54695480

5481+
#define ctu(...) ctu_(__FILE__, __LINE__, __VA_ARGS__)
54705482
template<size_t size>
5471-
void valueFlowUninit_(const char* file, int line, const char (&code)[size], bool cpp = true)
5472-
{
5473-
SimpleTokenizer tokenizer(settings, *this, cpp);
5483+
void ctu_(const char* file, int line, const char (&code)[size]) {
5484+
// Tokenize..
5485+
SimpleTokenizer tokenizer(settings, *this);
54745486
ASSERT_LOC(tokenizer.tokenize(code), file, line);
54755487

5476-
// Check for redundant code..
5477-
CheckUninitVar checkuninitvar(&tokenizer, &settings, this);
5478-
(checkuninitvar.valueFlowUninit)();
5488+
CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);
5489+
5490+
// Check code..
5491+
std::list<Check::FileInfo*> fileInfo;
5492+
Check& c = getCheck<CheckUninitVar>();
5493+
fileInfo.push_back(c.getFileInfo(tokenizer, settings, ""));
5494+
c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result
5495+
while (!fileInfo.empty()) {
5496+
delete fileInfo.back();
5497+
fileInfo.pop_back();
5498+
}
5499+
delete ctu;
54795500
}
54805501

5481-
#define ctu(code) ctu_(__FILE__, __LINE__, code)
54825502
void valueFlowUninitTest() {
54835503
// #9735 - FN
54845504
valueFlowUninit("typedef struct\n"
@@ -7951,26 +7971,6 @@ class TestUninitVar : public TestFixture {
79517971
ASSERT_EQUALS("", errout_str());
79527972
}
79537973

7954-
template<size_t size>
7955-
void ctu_(const char* file, int line, const char (&code)[size]) {
7956-
// Tokenize..
7957-
SimpleTokenizer tokenizer(settings, *this);
7958-
ASSERT_LOC(tokenizer.tokenize(code), file, line);
7959-
7960-
CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);
7961-
7962-
// Check code..
7963-
std::list<Check::FileInfo*> fileInfo;
7964-
Check& c = getCheck<CheckUninitVar>();
7965-
fileInfo.push_back(c.getFileInfo(tokenizer, settings, ""));
7966-
c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result
7967-
while (!fileInfo.empty()) {
7968-
delete fileInfo.back();
7969-
fileInfo.pop_back();
7970-
}
7971-
delete ctu;
7972-
}
7973-
79747974
void ctuTest() {
79757975
ctu("void f(int *p) {\n"
79767976
" a = *p;\n"

test/testvalueflow.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ class TestValueFlow : public TestFixture {
297297
return false;
298298
}
299299

300-
#define testValueOfXInconclusive(code, linenr, value) testValueOfXInconclusive_(code, linenr, value, __FILE__, __LINE__)
301-
bool testValueOfXInconclusive_(const char code[], unsigned int linenr, int value, const char* file, int line) {
300+
#define testValueOfXInconclusive(...) testValueOfXInconclusive_(__FILE__, __LINE__, __VA_ARGS__)
301+
bool testValueOfXInconclusive_(const char* file, int line, const char code[], unsigned int linenr, int value) {
302302
// Tokenize..
303303
SimpleTokenizer tokenizer(settings, *this);
304304
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -374,8 +374,8 @@ class TestValueFlow : public TestFixture {
374374
return false;
375375
}
376376

377-
#define getErrorPathForX(code, linenr) getErrorPathForX_(code, linenr, __FILE__, __LINE__)
378-
std::string getErrorPathForX_(const char code[], unsigned int linenr, const char* file, int line) {
377+
#define getErrorPathForX(...) getErrorPathForX_(__FILE__, __LINE__, __VA_ARGS__)
378+
std::string getErrorPathForX_(const char* file, int line, const char code[], unsigned int linenr) {
379379
// Tokenize..
380380
SimpleTokenizer tokenizer(settings, *this);
381381
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -470,9 +470,9 @@ class TestValueFlow : public TestFixture {
470470
return false;
471471
}
472472

473-
#define testConditionalValueOfX(code, linenr, value) testConditionalValueOfX_(code, linenr, value, __FILE__, __LINE__)
473+
#define testConditionalValueOfX(...) testConditionalValueOfX_(__FILE__, __LINE__, __VA_ARGS__)
474474
template<size_t size>
475-
bool testConditionalValueOfX_(const char (&code)[size], unsigned int linenr, int value, const char* file, int line) {
475+
bool testConditionalValueOfX_(const char* file, int line, const char (&code)[size], unsigned int linenr, int value) {
476476
// Tokenize..
477477
SimpleTokenizer tokenizer(settings, *this);
478478
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -9115,7 +9115,7 @@ class TestValueFlow : public TestFixture {
91159115
ASSERT_EQUALS(1U, tokenValues(code, "v .", &s).size());
91169116
}
91179117

9118-
#define testBitfields(structBody, expectedSize) testBitfields_(__FILE__, __LINE__, structBody, expectedSize)
9118+
#define testBitfields(...) testBitfields_(__FILE__, __LINE__, __VA_ARGS__)
91199119
void testBitfields_(const char *file, int line, const std::string &structBody, std::size_t expectedSize) {
91209120
const Settings settingsUnix64 = settingsBuilder().platform(Platform::Type::Unix64).build();
91219121
const std::string code = "struct S { " + structBody + " }; const std::size_t size = sizeof(S);";

0 commit comments

Comments
 (0)