Skip to content

Commit 9e547a3

Browse files
authored
testrunner: some Settings usage cleanups (danmar#7477)
1 parent 73de813 commit 9e547a3

18 files changed

+152
-171
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ test/testerrorlogger.o: test/testerrorlogger.cpp externals/tinyxml2/tinyxml2.h l
752752
test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/checkexceptionsafety.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
753753
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testexceptionsafety.cpp
754754

755-
test/testexecutor.o: test/testexecutor.cpp cli/executor.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.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
755+
test/testexecutor.o: test/testexecutor.cpp cli/executor.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
756756
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testexecutor.cpp
757757

758758
test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/utils.h test/fixture.h

test/testastutils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class TestAstUtils : public TestFixture {
5252
#define findLambdaEndToken(...) findLambdaEndToken_(__FILE__, __LINE__, __VA_ARGS__)
5353
template<size_t size>
5454
bool findLambdaEndToken_(const char* file, int line, const char (&code)[size], const char pattern[] = nullptr, bool checkNext = true) {
55-
const Settings settings;
56-
SimpleTokenizer tokenizer(settings, *this);
55+
SimpleTokenizer tokenizer(settingsDefault, *this);
5756
ASSERT_LOC(tokenizer.tokenize(code), file, line);
5857
const Token* const tokStart = pattern ? Token::findsimplematch(tokenizer.tokens(), pattern, strlen(pattern)) : tokenizer.tokens();
5958
const Token * const tokEnd = (::findLambdaEndToken)(tokStart);

test/testbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3497,7 +3497,7 @@ class TestBufferOverrun : public TestFixture {
34973497

34983498
void buffer_overrun_errorpath() {
34993499
setMultiline();
3500-
const Settings settingsOld = settings0;
3500+
const Settings settingsOld = settings0; // TODO: get rid of this
35013501
settings0.templateLocation = "{file}:{line}:note:{info}";
35023502

35033503
check("void f() {\n"

test/testcppcheck.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ class TestCppcheck : public TestFixture {
112112
" return 0;\n"
113113
"}");
114114

115-
/*const*/ Settings s;
116-
s.templateFormat = templateFormat;
115+
const auto s = dinit(Settings, $.templateFormat = templateFormat);
117116
Suppressions supprs;
118117
ErrorLogger2 errorLogger;
119118
CppCheck cppcheck(s, supprs, errorLogger, false, {});
@@ -135,8 +134,7 @@ class TestCppcheck : public TestFixture {
135134
" return 0;\n"
136135
"}");
137136

138-
/*const*/ Settings s;
139-
s.templateFormat = templateFormat;
137+
const auto s = dinit(Settings, $.templateFormat = templateFormat);
140138
Suppressions supprs;
141139
ErrorLogger2 errorLogger;
142140
CppCheck cppcheck(s, supprs, errorLogger, false, {});
@@ -185,9 +183,8 @@ class TestCppcheck : public TestFixture {
185183
ScopedFile test_file_b("b.cpp",
186184
"#include \"inc.h\"");
187185

188-
/*const*/ Settings s;
189186
// this is the "simple" format
190-
s.templateFormat = templateFormat; // TODO: remove when we only longer rely on toString() in unique message handling
187+
const auto s = dinit(Settings, $.templateFormat = templateFormat); // TODO: remove when we only longer rely on toString() in unique message handling
191188
Suppressions supprs;
192189
ErrorLogger2 errorLogger;
193190
CppCheck cppcheck(s, supprs, errorLogger, false, {});
@@ -218,9 +215,8 @@ class TestCppcheck : public TestFixture {
218215
"(void)b;\n"
219216
"}");
220217

221-
/*const*/ Settings s;
222218
// this is the "simple" format
223-
s.templateFormat = templateFormat; // TODO: remove when we only longer rely on toString() in unique message handling?
219+
const auto s = dinit(Settings, $.templateFormat = templateFormat); // TODO: remove when we only longer rely on toString() in unique message handling?
224220
Suppressions supprs;
225221
ErrorLogger2 errorLogger;
226222
CppCheck cppcheck(s, supprs, errorLogger, false, {});
@@ -256,8 +252,7 @@ class TestCppcheck : public TestFixture {
256252
ErrorLogger2 errorLogger;
257253

258254
{
259-
Settings s;
260-
s.premiumArgs = "";
255+
const auto s = dinit(Settings, $.premiumArgs = "");
261256
CppCheck cppcheck(s, supprs, errorLogger, false, {});
262257

263258
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
@@ -271,8 +266,7 @@ class TestCppcheck : public TestFixture {
271266
}
272267

273268
{
274-
Settings s;
275-
s.premiumArgs = "--misra-c-2012 --cert-c++-2016 --autosar";
269+
const auto s = dinit(Settings, $.premiumArgs = "--misra-c-2012 --cert-c++-2016 --autosar");
276270

277271
CppCheck cppcheck(s, supprs, errorLogger, false, {});
278272

@@ -288,7 +282,7 @@ class TestCppcheck : public TestFixture {
288282
}
289283

290284
void getDumpFileContentsRawTokens() const {
291-
Settings s = settingsBuilder().build();
285+
Settings s;
292286
s.relativePaths = true;
293287
s.basePaths.emplace_back("/some/path");
294288
Suppressions supprs;

test/testexecutor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "executor.h"
2222
#include "filesettings.h"
2323
#include "fixture.h"
24+
#include "helpers.h"
2425
#include "settings.h"
2526
#include "suppressions.h"
2627

@@ -59,9 +60,9 @@ class TestExecutor : public TestFixture {
5960
void hasToLogSimple() {
6061
const std::list<FileWithDetails> files{FileWithDetails{"test.c"}};
6162
const std::list<FileSettings> fileSettings;
62-
Settings settings;
6363
// this is the "simple" format
64-
settings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
64+
const auto settings = dinit(Settings,
65+
$.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]");
6566
Suppressions supprs;
6667
DummyExecutor executor(files, fileSettings, settings, supprs, *this);
6768

test/testleakautovar.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ class TestLeakAutoVar : public TestFixture {
3030
TestLeakAutoVar() : TestFixture("TestLeakAutoVar") {}
3131

3232
private:
33-
Settings settings;
33+
const Settings settings = settingsBuilder().library("std.cfg").build();
3434

3535
void run() override {
36-
settings = settingsBuilder(settings).library("std.cfg").build();
37-
3836
// Assign
3937
TEST_CASE(assign1);
4038
TEST_CASE(assign2);

test/testlibrary.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class TestLibrary : public TestFixture {
4040
TestLibrary() : TestFixture("TestLibrary") {}
4141

4242
private:
43-
const Settings settings;
44-
4543
void run() override {
4644
TEST_CASE(isCompliantValidationExpression);
4745
TEST_CASE(empty);
@@ -153,7 +151,7 @@ class TestLibrary : public TestFixture {
153151
" </function>\n"
154152
"</def>";
155153

156-
TokenList tokenList(&settings);
154+
TokenList tokenList(&settingsDefault);
157155
std::istringstream istr("foo();"); // <- too few arguments, not library function
158156
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
159157
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
@@ -177,7 +175,7 @@ class TestLibrary : public TestFixture {
177175
ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata)));
178176

179177
{
180-
TokenList tokenList(&settings);
178+
TokenList tokenList(&settingsDefault);
181179
std::istringstream istr("foo();"); // <- too few arguments, not library function
182180
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
183181
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
@@ -186,7 +184,7 @@ class TestLibrary : public TestFixture {
186184
ASSERT(library.isNotLibraryFunction(tokenList.front()));
187185
}
188186
{
189-
TokenList tokenList(&settings);
187+
TokenList tokenList(&settingsDefault);
190188
std::istringstream istr("foo(a);"); // <- library function
191189
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
192190
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
@@ -197,7 +195,7 @@ class TestLibrary : public TestFixture {
197195
ASSERT(func);
198196
}
199197
{
200-
TokenList tokenList(&settings);
198+
TokenList tokenList(&settingsDefault);
201199
std::istringstream istr("foo(a, b);"); // <- library function
202200
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
203201
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
@@ -208,7 +206,7 @@ class TestLibrary : public TestFixture {
208206
ASSERT(func);
209207
}
210208
{
211-
TokenList tokenList(&settings);
209+
TokenList tokenList(&settingsDefault);
212210
std::istringstream istr("foo(a, b, c);"); // <- too much arguments, not library function
213211
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
214212
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
@@ -569,14 +567,14 @@ class TestLibrary : public TestFixture {
569567
ASSERT_EQUALS(library.functions().size(), 1U);
570568

571569
{
572-
SimpleTokenizer tokenizer(settings, *this);
570+
SimpleTokenizer tokenizer(settingsDefault, *this);
573571
const char code[] = "CString str; str.Format();";
574572
ASSERT(tokenizer.tokenize(code));
575573
ASSERT(library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
576574
}
577575

578576
{
579-
SimpleTokenizer tokenizer(settings, *this);
577+
SimpleTokenizer tokenizer(settingsDefault, *this);
580578
const char code[] = "HardDrive hd; hd.Format();";
581579
ASSERT(tokenizer.tokenize(code));
582580
ASSERT(!library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
@@ -595,14 +593,14 @@ class TestLibrary : public TestFixture {
595593
ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata)));
596594

597595
{
598-
SimpleTokenizer tokenizer(settings, *this);
596+
SimpleTokenizer tokenizer(settingsDefault, *this);
599597
const char code[] = "struct X : public Base { void dostuff() { f(0); } };";
600598
ASSERT(tokenizer.tokenize(code));
601599
ASSERT(library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));
602600
}
603601

604602
{
605-
SimpleTokenizer tokenizer(settings, *this);
603+
SimpleTokenizer tokenizer(settingsDefault, *this);
606604
const char code[] = "struct X : public Base { void dostuff() { f(1,2); } };";
607605
ASSERT(tokenizer.tokenize(code));
608606
ASSERT(!library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));

test/testmemleak.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class TestMemleak : public TestFixture {
3232
TestMemleak() : TestFixture("TestMemleak") {}
3333

3434
private:
35-
const Settings settings;
36-
3735
void run() override {
3836
TEST_CASE(testFunctionReturnType);
3937
TEST_CASE(open);
@@ -43,10 +41,10 @@ class TestMemleak : public TestFixture {
4341
template<size_t size>
4442
CheckMemoryLeak::AllocType functionReturnType_(const char* file, int line, const char (&code)[size]) {
4543
// Tokenize..
46-
SimpleTokenizer tokenizer(settings, *this);
44+
SimpleTokenizer tokenizer(settingsDefault, *this);
4745
ASSERT_LOC(tokenizer.tokenize(code), file, line);
4846

49-
const CheckMemoryLeak c(&tokenizer, this, &settings);
47+
const CheckMemoryLeak c(&tokenizer, this, &settingsDefault);
5048

5149
return (c.functionReturnType)(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front());
5250
}
@@ -91,12 +89,12 @@ class TestMemleak : public TestFixture {
9189
" }\n"
9290
"};\n";
9391

94-
SimpleTokenizer tokenizer(settings, *this);
92+
SimpleTokenizer tokenizer(settingsDefault, *this);
9593
ASSERT(tokenizer.tokenize(code));
9694

9795
// there is no allocation
9896
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "ret =");
99-
const CheckMemoryLeak check(&tokenizer, nullptr, &settings);
97+
const CheckMemoryLeak check(&tokenizer, nullptr, &settingsDefault);
10098
ASSERT_EQUALS(CheckMemoryLeak::No, check.getAllocationType(tok->tokAt(2), 1));
10199
}
102100
};

test/testpreprocessor.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ class TestPreprocessor : public TestFixture {
4949
TestPreprocessor() : TestFixture("TestPreprocessor") {}
5050

5151
private:
52-
static std::string expandMacros(const char code[], ErrorLogger &errorLogger) {
52+
std::string expandMacros(const char code[], ErrorLogger &errorLogger) const {
5353
std::istringstream istr(code);
5454
simplecpp::OutputList outputList;
5555
std::vector<std::string> files;
5656
const simplecpp::TokenList tokens1 = simplecpp::TokenList(istr, files, "file.cpp", &outputList);
57-
const Settings settings;
58-
Preprocessor p(settings, errorLogger);
57+
Preprocessor p(settingsDefault, errorLogger);
5958
simplecpp::TokenList tokens2 = p.preprocess(tokens1, "", files, true);
6059
p.reportOutput(outputList, true);
6160
return tokens2.stringify();
@@ -82,15 +81,13 @@ class TestPreprocessor : public TestFixture {
8281
tokenlist.createTokens(std::move(tokens2));
8382
}
8483

85-
static std::vector<RemarkComment> getRemarkComments(const char code[], ErrorLogger& errorLogger)
84+
std::vector<RemarkComment> getRemarkComments(const char code[], ErrorLogger& errorLogger) const
8685
{
8786
std::vector<std::string> files;
8887
std::istringstream istr(code);
8988
const simplecpp::TokenList tokens1(istr, files, "test.cpp");
9089

91-
const Settings settings;
92-
93-
const Preprocessor preprocessor(settings, errorLogger);
90+
const Preprocessor preprocessor(settingsDefault, errorLogger);
9491
return preprocessor.getRemarkComments(tokens1);
9592
}
9693

@@ -316,8 +313,7 @@ class TestPreprocessor : public TestFixture {
316313
}
317314

318315
std::size_t getHash(const char filedata[]) {
319-
Settings settings;
320-
Preprocessor preprocessor(settings, *this);
316+
Preprocessor preprocessor(settingsDefault, *this);
321317
std::vector<std::string> files;
322318
std::istringstream istr(filedata);
323319
simplecpp::TokenList tokens(istr,files);

test/testprocessexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class TestProcessExecutorBase : public TestFixture {
342342

343343
void suppress_error_library() {
344344
SUPPRESS;
345-
const Settings settingsOld = settings;
345+
const Settings settingsOld = settings; // TODO: get rid of this
346346
const char xmldata[] = R"(<def format="2"><markup ext=".cpp" reporterrors="false"/></def>)";
347347
settings = settingsBuilder().libraryxml(xmldata).build();
348348
check(2, 1, 0,

0 commit comments

Comments
 (0)