From e3f06760367fa6f5e0c18593394c6b0513401791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 31 Jan 2024 22:55:14 +0100 Subject: [PATCH] testrunner: reduced usage of mutable `Settings` / some cleanups (#5909) --- test/fixture.cpp | 10 +++-- test/fixture.h | 1 - test/testbufferoverrun.cpp | 4 +- test/testclass.cpp | 30 +++++++-------- test/testcondition.cpp | 2 +- test/testexceptionsafety.cpp | 2 +- test/testfunctions.cpp | 2 +- test/testgarbage.cpp | 2 +- test/testinternal.cpp | 2 +- test/testio.cpp | 2 +- test/testother.cpp | 33 +++++++---------- test/testpreprocessor.cpp | 47 +++++++++++------------- test/testprocessexecutor.cpp | 4 +- test/testsingleexecutor.cpp | 4 +- test/teststl.cpp | 2 +- test/testsuppressions.cpp | 16 ++++---- test/testsymboldatabase.cpp | 71 ++++++++++++++++++++---------------- test/testthreadexecutor.cpp | 4 +- test/testtokenlist.cpp | 2 +- test/testunusedvar.cpp | 2 +- test/testvalueflow.cpp | 24 +++++------- 21 files changed, 129 insertions(+), 137 deletions(-) diff --git a/test/fixture.cpp b/test/fixture.cpp index f8a433d66e7..71281e3fa60 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -461,9 +461,11 @@ TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::platform(Platform::T TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::libraryxml(const char xmldata[], std::size_t len) { tinyxml2::XMLDocument doc; - if (tinyxml2::XML_SUCCESS != doc.Parse(xmldata, len)) - throw std::runtime_error("loading XML data failed"); - if (settings.library.load(doc).errorcode != Library::ErrorCode::OK) - throw std::runtime_error("loading library XML failed"); + const tinyxml2::XMLError xml_error = doc.Parse(xmldata, len); + if (tinyxml2::XML_SUCCESS != xml_error) + throw std::runtime_error(std::string("loading XML data failed - ") + tinyxml2::XMLDocument::ErrorIDToName(xml_error)); + const Library::ErrorCode lib_error = settings.library.load(doc).errorcode; + if (lib_error != Library::ErrorCode::OK) + throw std::runtime_error("loading library XML failed - " + std::to_string(static_cast(lib_error))); return *this; } diff --git a/test/fixture.h b/test/fixture.h index 1a8b3878db4..f278b51d13e 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -282,7 +282,6 @@ class TestFixture : public ErrorLogger { #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_ ## CLASSNAME; } #define LOAD_LIB_2_EXE( LIB, NAME, EXE ) do { if (((LIB).load((EXE), NAME).errorcode != Library::ErrorCode::OK)) throw std::runtime_error("library '" + std::string(NAME) + "' not found"); } while (false) -#define LOAD_LIB_2( LIB, NAME ) LOAD_LIB_2_EXE(LIB, NAME, exename.c_str()) #define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(Platform::toString(T), errstr, {exename}), errstr); } while (false) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 128b8120a6f..51255de8729 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -38,7 +38,7 @@ class TestBufferOverrun : public TestFixture { TestBufferOverrun() : TestFixture("TestBufferOverrun") {} private: - Settings settings0 = settingsBuilder().library("std.cfg").severity(Severity::warning).severity(Severity::style).severity(Severity::portability).build(); + /*const*/ Settings settings0 = settingsBuilder().library("std.cfg").severity(Severity::warning).severity(Severity::style).severity(Severity::portability).build(); #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { @@ -4191,7 +4191,7 @@ class TestBufferOverrun : public TestFixture { " \n" " \n" ""; - Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).severity(Severity::warning).build(); + /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).severity(Severity::warning).build(); settings.platform.sizeof_wchar_t = 4; check("void f() {\n" diff --git a/test/testclass.cpp b/test/testclass.cpp index 601f384ffcf..8d6fb0478cb 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -35,8 +35,10 @@ class TestClass : public TestFixture { TestClass() : TestFixture("TestClass") {} private: - Settings settings0 = settingsBuilder().severity(Severity::style).library("std.cfg").build(); + const Settings settings0 = settingsBuilder().severity(Severity::style).library("std.cfg").build(); const Settings settings1 = settingsBuilder().severity(Severity::warning).library("std.cfg").build(); + const Settings settings2 = settingsBuilder().severity(Severity::style).library("std.cfg").certainty(Certainty::inconclusive).build(); + const Settings settings3 = settingsBuilder().severity(Severity::style).library("std.cfg").severity(Severity::warning).build(); void run() override { TEST_CASE(virtualDestructor1); // Base class not found => no error @@ -731,15 +733,15 @@ class TestClass : public TestFixture { // Clear the error log errout.str(""); - Preprocessor preprocessor(settings0); + Preprocessor preprocessor(settings3); // Tokenize.. - Tokenizer tokenizer(settings0, this, &preprocessor); + Tokenizer tokenizer(settings3, this, &preprocessor); std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. - CheckClass checkClass(&tokenizer, &settings0, this); + CheckClass checkClass(&tokenizer, &settings3, this); checkClass.copyconstructors(); } @@ -2617,19 +2619,17 @@ class TestClass : public TestFixture { // Clear the error log errout.str(""); - // TODO: subsequent tests depend on these changes - should use SettingsBuilder - settings0.certainty.setEnabled(Certainty::inconclusive, inconclusive); - settings0.severity.enable(Severity::warning); + const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, inconclusive).severity(Severity::warning).build(); - Preprocessor preprocessor(settings0); + Preprocessor preprocessor(s); // Tokenize.. - Tokenizer tokenizer(settings0, this, &preprocessor); + Tokenizer tokenizer(s, this, &preprocessor); std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. - CheckClass checkClass(&tokenizer, &settings0, this); + CheckClass checkClass(&tokenizer, &s, this); checkClass.virtualDestructor(); } @@ -7565,16 +7565,14 @@ class TestClass : public TestFixture { errout.str(""); // Check.. - settings0.certainty.setEnabled(Certainty::inconclusive, true); - - Preprocessor preprocessor(settings0); + Preprocessor preprocessor(settings2); // Tokenize.. - Tokenizer tokenizer(settings0, this, &preprocessor); + Tokenizer tokenizer(settings2, this, &preprocessor); std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); - CheckClass checkClass(&tokenizer, &settings0, this); + CheckClass checkClass(&tokenizer, &settings2, this); checkClass.initializerListOrder(); } @@ -8749,7 +8747,7 @@ class TestClass : public TestFixture { // Clear the error log errout.str(""); - Settings settings = settingsBuilder().severity(Severity::warning).build(); + /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build(); settings.safeChecks.classes = true; Preprocessor preprocessor(settings); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index df48369c6cc..72adc6fac04 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -36,7 +36,7 @@ class TestCondition : public TestFixture { private: const Settings settings0 = settingsBuilder().library("qt.cfg").library("std.cfg").severity(Severity::style).severity(Severity::warning).build(); - Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build(); + /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build(); void run() override { const char cfg[] = "\n" diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 117ebc8015c..243cd63af52 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -30,7 +30,7 @@ class TestExceptionSafety : public TestFixture { TestExceptionSafety() : TestFixture("TestExceptionSafety") {} private: - Settings settings; + /*const*/ Settings settings; void run() override { settings.severity.fill(); diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 6f475931a54..6fdc2f42dc6 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1837,7 +1837,7 @@ class TestFunctions : public TestFixture { } void checkLibraryMatchFunctions() { - Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build(); + /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build(); s.daca = true; check("void f() {\n" diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 22a727fe719..8e94cd11d58 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -34,7 +34,7 @@ class TestGarbage : public TestFixture { TestGarbage() : TestFixture("TestGarbage") {} private: - Settings settings = settingsBuilder().debugwarnings().build(); + /*const*/ Settings settings = settingsBuilder().debugwarnings().build(); void run() override { settings.severity.fill(); diff --git a/test/testinternal.cpp b/test/testinternal.cpp index ee271f0d308..069345131ed 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -30,7 +30,7 @@ class TestInternal : public TestFixture { TestInternal() : TestFixture("TestInternal") {} private: - Settings settings; + /*const*/ Settings settings; void run() override { settings.addEnabled("internal"); diff --git a/test/testio.cpp b/test/testio.cpp index 024757bf6c9..c20e162eb83 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -35,7 +35,7 @@ class TestIO : public TestFixture { private: const Settings settings = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").build(); - Settings settings1 = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").build(); + /*const*/ Settings settings1 = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").build(); void run() override { TEST_CASE(coutCerrMisusage); diff --git a/test/testother.cpp b/test/testother.cpp index 2dbebf306d8..90247330a9f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -35,12 +35,9 @@ class TestOther : public TestFixture { TestOther() : TestFixture("TestOther") {} private: - Settings _settings; + /*const*/ Settings _settings = settingsBuilder().library("std.cfg").build(); void run() override { - LOAD_LIB_2(_settings.library, "std.cfg"); - - TEST_CASE(emptyBrackets); TEST_CASE(zeroDiv1); @@ -355,8 +352,7 @@ class TestOther : public TestFixture { } void checkInterlockedDecrement(const char code[]) { - Settings settings; - settings.platform.type = Platform::Type::Win32A; + /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build(); check(code, nullptr, false, true, false, &settings); } @@ -1905,7 +1901,7 @@ class TestOther : public TestFixture { // Clear the error buffer.. errout.str(""); - Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build(); + /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build(); settings.platform.defaultSign = 's'; Preprocessor preprocessor(settings); @@ -2204,7 +2200,7 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 't' should be passed by const reference.\n", errout.str()); - Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); + /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); check("struct S {\n" // #12138 " union {\n" " int a = 0;\n" @@ -2243,7 +2239,7 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 's' should be passed by const reference.\n", errout.str()); - Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); + /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); check("using ui64 = unsigned __int64;\n" "ui64 Test(ui64 one, ui64 two) { return one + two; }\n", /*filename*/ nullptr, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1); @@ -2390,11 +2386,11 @@ class TestOther : public TestFixture { "};\n" "void f(X x) {}"; - Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build(); + /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build(); check(code, &s32); ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by const reference.\n", errout.str()); - Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); + /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); check(code, &s64); ASSERT_EQUALS("", errout.str()); } @@ -4929,7 +4925,7 @@ class TestOther : public TestFixture { " \n" " \n" ""; - Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); + /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); check("void foo() {\n" " exit(0);\n" @@ -6627,7 +6623,7 @@ class TestOther : public TestFixture { " \n" " \n" ""; - Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); + /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); check("void foo() {\n" " if (x() || x()) {}\n" @@ -7268,7 +7264,7 @@ class TestOther : public TestFixture { const char code[] = "void foo(bool flag) {\n" " bar( (flag) ? ~0u : ~0ul);\n" "}"; - Settings settings = _settings; + /*const*/ Settings settings = _settings; settings.platform.sizeof_int = 4; settings.platform.int_bit = 32; @@ -8217,10 +8213,9 @@ class TestOther : public TestFixture { } { - Settings s = settingsBuilder().checkUnusedTemplates().build(); check("template void foo(unsigned int x) {\n" "if (x <= 0);\n" - "}", &s); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str()); } @@ -8235,7 +8230,7 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3]: (style) Checking if unsigned expression 'value' is less than zero.\n", errout.str()); // #9040 - Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); + /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); check("using BOOL = unsigned;\n" "int i;\n" "bool f() {\n" @@ -11123,13 +11118,11 @@ class TestOther : public TestFixture { } void forwardAndUsed() { - Settings s = settingsBuilder().checkUnusedTemplates().build(); - check("template\n" "void f(T && t) {\n" " g(std::forward(t));\n" " T s = t;\n" - "}", &s); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) Access of forwarded variable 't'.\n", errout.str()); } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 9d2bd010e5a..9bf351ddccd 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -368,8 +368,7 @@ class TestPreprocessor : public TestFixture { void error3() { errout.str(""); - Settings settings; - settings.userDefines = "__cplusplus"; + const auto settings = dinit(Settings, $.userDefines = "__cplusplus"); Preprocessor preprocessor(settings, this); const std::string code("#error hello world!\n"); PreprocessorHelper::getcode(preprocessor, code, "X", "test.c"); @@ -381,8 +380,7 @@ class TestPreprocessor : public TestFixture { // In included file { errout.str(""); - Settings settings; - settings.userDefines = "TEST"; + const auto settings = dinit(Settings, $.userDefines = "TEST"); Preprocessor preprocessor(settings, this); const std::string code("#file \"ab.h\"\n#error hello world!\n#endfile"); PreprocessorHelper::getcode(preprocessor, code, "TEST", "test.c"); @@ -392,8 +390,7 @@ class TestPreprocessor : public TestFixture { // After including a file { errout.str(""); - Settings settings; - settings.userDefines = "TEST"; + const auto settings = dinit(Settings, $.userDefines = "TEST"); Preprocessor preprocessor(settings, this); const std::string code("#file \"ab.h\"\n\n#endfile\n#error aaa"); PreprocessorHelper::getcode(preprocessor, code, "TEST", "test.c"); @@ -403,9 +400,10 @@ class TestPreprocessor : public TestFixture { void error5() { errout.str(""); - Settings settings; - settings.userDefines = "FOO"; - settings.force = true; // No message if --force is given + // No message if --force is given + const auto settings = dinit(Settings, + $.userDefines = "TEST", + $.force = true); Preprocessor preprocessor(settings, this); const std::string code("#error hello world!\n"); PreprocessorHelper::getcode(preprocessor, code, "X", "test.c"); @@ -1959,7 +1957,7 @@ class TestPreprocessor : public TestFixture { void inline_suppressions() { errout.str(""); - Settings settings; + /*const*/ Settings settings; settings.inlineSuppressions = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2315,8 +2313,7 @@ class TestPreprocessor : public TestFixture { void wrongPathOnErrorDirective() { errout.str(""); - Settings settings; - settings.userDefines = "foo"; + const auto settings = dinit(Settings, $.userDefines = "foo"); Preprocessor preprocessor(settings, this); const std::string code("#error hello world!\n"); PreprocessorHelper::getcode(preprocessor, code, "X", "./././test.c"); @@ -2407,7 +2404,7 @@ class TestPreprocessor : public TestFixture { // test for existing local include void testMissingInclude() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2426,7 +2423,7 @@ class TestPreprocessor : public TestFixture { // test for missing local include void testMissingInclude2() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2443,7 +2440,7 @@ class TestPreprocessor : public TestFixture { // test for missing local include - no include path given void testMissingInclude3() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2462,7 +2459,7 @@ class TestPreprocessor : public TestFixture { // test for existing local include - include path provided void testMissingInclude4() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2482,7 +2479,7 @@ class TestPreprocessor : public TestFixture { // test for existing local include - absolute path void testMissingInclude5() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2502,7 +2499,7 @@ class TestPreprocessor : public TestFixture { // test for missing local include - absolute path void testMissingInclude6() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2521,7 +2518,7 @@ class TestPreprocessor : public TestFixture { // test for missing system include - system includes are not searched for in relative path void testMissingSystemInclude() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2540,7 +2537,7 @@ class TestPreprocessor : public TestFixture { // test for missing system include void testMissingSystemInclude2() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2557,7 +2554,7 @@ class TestPreprocessor : public TestFixture { // test for existing system include in system include path void testMissingSystemInclude3() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2578,7 +2575,7 @@ class TestPreprocessor : public TestFixture { // test for existing system include - absolute path void testMissingSystemInclude4() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2598,7 +2595,7 @@ class TestPreprocessor : public TestFixture { // test for missing system include - absolute path void testMissingSystemInclude5() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2617,7 +2614,7 @@ class TestPreprocessor : public TestFixture { // test for missing local and system include void testMissingIncludeMixed() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); @@ -2641,7 +2638,7 @@ class TestPreprocessor : public TestFixture { } void testMissingIncludeCheckConfig() { - Settings settings; + /*const*/ Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index 654e1e5b8a0..6b54db41724 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -39,7 +39,7 @@ class TestProcessExecutorBase : public TestFixture { TestProcessExecutorBase(const char * const name, bool useFS) : TestFixture(name), useFS(useFS) {} private: - Settings settings = settingsBuilder().library("std.cfg").build(); + /*const*/ Settings settings = settingsBuilder().library("std.cfg").build(); bool useFS; std::string fprefix() const @@ -97,7 +97,7 @@ class TestProcessExecutorBase : public TestFixture { } } - Settings s = settings; + /*const*/ Settings s = settings; s.jobs = jobs; s.showtime = opt.showtime; s.quiet = opt.quiet; diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 4a2b9148e86..de9d1572ccb 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -39,7 +39,7 @@ class TestSingleExecutorBase : public TestFixture { TestSingleExecutorBase(const char * const name, bool useFS) : TestFixture(name), useFS(useFS) {} private: - Settings settings = settingsBuilder().library("std.cfg").build(); + /*const*/ Settings settings = settingsBuilder().library("std.cfg").build(); bool useFS; std::string fprefix() const @@ -102,7 +102,7 @@ class TestSingleExecutorBase : public TestFixture { } } - Settings s = settings; + /*const*/ Settings s = settings; s.showtime = opt.showtime; s.quiet = opt.quiet; if (opt.plistOutput) diff --git a/test/teststl.cpp b/test/teststl.cpp index 4369d6915e4..67eb86f4a6a 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -34,7 +34,7 @@ class TestStl : public TestFixture { TestStl() : TestFixture("TestStl") {} private: - Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library("std.cfg").build(); + /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library("std.cfg").build(); void run() override { TEST_CASE(outOfBounds); diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 0f08e850ba2..8e1fb86c096 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -296,10 +296,10 @@ class TestSuppressions : public TestFixture { fileSettings.emplace_back(std::move(fs)); } - Settings settings; - settings.jobs = 2; - settings.quiet = true; - settings.inlineSuppressions = true; + /*const*/ auto settings = dinit(Settings, + $.jobs = 2, + $.quiet = true, + $.inlineSuppressions = true); settings.severity.enable(Severity::information); if (!suppression.empty()) { EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression)); @@ -346,10 +346,10 @@ class TestSuppressions : public TestFixture { fileSettings.emplace_back(std::move(fs)); } - Settings settings; - settings.jobs = 2; - settings.quiet = true; - settings.inlineSuppressions = true; + /*const*/ auto settings = dinit(Settings, + $.jobs = 2, + $.quiet = true, + $.inlineSuppressions = true); settings.severity.enable(Severity::information); if (!suppression.empty()) { EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression)); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index cf6fb8b06da..1cfaf407602 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -8480,12 +8480,12 @@ class TestSymbolDatabase : public TestFixture { // stringification ASSERT_EQUALS("", ValueType().str()); - Settings s; + /*const*/ Settings s; s.platform.int_bit = 16; s.platform.long_bit = 32; s.platform.long_long_bit = 64; - Settings sSameSize; + /*const*/ Settings sSameSize; sSameSize.platform.int_bit = 32; sSameSize.platform.long_bit = 64; sSameSize.platform.long_long_bit = 64; @@ -8744,13 +8744,13 @@ class TestSymbolDatabase : public TestFixture { // Library types { // Char types - Settings settings; - constexpr Library::PodType char8 = { 1, 'u' }; - constexpr Library::PodType char16 = { 2, 'u' }; - constexpr Library::PodType char32 = { 4, 'u' }; - settings.library.mPodTypes["char8_t"] = char8; - settings.library.mPodTypes["char16_t"] = char16; - settings.library.mPodTypes["char32_t"] = char32; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + ""; + /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); settings.platform.sizeof_short = 2; settings.platform.sizeof_int = 4; @@ -8763,12 +8763,13 @@ class TestSymbolDatabase : public TestFixture { } { // PodType - Settings settingsWin64 = settingsBuilder().platform(Platform::Type::Win64).build(); - constexpr Library::PodType u32 = { 4, 'u' }; - constexpr Library::PodType podtype2 = { 0, 'u', Library::PodType::Type::INT }; - settingsWin64.library.mPodTypes["u32"] = u32; - settingsWin64.library.mPodTypes["xyz::x"] = u32; - settingsWin64.library.mPodTypes["podtype2"] = podtype2; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + ""; + const Settings settingsWin64 = settingsBuilder().platform(Platform::Type::Win64).libraryxml(xmldata, sizeof(xmldata)).build(); ValueType vt; ASSERT_EQUALS(true, vt.fromLibraryType("u32", settingsWin64)); ASSERT_EQUALS(true, vt.fromLibraryType("xyz::x", settingsWin64)); @@ -8784,20 +8785,26 @@ class TestSymbolDatabase : public TestFixture { } { // PlatformType - Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build(); - Library::PlatformType s32; - s32.mType = "int"; - settingsUnix32.library.mPlatforms[settingsUnix32.platform.toString()].mPlatformTypes["s32"] = s32; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + ""; + const Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).libraryxml(xmldata, sizeof(xmldata)).build(); ValueType vt; ASSERT_EQUALS(true, vt.fromLibraryType("s32", settingsUnix32)); ASSERT_EQUALS(ValueType::Type::INT, vt.type); } { // PlatformType - wchar_t - Settings settingsWin64 = settingsBuilder().platform(Platform::Type::Win64).build(); - Library::PlatformType lpctstr; - lpctstr.mType = "wchar_t"; - settingsWin64.library.mPlatforms[settingsWin64.platform.toString()].mPlatformTypes["LPCTSTR"] = lpctstr; + constexpr char xmldata[] = "\n" + "\n" + " \n" + " \n" + " \n" + ""; + const Settings settingsWin64 = settingsBuilder().platform(Platform::Type::Win64).libraryxml(xmldata, sizeof(xmldata)).build(); ValueType vt; ASSERT_EQUALS(true, vt.fromLibraryType("LPCTSTR", settingsWin64)); ASSERT_EQUALS(ValueType::Type::WCHAR_T, vt.type); @@ -8892,10 +8899,11 @@ class TestSymbolDatabase : public TestFixture { // std::make_shared { - Settings set; - Library::SmartPointer sharedPtr; - sharedPtr.name = "std::shared_ptr"; - set.library.smartPointers["std::shared_ptr"] = sharedPtr; + constexpr char xmldata[] = "\n" + "\n" + " \n" + ""; + const Settings set = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); ASSERT_EQUALS("smart-pointer(std::shared_ptr)", typeOf("class C {}; x = std::make_shared();", "(", "test.cpp", &set)); } @@ -8912,10 +8920,11 @@ class TestSymbolDatabase : public TestFixture { } // Smart pointer { - Settings set; - Library::SmartPointer myPtr; - myPtr.name = "MyPtr"; - set.library.smartPointers["MyPtr"] = myPtr; + constexpr char xmldata[] = "\n" + "\n" + " \n" + ""; + const Settings set = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); ASSERT_EQUALS("smart-pointer(MyPtr)", typeOf("void f() { MyPtr p; return p; }", "p ;", "test.cpp", &set)); ASSERT_EQUALS("signed int", typeOf("void f() { MyPtr p; return *p; }", "* p ;", "test.cpp", &set)); diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 7a8bfa3e7e8..dcb006db5c5 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -39,7 +39,7 @@ class TestThreadExecutorBase : public TestFixture { TestThreadExecutorBase(const char * const name, bool useFS) : TestFixture(name), useFS(useFS) {} private: - Settings settings = settingsBuilder().library("std.cfg").build(); + /*const*/ Settings settings = settingsBuilder().library("std.cfg").build(); bool useFS; std::string fprefix() const @@ -97,7 +97,7 @@ class TestThreadExecutorBase : public TestFixture { } } - Settings s = settings; + /*const*/ Settings s = settings; s.jobs = jobs; s.showtime = opt.showtime; s.quiet = opt.quiet; diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index 0b979aa2df6..a3542b6ee56 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -50,7 +50,7 @@ class TestTokenList : public TestFixture { void testaddtoken2() const { const std::string code = "0xF0000000"; - Settings settings1; + /*const*/ Settings settings1; settings1.platform.int_bit = 32; TokenList tokenlist(&settings1); tokenlist.addtoken(code, 1, 1, false); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 3a8bbeed294..5bd59e6f5dc 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1821,7 +1821,7 @@ class TestUnusedVar : public TestFixture { ASSERT_EQUALS("[test.cpp:1]: (style) struct member 'A::i' is never used.\n", errout.str()); - Settings s = settings; + /*const*/ Settings s = settings; s.enforcedLang = Standards::Language::C; checkStructMemberUsage("struct A {\n" // #10852 " struct B {\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 776a691dbe1..e160a7fb66a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -42,7 +42,7 @@ class TestValueFlow : public TestFixture { TestValueFlow() : TestFixture("TestValueFlow") {} private: - Settings settings = settingsBuilder().library("std.cfg").exhaustive().build(); + /*const*/ Settings settings = settingsBuilder().library("std.cfg").exhaustive().build(); void run() override { // strcpy, abort cfg @@ -633,8 +633,6 @@ class TestValueFlow : public TestFixture { const char *code; std::vector lifetimes; - LOAD_LIB_2(settings.library, "std.cfg"); - code = "void f() {\n" " int a = 1;\n" " auto x = [&]() { return a + 1; };\n" @@ -1012,7 +1010,6 @@ class TestValueFlow : public TestFixture { // ~ code = "x = ~0U;"; - PLATFORM(settings.platform, Platform::Type::Native); // ensure platform is native values = tokenValues(code,"~"); ASSERT_EQUALS(1U, values.size()); ASSERT_EQUALS(~0U, values.back().intvalue); @@ -3946,7 +3943,7 @@ class TestValueFlow : public TestFixture { void valueFlowRightShift() { const char *code; /* Set some temporary fixed values to simplify testing */ - Settings s = settings; + /*const*/ Settings s = settings; s.platform.int_bit = 32; s.platform.long_bit = 64; s.platform.long_long_bit = MathLib::bigint_bits * 2; @@ -6070,8 +6067,6 @@ class TestValueFlow : public TestFixture { void valueFlowContainerSize() { const char *code; - LOAD_LIB_2(settings.library, "std.cfg"); - // condition code = "void f(const std::list &ints) {\n" " if (!static_cast(ints.empty()))\n" @@ -6856,8 +6851,6 @@ class TestValueFlow : public TestFixture { { const char* code; - LOAD_LIB_2(settings.library, "std.cfg"); - code = "int f() {\n" " std::vector v = {1, 2, 3, 4};\n" " int x = v[1];\n" @@ -6883,9 +6876,8 @@ class TestValueFlow : public TestFixture { void valueFlowDynamicBufferSize() { const char *code; - LOAD_LIB_2(settings.library, "std.cfg"); - LOAD_LIB_2(settings.library, "posix.cfg"); - LOAD_LIB_2(settings.library, "bsd.cfg"); + const Settings settingsOld = settings; + settings = settingsBuilder(settings).library("posix.cfg").library("bsd.cfg").build(); code = "void* f() {\n" " void* x = malloc(10);\n" @@ -6919,12 +6911,14 @@ class TestValueFlow : public TestFixture { " return x;\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 4U, 100, ValueFlow::Value::ValueType::BUFFER_SIZE)); + + settings = settingsOld; } void valueFlowSafeFunctionParameterValues() { const char *code; std::list values; - Settings s = settingsBuilder().exhaustive().library("std.cfg").build(); + /*const*/ Settings s = settingsBuilder().exhaustive().library("std.cfg").build(); s.safeChecks.classes = s.safeChecks.externalFunctions = s.safeChecks.internalFunctions = true; code = "short f(short x) {\n" @@ -6975,7 +6969,7 @@ class TestValueFlow : public TestFixture { void valueFlowUnknownFunctionReturn() { const char *code; std::list values; - Settings s = settingsBuilder().exhaustive().library("std.cfg").build(); + /*const*/ Settings s = settingsBuilder().exhaustive().library("std.cfg").build(); s.checkUnknownFunctionReturn.insert("rand"); code = "x = rand();"; @@ -8433,7 +8427,7 @@ class TestValueFlow : public TestFixture { } void performanceIfCount() { - Settings s(settings); + /*const*/ Settings s(settings); s.performanceValueFlowMaxIfCount = 1; const char *code;