Skip to content

Commit 4372cfb

Browse files
committed
Revert "testrunner: even more SettingsBuilder usage and const cleanups (danmar#5030)"
This reverts commit 5833fc3.
1 parent 1999bc6 commit 4372cfb

17 files changed

+229
-215
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h
667667
cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
668668
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/threadexecutor.cpp
669669

670-
test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h test/redirect.h
670+
test/fixture.o: test/fixture.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h test/redirect.h
671671
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp
672672

673673
test/helpers.o: test/helpers.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/helpers.h

test/fixture.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include <sstream>
3131
#include <string>
3232

33-
#include <tinyxml2.h>
34-
3533
std::ostringstream errout;
3634
std::ostringstream output;
3735

@@ -423,13 +421,3 @@ TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::platform(cppcheck::P
423421
throw std::runtime_error("platform '" + platformStr + "' not found");
424422
return *this;
425423
}
426-
427-
TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::libraryxml(const char xmldata[], std::size_t len)
428-
{
429-
tinyxml2::XMLDocument doc;
430-
if (tinyxml2::XML_SUCCESS != doc.Parse(xmldata, len))
431-
throw std::runtime_error("loading XML data failed");
432-
if (settings.library.load(doc).errorcode != Library::ErrorCode::OK)
433-
throw std::runtime_error("loading library XML failed");
434-
return *this;
435-
}

test/fixture.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ class TestFixture : public ErrorLogger {
176176

177177
SettingsBuilder& library(const char lib[]);
178178

179-
SettingsBuilder& libraryxml(const char xmldata[], std::size_t len);
180-
181179
SettingsBuilder& platform(cppcheck::Platform::Type type);
182180

183181
SettingsBuilder& checkConfiguration() {

test/testbufferoverrun.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,7 @@ class TestBufferOverrun : public TestFixture {
35323532
}
35333533

35343534
void buffer_overrun_readSizeFromCfg() {
3535+
Settings settings;
35353536
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
35363537
"<def>\n"
35373538
" <podtype name=\"u8\" sign=\"u\" size=\"1\"/>\n"
@@ -3543,7 +3544,7 @@ class TestBufferOverrun : public TestFixture {
35433544
" <arg nr=\"2\"/>\n"
35443545
" </function>\n"
35453546
"</def>";
3546-
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
3547+
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
35473548

35483549
// Attempt to get size from Cfg files, no false positives if size is not specified
35493550
check("void f() {\n"
@@ -4084,6 +4085,7 @@ class TestBufferOverrun : public TestFixture {
40844085
// extracttests.disable
40854086

40864087
void minsize_argvalue() {
4088+
Settings settings;
40874089
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
40884090
"<def>\n"
40894091
" <function name=\"mymemset\">\n"
@@ -4095,7 +4097,8 @@ class TestBufferOverrun : public TestFixture {
40954097
" <arg nr=\"3\"/>\n"
40964098
" </function>\n"
40974099
"</def>";
4098-
Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).severity(Severity::warning).build();
4100+
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
4101+
settings.severity.enable(Severity::warning);
40994102
settings.platform.sizeof_wchar_t = 4;
41004103

41014104
check("void f() {\n"
@@ -4221,6 +4224,7 @@ class TestBufferOverrun : public TestFixture {
42214224
}
42224225

42234226
void minsize_sizeof() {
4227+
Settings settings;
42244228
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
42254229
"<def>\n"
42264230
" <function name=\"mystrncpy\">\n"
@@ -4233,7 +4237,7 @@ class TestBufferOverrun : public TestFixture {
42334237
" <arg nr=\"3\"/>\n"
42344238
" </function>\n"
42354239
"</def>";
4236-
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
4240+
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
42374241

42384242
check("void f() {\n"
42394243
" char c[7];\n"
@@ -4281,6 +4285,7 @@ class TestBufferOverrun : public TestFixture {
42814285
}
42824286

42834287
void minsize_strlen() {
4288+
Settings settings;
42844289
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
42854290
"<def>\n"
42864291
" <function name=\"mysprintf\">\n"
@@ -4294,7 +4299,7 @@ class TestBufferOverrun : public TestFixture {
42944299
" </arg>\n"
42954300
" </function>\n"
42964301
"</def>";
4297-
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
4302+
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
42984303

42994304
// formatstr..
43004305
check("void f() {\n"
@@ -4394,6 +4399,7 @@ class TestBufferOverrun : public TestFixture {
43944399
}
43954400

43964401
void minsize_mul() {
4402+
Settings settings;
43974403
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
43984404
"<def>\n"
43994405
" <function name=\"myfread\">\n"
@@ -4405,7 +4411,7 @@ class TestBufferOverrun : public TestFixture {
44054411
" <arg nr=\"4\"/>\n"
44064412
" </function>\n"
44074413
"</def>";
4408-
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
4414+
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
44094415

44104416
check("void f() {\n"
44114417
" char c[5];\n"

test/testclass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3397,12 +3397,13 @@ class TestClass : public TestFixture {
33973397
}
33983398

33993399
void memsetOnStdPodType() { // Ticket #5901
3400+
Settings settings;
34003401
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
34013402
"<def>\n"
34023403
" <podtype name=\"std::uint8_t\" sign=\"u\" size=\"1\"/>\n"
34033404
" <podtype name=\"std::atomic_bool\"/>\n"
34043405
"</def>";
3405-
const Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
3406+
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
34063407

34073408
checkNoMemset("class A {\n"
34083409
" std::array<int, 10> ints;\n"

test/testconstructors.cpp

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TestConstructors : public TestFixture {
3232
TestConstructors() : TestFixture("TestConstructors") {}
3333

3434
private:
35-
const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
35+
Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
3636

3737
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
3838
void check_(const char* file, int line, const char code[], bool inconclusive = false) {
@@ -1493,31 +1493,29 @@ class TestConstructors : public TestFixture {
14931493
}
14941494

14951495
void initvar_private_constructor() {
1496-
{
1497-
const Settings s = settingsBuilder(settings).cpp( Standards::CPP11).build();
1498-
check("class Fred\n"
1499-
"{\n"
1500-
"private:\n"
1501-
" int var;\n"
1502-
" Fred();\n"
1503-
"};\n"
1504-
"Fred::Fred()\n"
1505-
"{ }", s);
1506-
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::var' is not initialized in the constructor.\n", errout.str());
1507-
}
1508-
1509-
{
1510-
const Settings s = settingsBuilder(settings).cpp(Standards::CPP03).build();
1511-
check("class Fred\n"
1512-
"{\n"
1513-
"private:\n"
1514-
" int var;\n"
1515-
" Fred();\n"
1516-
"};\n"
1517-
"Fred::Fred()\n"
1518-
"{ }", s);
1519-
ASSERT_EQUALS("", errout.str());
1520-
}
1496+
const Settings settingsOld = settings;
1497+
settings.standards.cpp = Standards::CPP11;
1498+
check("class Fred\n"
1499+
"{\n"
1500+
"private:\n"
1501+
" int var;\n"
1502+
" Fred();\n"
1503+
"};\n"
1504+
"Fred::Fred()\n"
1505+
"{ }");
1506+
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::var' is not initialized in the constructor.\n", errout.str());
1507+
1508+
settings.standards.cpp = Standards::CPP03;
1509+
check("class Fred\n"
1510+
"{\n"
1511+
"private:\n"
1512+
" int var;\n"
1513+
" Fred();\n"
1514+
"};\n"
1515+
"Fred::Fred()\n"
1516+
"{ }");
1517+
ASSERT_EQUALS("", errout.str());
1518+
settings = settingsOld;
15211519
}
15221520

15231521
void initvar_copy_constructor() { // ticket #1611
@@ -3542,23 +3540,19 @@ class TestConstructors : public TestFixture {
35423540
}
35433541

35443542
void privateCtor1() {
3545-
{
3546-
const Settings s = settingsBuilder(settings).cpp(Standards::CPP03).build();
3547-
check("class Foo {\n"
3548-
" int foo;\n"
3549-
" Foo() { }\n"
3550-
"};", s);
3551-
ASSERT_EQUALS("", errout.str());
3552-
}
3553-
3554-
{
3555-
const Settings s = settingsBuilder(settings).cpp(Standards::CPP11).build();
3556-
check("class Foo {\n"
3557-
" int foo;\n"
3558-
" Foo() { }\n"
3559-
"};", s);
3560-
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Foo::foo' is not initialized in the constructor.\n", errout.str());
3561-
}
3543+
settings.standards.cpp = Standards::CPP03;
3544+
check("class Foo {\n"
3545+
" int foo;\n"
3546+
" Foo() { }\n"
3547+
"};");
3548+
ASSERT_EQUALS("", errout.str());
3549+
3550+
settings.standards.cpp = Standards::CPP11;
3551+
check("class Foo {\n"
3552+
" int foo;\n"
3553+
" Foo() { }\n"
3554+
"};");
3555+
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Foo::foo' is not initialized in the constructor.\n", errout.str());
35623556
}
35633557

35643558
void privateCtor2() {

test/testexceptionsafety.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ class TestExceptionSafety : public TestFixture {
6060
}
6161

6262
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
63-
void check_(const char* file, int line, const char code[], bool inconclusive = false, const Settings *s = nullptr) {
63+
void check_(const char* file, int line, const char code[], bool inconclusive = false) {
6464
// Clear the error buffer..
6565
errout.str("");
6666

67-
Settings settings1 = settingsBuilder(s ? *s : settings).certainty(Certainty::inconclusive, inconclusive).build();
67+
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
6868

6969
// Tokenize..
70-
Tokenizer tokenizer(&settings1, this);
70+
Tokenizer tokenizer(&settings, this);
7171
std::istringstream istr(code);
7272
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
7373

7474
// Check char variable usage..
75-
runChecks<CheckExceptionSafety>(&tokenizer, &settings1, this);
75+
runChecks<CheckExceptionSafety>(&tokenizer, &settings, this);
7676
}
7777

7878
void destructors() {
@@ -398,9 +398,13 @@ class TestExceptionSafety : public TestFixture {
398398
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (style, inconclusive) Unhandled exception specification when calling function f().\n"
399399
"[test.cpp:6] -> [test.cpp:1]: (style, inconclusive) Unhandled exception specification when calling function f().\n", errout.str());
400400

401-
const Settings s = settingsBuilder(settings).library("gnu.cfg").build();
402-
check(code, true, &s);
401+
Settings settingsOld = settings;
402+
LOAD_LIB_2(settings.library, "gnu.cfg");
403+
404+
check(code, true);
403405
ASSERT_EQUALS("", errout.str());
406+
407+
settings = settingsOld;
404408
}
405409

406410
void nothrowAttributeThrow() {

0 commit comments

Comments
 (0)