Skip to content

Commit 6697db1

Browse files
committed
testrunner: more options/settings usage cleanups [skip ci]
1 parent 8d0ad65 commit 6697db1

File tree

11 files changed

+264
-231
lines changed

11 files changed

+264
-231
lines changed

test/testbufferoverrun.cpp

Lines changed: 55 additions & 54 deletions
Large diffs are not rendered by default.

test/testclass.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TestClass : public TestFixture {
3535

3636
private:
3737
const Settings settings0 = settingsBuilder().severity(Severity::style).library("std.cfg").build();
38+
const Settings settings0_i = settingsBuilder(settings0).certainty(Certainty::inconclusive).build();
3839
const Settings settings1 = settingsBuilder().severity(Severity::warning).library("std.cfg").build();
3940
const Settings settings2 = settingsBuilder().severity(Severity::style).library("std.cfg").certainty(Certainty::inconclusive).build();
4041
const Settings settings3 = settingsBuilder().severity(Severity::style).library("std.cfg").severity(Severity::warning).build();
@@ -3655,23 +3656,26 @@ class TestClass : public TestFixture {
36553656

36563657
struct CheckConstOptions
36573658
{
3658-
const Settings *s = nullptr;
36593659
bool inconclusive = true;
36603660
};
36613661

36623662
#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)
36633663
template<size_t size>
36643664
void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {
3665-
const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();
3665+
const Settings& settings = options.inconclusive ? settings0_i : settings0;
36663666

3667-
// Tokenize..
3668-
SimpleTokenizer tokenizer(settings, *this);
3669-
ASSERT_LOC(tokenizer.tokenize(code), file, line);
3670-
3671-
CheckClass checkClass(&tokenizer, &settings, this);
3672-
(checkClass.checkConst)();
3667+
checkConst_(file, line, code, settings);
36733668
}
36743669

3670+
template<size_t size>
3671+
void checkConst_(const char* file, int line, const char (&code)[size], const Settings& settings) {
3672+
SimpleTokenizer tokenizer(settings, *this);
3673+
ASSERT_LOC(tokenizer.tokenize(code), file, line);
3674+
3675+
CheckClass checkClass(&tokenizer, &settings, this);
3676+
(checkClass.checkConst)();
3677+
}
3678+
36753679
void const1() {
36763680
checkConst("class Fred {\n"
36773681
" int a;\n"
@@ -7747,15 +7751,15 @@ class TestClass : public TestFixture {
77477751
}
77487752

77497753
void qualifiedNameMember() { // #10872
7750-
const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library("std.cfg").build();
7754+
const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library("std.cfg").certainty(Certainty::inconclusive).build();
77517755
checkConst("struct data {};\n"
77527756
" struct S {\n"
77537757
" std::vector<data> std;\n"
77547758
" void f();\n"
77557759
"};\n"
77567760
"void S::f() {\n"
77577761
" std::vector<data>::const_iterator end = std.end();\n"
7758-
"}\n", dinit(CheckConstOptions, $.s = &s));
7762+
"}\n", s);
77597763
ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n", errout_str());
77607764
}
77617765

test/testcondition.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,18 @@ class TestCondition : public TestFixture {
130130

131131
struct CheckOptions
132132
{
133-
const Settings* s = nullptr;
134133
bool cpp = true;
135134
};
136135

137136
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
138137
template<size_t size>
139138
void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {
140-
const Settings& settings = options.s ? *options.s : settings0;
139+
check_(file, line, code, settings0, options.cpp);
140+
}
141141

142-
SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? "test.cpp" : "test.c");
142+
template<size_t size>
143+
void check_(const char* file, int line, const char (&code)[size], const Settings& settings, bool cpp = true) {
144+
SimpleTokenizer2 tokenizer(settings, *this, code, cpp ? "test.cpp" : "test.c");
143145

144146
// Tokenizer..
145147
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
@@ -1309,27 +1311,27 @@ class TestCondition : public TestFixture {
13091311
const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive).build();
13101312
check("void f(char x) {\n"
13111313
" if (x == '1' || x == '2') {}\n"
1312-
"}", dinit(CheckOptions, $.s = &s));
1314+
"}", s);
13131315
ASSERT_EQUALS("", errout_str());
13141316

13151317
check("void f(char x) {\n"
13161318
" if (x == '1' && x == '2') {}\n"
1317-
"}", dinit(CheckOptions, $.s = &s));
1319+
"}", s);
13181320
ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\n", errout_str());
13191321

13201322
check("int f(char c) {\n"
13211323
" return (c >= 'a' && c <= 'z');\n"
1322-
"}", dinit(CheckOptions, $.s = &s));
1324+
"}", s);
13231325
ASSERT_EQUALS("", errout_str());
13241326

13251327
check("int f(char c) {\n"
13261328
" return (c <= 'a' && c >= 'z');\n"
1327-
"}", dinit(CheckOptions, $.s = &s));
1329+
"}", s);
13281330
ASSERT_EQUALS("[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\n", errout_str());
13291331

13301332
check("int f(char c) {\n"
13311333
" return (c <= 'a' && c >= 'z');\n"
1332-
"}");
1334+
"}"); // TODO: use s?
13331335
ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\n", errout_str());
13341336
}
13351337

@@ -6142,65 +6144,65 @@ class TestCondition : public TestFixture {
61426144

61436145
check("void f(unsigned char c) {\n"
61446146
" if (c == 256) {}\n"
6145-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6147+
"}", settingsUnix64);
61466148
ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str());
61476149

61486150
check("void f(unsigned char* b, int i) {\n" // #6372
61496151
" if (b[i] == 256) {}\n"
6150-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6152+
"}", settingsUnix64);
61516153
ASSERT_EQUALS("[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str());
61526154

61536155
check("void f(unsigned char c) {\n"
61546156
" if (c == 255) {}\n"
6155-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6157+
"}", settingsUnix64);
61566158
ASSERT_EQUALS("", errout_str());
61576159

61586160
check("void f(bool b) {\n"
61596161
" if (b == true) {}\n"
6160-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6162+
"}", settingsUnix64);
61616163
ASSERT_EQUALS("", errout_str());
61626164

61636165
// #10372
61646166
check("void f(signed char x) {\n"
61656167
" if (x == 0xff) {}\n"
6166-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6168+
"}", settingsUnix64);
61676169
ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str());
61686170

61696171
check("void f(short x) {\n"
61706172
" if (x == 0xffff) {}\n"
6171-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6173+
"}", settingsUnix64);
61726174
ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str());
61736175

61746176
check("void f(int x) {\n"
61756177
" if (x == 0xffffffff) {}\n"
6176-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6178+
"}", settingsUnix64);
61776179
ASSERT_EQUALS("", errout_str());
61786180

61796181
check("void f(long x) {\n"
61806182
" if (x == ~0L) {}\n"
6181-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6183+
"}", settingsUnix64);
61826184
ASSERT_EQUALS("", errout_str());
61836185

61846186
check("void f(long long x) {\n"
61856187
" if (x == ~0LL) {}\n"
6186-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6188+
"}", settingsUnix64);
61876189
ASSERT_EQUALS("", errout_str());
61886190

61896191
check("int f(int x) {\n"
61906192
" const int i = 0xFFFFFFFF;\n"
61916193
" if (x == i) {}\n"
6192-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6194+
"}", settingsUnix64);
61936195
ASSERT_EQUALS("", errout_str());
61946196

61956197
check("void f() {\n"
61966198
" char c;\n"
61976199
" if ((c = foo()) != -1) {}\n"
6198-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6200+
"}", settingsUnix64);
61996201
ASSERT_EQUALS("", errout_str());
62006202

62016203
check("void f(int x) {\n"
62026204
" if (x < 3000000000) {}\n"
6203-
"}", dinit(CheckOptions, $.s = &settingsUnix64));
6205+
"}", settingsUnix64);
62046206
ASSERT_EQUALS("[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\n", errout_str());
62056207

62066208
check("void f(const signed char i) {\n" // #8545
@@ -6210,7 +6212,7 @@ class TestCondition : public TestFixture {
62106212
" if (i < +128) {}\n" // warn
62116213
" if (i <= +127) {}\n" // warn
62126214
" if (i <= +126) {}\n"
6213-
"}\n", dinit(CheckOptions, $.s = &settingsUnix64));
6215+
"}\n", settingsUnix64);
62146216
ASSERT_EQUALS("[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\n"
62156217
"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\n"
62166218
"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\n"
@@ -6234,7 +6236,7 @@ class TestCondition : public TestFixture {
62346236
" if (255 > u) {}\n"
62356237
" if (255 <= u) {}\n"
62366238
" if (255 >= u) {}\n" // warn
6237-
"}\n", dinit(CheckOptions, $.s = &settingsUnix64));
6239+
"}\n", settingsUnix64);
62386240
ASSERT_EQUALS("[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\n"
62396241
"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\n"
62406242
"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n"
@@ -6247,7 +6249,7 @@ class TestCondition : public TestFixture {
62476249

62486250
check("void f(bool b) {\n" // #14037
62496251
" if (b != 2) {}\n"
6250-
"}\n", dinit(CheckOptions, $.s = &settingsUnix64));
6252+
"}\n", settingsUnix64);
62516253
ASSERT_EQUALS("[test.cpp:2:14]: (style) Comparing expression of type 'bool' against value 2. Condition is always true. [compareValueOutOfTypeRangeError]\n",
62526254
errout_str());
62536255
}

test/testconstructors.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,23 @@ class TestConstructors : public TestFixture {
3131

3232
private:
3333
const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
34+
const Settings settings_i = settingsBuilder(settings).certainty(Certainty::inconclusive).build();
3435

3536
struct CheckOptions
3637
{
3738
bool inconclusive = false;
38-
const Settings* s = nullptr;
3939
};
4040

4141
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
4242
template<size_t size>
4343
void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {
44-
const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).certainty(Certainty::inconclusive, options.inconclusive).build();
44+
const Settings settings1 = options.inconclusive ? settings_i : settings;
4545

46-
// Tokenize..
46+
check_(file, line, code, settings1);
47+
}
48+
49+
template<size_t size>
50+
void check_(const char* file, int line, const char (&code)[size], const Settings& settings1) {
4751
SimpleTokenizer tokenizer(settings1, *this);
4852
ASSERT_LOC(tokenizer.tokenize(code), file, line);
4953

@@ -1593,7 +1597,7 @@ class TestConstructors : public TestFixture {
15931597
" Fred();\n"
15941598
"};\n"
15951599
"Fred::Fred()\n"
1596-
"{ }", dinit(CheckOptions, $.s = &s));
1600+
"{ }", s);
15971601
ASSERT_EQUALS("[test.cpp:7:7]: (warning) Member variable 'Fred::var' is not initialized in the constructor. [uninitMemberVarPrivate]\n", errout_str());
15981602
}
15991603

@@ -1606,7 +1610,7 @@ class TestConstructors : public TestFixture {
16061610
" Fred();\n"
16071611
"};\n"
16081612
"Fred::Fred()\n"
1609-
"{ }", dinit(CheckOptions, $.s = &s));
1613+
"{ }", s);
16101614
ASSERT_EQUALS("", errout_str());
16111615
}
16121616
}
@@ -2064,7 +2068,7 @@ class TestConstructors : public TestFixture {
20642068
" d = rhs.get();\n"
20652069
" }\n"
20662070
" double d;\n"
2067-
"};", dinit(CheckOptions, $.s = &s));
2071+
"};", s);
20682072
ASSERT_EQUALS("", errout_str());
20692073

20702074
check("struct S {\n" // #8485
@@ -2098,7 +2102,7 @@ class TestConstructors : public TestFixture {
20982102
check("struct S {\n"
20992103
" S& operator=(const S& s) { return *this; }\n"
21002104
" std::mutex m;\n"
2101-
"};\n", dinit(CheckOptions, $.s = &s));
2105+
"};\n", s);
21022106
ASSERT_EQUALS("", errout_str());
21032107
}
21042108

@@ -3046,7 +3050,7 @@ class TestConstructors : public TestFixture {
30463050
check("struct C {\n" // #13989
30473051
" C() = default;\n"
30483052
" std::list<int>::const_iterator it;\n"
3049-
"};\n", dinit(CheckOptions, $.s = &s));
3053+
"};\n", s);
30503054
ASSERT_EQUALS("[test.cpp:2:5]: (warning) Member variable 'C::it' is not initialized in the constructor. [uninitMemberVar]\n", errout_str());
30513055
}
30523056

@@ -3257,7 +3261,7 @@ class TestConstructors : public TestFixture {
32573261
" std::array<std::string, 2> e;\n"
32583262
" std::array<U, 2> f;\n"
32593263
"S() {}\n"
3260-
"};\n", dinit(CheckOptions, $.s = &s));
3264+
"};\n", s);
32613265

32623266
ASSERT_EQUALS("[test.cpp:10:1]: (warning) Member variable 'S::a' is not initialized in the constructor. [uninitMemberVar]\n"
32633267
"[test.cpp:10:1]: (warning) Member variable 'S::b' is not initialized in the constructor. [uninitMemberVar]\n"
@@ -3689,7 +3693,7 @@ class TestConstructors : public TestFixture {
36893693
check("class Foo {\n"
36903694
" int foo;\n"
36913695
" Foo() { }\n"
3692-
"};", dinit(CheckOptions, $.s = &s));
3696+
"};", s);
36933697
ASSERT_EQUALS("", errout_str());
36943698
}
36953699

@@ -3698,7 +3702,7 @@ class TestConstructors : public TestFixture {
36983702
check("class Foo {\n"
36993703
" int foo;\n"
37003704
" Foo() { }\n"
3701-
"};", dinit(CheckOptions, $.s = &s));
3705+
"};", s);
37023706
ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Foo::foo' is not initialized in the constructor. [uninitMemberVarPrivate]\n", errout_str());
37033707
}
37043708
}
@@ -3760,7 +3764,7 @@ class TestConstructors : public TestFixture {
37603764
" Fred() { }\n"
37613765
"private:\n"
37623766
" int x;\n"
3763-
"};", dinit(CheckOptions, $.s = &s));
3767+
"};", s);
37643768
ASSERT_EQUALS("", errout_str());
37653769
}
37663770

0 commit comments

Comments
 (0)