Skip to content

Commit 5398426

Browse files
authored
testrunner: cleaned up some test options (#7426)
1 parent 8f81e60 commit 5398426

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

test/testbufferoverrun.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class TestBufferOverrun : public TestFixture {
7272
}
7373

7474
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
75-
void checkP_(const char* file, int line, const char code[], const char* filename = "test.cpp")
75+
void checkP_(const char* file, int line, const char code[])
7676
{
7777
const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();
7878

79-
std::vector<std::string> files(1, filename);
79+
std::vector<std::string> files(1, "test.cpp");
8080
Tokenizer tokenizer(settings, *this);
8181
PreprocessorHelper::preprocess(code, files, tokenizer, *this);
8282

test/testcondition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ class TestCondition : public TestFixture {
132132
{
133133
CheckOptions() = default;
134134
const Settings* s = nullptr;
135-
const char* filename = "test.cpp";
135+
bool cpp = true;
136136
bool inconclusive = false;
137137
};
138138

139139
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
140140
void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {
141141
const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();
142142
Tokenizer tokenizer(settings, *this);
143-
std::vector<std::string> files(1, options.filename);
143+
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
144144
PreprocessorHelper::preprocess(code, files, tokenizer, *this);
145145

146146
// Tokenizer..
@@ -3162,7 +3162,7 @@ class TestCondition : public TestFixture {
31623162
check("void f() { A<x &> a; }");
31633163
ASSERT_EQUALS("", errout_str());
31643164

3165-
check("void f() { a(x<y|z,0); }", dinit(CheckOptions, $.filename = "test.c")); // filename is c => there are never templates
3165+
check("void f() { a(x<y|z,0); }", dinit(CheckOptions, $.cpp = false)); // language is c => there are never templates
31663166
ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout_str());
31673167

31683168
check("class A<B&,C>;");

test/testother.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,15 @@ class TestOther : public TestFixture {
336336
check_(file, line, code, true, true, true, false, s);
337337
}
338338

339+
struct CheckPOptions
340+
{
341+
CheckPOptions() = default;
342+
bool cpp = true;
343+
};
344+
339345
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
340346
template<size_t size>
341-
void checkP_(const char* file, int line, const char (&code)[size], const char *filename = "test.cpp") {
347+
void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {
342348
Settings* settings = &_settings;
343349
settings->severity.enable(Severity::style);
344350
settings->severity.enable(Severity::warning);
@@ -348,7 +354,7 @@ class TestOther : public TestFixture {
348354
settings->standards.cpp = Standards::CPPLatest;
349355
settings->certainty.enable(Certainty::inconclusive);
350356

351-
std::vector<std::string> files(1, filename);
357+
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
352358
Tokenizer tokenizer(*settings, *this);
353359
PreprocessorHelper::preprocess(code, files, tokenizer, *this);
354360

@@ -5601,7 +5607,7 @@ class TestOther : public TestFixture {
56015607
" }\n"
56025608
" OUTB(index, port_0);\n"
56035609
" return INB(port_1);\n"
5604-
"}\n", "test.c");
5610+
"}\n", dinit(CheckPOptions, $.cpp = false));
56055611
ASSERT_EQUALS("", errout_str());
56065612

56075613
check("[[noreturn]] void n();\n"
@@ -11672,7 +11678,7 @@ class TestOther : public TestFixture {
1167211678
checkP("#define X x\n"
1167311679
"void f(int x) {\n"
1167411680
" return x + X++;\n"
11675-
"}", "test.c");
11681+
"}", dinit(CheckPOptions, $.cpp = false));
1167611682
ASSERT_EQUALS("[test.c:3]: (error) Expression 'x+x++' depends on order of evaluation of side effects\n", errout_str());
1167711683
}
1167811684

test/teststring.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ class TestString : public TestFixture {
6464
struct CheckOptions
6565
{
6666
CheckOptions() = default;
67-
const char* filename = "test.cpp";
67+
bool cpp = true;
6868
};
6969

7070
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
7171
void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {
72-
std::vector<std::string> files(1, options.filename);
72+
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
7373
Tokenizer tokenizer(settings, *this);
7474
PreprocessorHelper::preprocess(code, files, tokenizer, *this);
7575

@@ -337,7 +337,7 @@ class TestString : public TestFixture {
337337

338338
check("bool foo(char* c) {\n"
339339
" return \"x\" == c+foo;\n"
340-
"}", dinit(CheckOptions, $.filename = "test.c"));
340+
"}", dinit(CheckOptions, $.cpp = false));
341341
ASSERT_EQUALS("[test.c:2]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead?\n", errout_str());
342342

343343
check("bool foo(Foo c) {\n"
@@ -347,7 +347,7 @@ class TestString : public TestFixture {
347347

348348
check("bool foo(Foo c) {\n"
349349
" return \"x\" == c.foo;\n"
350-
"}", dinit(CheckOptions, $.filename = "test.c"));
350+
"}", dinit(CheckOptions, $.cpp = false));
351351
ASSERT_EQUALS("[test.c:2]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead?\n", errout_str());
352352

353353
check("bool foo(const std::string& c) {\n"
@@ -363,7 +363,7 @@ class TestString : public TestFixture {
363363
// Ticket #4257
364364
check("bool foo() {\n"
365365
"MyString *str=Getter();\n"
366-
"return *str==\"bug\"; }\n", dinit(CheckOptions, $.filename = "test.c"));
366+
"return *str==\"bug\"; }\n", dinit(CheckOptions, $.cpp = false));
367367
ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n", errout_str());
368368

369369
// Ticket #4257
@@ -375,27 +375,27 @@ class TestString : public TestFixture {
375375
// Ticket #4257
376376
check("bool foo() {\n"
377377
"MyString **str=OtherGetter();\n"
378-
"return *str==\"bug\"; }", dinit(CheckOptions, $.filename = "test.c"));
378+
"return *str==\"bug\"; }", dinit(CheckOptions, $.cpp = false));
379379
ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n", errout_str());
380380

381381
// Ticket #4257
382382
check("bool foo() {\n"
383383
"MyString str=OtherGetter2();\n"
384-
"return &str==\"bug\"; }", dinit(CheckOptions, $.filename = "test.c"));
384+
"return &str==\"bug\"; }", dinit(CheckOptions, $.cpp = false));
385385
ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead?\n", errout_str());
386386

387387
// Ticket #5734
388388
check("int foo(char c) {\n"
389389
"return c == '4';}");
390390
ASSERT_EQUALS("", errout_str());
391391
check("int foo(char c) {\n"
392-
"return c == '4';}", dinit(CheckOptions, $.filename = "test.c"));
392+
"return c == '4';}", dinit(CheckOptions, $.cpp = false));
393393
ASSERT_EQUALS("", errout_str());
394394
check("int foo(char c) {\n"
395395
"return c == \"42\"[0];}");
396396
ASSERT_EQUALS("", errout_str());
397397
check("int foo(char c) {\n"
398-
"return c == \"42\"[0];}", dinit(CheckOptions, $.filename = "test.c"));
398+
"return c == \"42\"[0];}", dinit(CheckOptions, $.cpp = false));
399399
ASSERT_EQUALS("", errout_str());
400400

401401
// 5639 String literal compared with char buffer in a struct
@@ -413,7 +413,7 @@ class TestString : public TestFixture {
413413
"void foo() {\n"
414414
" struct Example example;\n"
415415
" if (example.buffer == \"test\") ;\n"
416-
"}\n", dinit(CheckOptions, $.filename = "test.c"));
416+
"}\n", dinit(CheckOptions, $.cpp = false));
417417
ASSERT_EQUALS("[test.c:6]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead?\n", errout_str());
418418

419419
// #9726
@@ -467,7 +467,7 @@ class TestString : public TestFixture {
467467

468468
check("bool foo(char* c) {\n"
469469
" return *c == 0;\n"
470-
"}", dinit(CheckOptions, $.filename = "test.c"));
470+
"}", dinit(CheckOptions, $.cpp = false));
471471
ASSERT_EQUALS("", errout_str());
472472

473473
check("bool foo(char* c) {\n"

test/testtype.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ class TestType : public TestFixture {
8181
struct CheckPOptions
8282
{
8383
CheckPOptions() = default;
84-
const char* filename = "test.cpp";
84+
bool cpp = true;
8585
};
8686

8787
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
8888
template<size_t size>
8989
void checkP_(const char* file, int line, const char (&code)[size], const Settings& settings, const CheckPOptions& options = make_default_obj()) {
9090
const Settings settings1 = settingsBuilder(settings).severity(Severity::warning).severity(Severity::portability).build();
9191

92-
std::vector<std::string> files(1, options.filename);
92+
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
9393
Tokenizer tokenizer(settings1, *this);
9494
PreprocessorHelper::preprocess(code, files, tokenizer, *this);
9595

@@ -566,14 +566,14 @@ class TestType : public TestFixture {
566566
"void f()\n"
567567
"{\n"
568568
" unsigned short u = TEST(true, 75000.0);\n"
569-
"}\n", settingsDefault, dinit(CheckPOptions, $.filename = "test.c"));
569+
"}\n", settingsDefault, dinit(CheckPOptions, $.cpp = false));
570570
ASSERT_EQUALS("", errout_str());
571571

572572
checkP("#define TEST(b, f) b ? 5000 : (unsigned short)f\n"
573573
"void f()\n"
574574
"{\n"
575575
" unsigned short u = TEST(false, 75000.0);\n"
576-
"}\n", settingsDefault, dinit(CheckPOptions, $.filename = "test.c"));
576+
"}\n", settingsDefault, dinit(CheckPOptions, $.cpp = false));
577577
ASSERT_EQUALS("[test.c:4]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str()));
578578

579579
}

test/testvarid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ class TestVarID : public TestFixture {
298298

299299
#define tokenizeExpr(...) tokenizeExpr_(__FILE__, __LINE__, __VA_ARGS__)
300300
template<size_t size>
301-
std::string tokenizeExpr_(const char* file, int line, const char (&code)[size], const char filename[] = "test.cpp") {
302-
std::vector<std::string> files(1, filename);
301+
std::string tokenizeExpr_(const char* file, int line, const char (&code)[size]) {
302+
std::vector<std::string> files(1, "test.cpp");
303303
Tokenizer tokenizer(settings, *this);
304304
PreprocessorHelper::preprocess(code, files, tokenizer, *this);
305305

0 commit comments

Comments
 (0)