From 598483e873d9431cee0c4dfbeb6adcf3cdae00a1 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 13 Apr 2023 15:24:08 +0200 Subject: [PATCH] moved settings ownership out of `CppCheck` --- cli/cppcheckexecutor.cpp | 3 +- cli/processexecutor.cpp | 5 +- cli/threadexecutor.cpp | 5 +- democlient/democlient.cpp | 14 ++--- gui/checkthread.cpp | 11 ++-- gui/checkthread.h | 2 +- gui/mainwindow.cpp | 3 +- lib/cppcheck.cpp | 48 ++++++++-------- lib/cppcheck.h | 14 ++--- oss-fuzz/main.cpp | 8 ++- test/testcppcheck.cpp | 107 ++++++++++++++++++++++-------------- test/testsingleexecutor.cpp | 3 +- test/testsuppressions.cpp | 17 +++--- 13 files changed, 129 insertions(+), 111 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index a6ec0bbd4aa..b98f5243def 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -440,8 +440,7 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup if (!settings.checkersReportFilename.empty()) std::remove(settings.checkersReportFilename.c_str()); - CppCheck cppcheck(supprs, stdLogger, true, executeCommand); - cppcheck.settings() = settings; // this is a copy + CppCheck cppcheck(settings, supprs, stdLogger, true, executeCommand); unsigned int returnValue = 0; if (settings.useSingleJob()) { diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 18eb13b9955..a478882fdff 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -284,13 +284,12 @@ unsigned int ProcessExecutor::check() close(pipes[0]); PipeWriter pipewriter(pipes[1]); - CppCheck fileChecker(mSuppressions, pipewriter, false, mExecuteCommand); - fileChecker.settings() = mSettings; + CppCheck fileChecker(mSettings, mSuppressions, pipewriter, false, mExecuteCommand); unsigned int resultOfCheck = 0; if (iFileSettings != mFileSettings.end()) { resultOfCheck = fileChecker.check(*iFileSettings); - if (fileChecker.settings().clangTidy) + if (mSettings.clangTidy) fileChecker.analyseClangTidy(*iFileSettings); } else { // Read file from a file diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 9d032e0357a..b81072449a3 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -112,14 +112,13 @@ class ThreadData } unsigned int check(ErrorLogger &errorLogger, const FileWithDetails *file, const FileSettings *fs) const { - CppCheck fileChecker(mSuppressions, errorLogger, false, mExecuteCommand); - fileChecker.settings() = mSettings; // this is a copy + CppCheck fileChecker(mSettings, mSuppressions, errorLogger, false, mExecuteCommand); unsigned int result; if (fs) { // file settings.. result = fileChecker.check(*fs); - if (fileChecker.settings().clangTidy) + if (mSettings.clangTidy) fileChecker.analyseClangTidy(*fs); } else { // Read file from a file diff --git a/democlient/democlient.cpp b/democlient/democlient.cpp index 8b36809af86..8421290f5e8 100644 --- a/democlient/democlient.cpp +++ b/democlient/democlient.cpp @@ -61,12 +61,9 @@ class CppcheckExecutor : public ErrorLogger { CppCheck cppcheck; public: - CppcheckExecutor() - : ErrorLogger() - , stoptime(std::time(nullptr)+2U) - , cppcheck(supprs, *this, false, nullptr) { - cppcheck.settings().addEnabled("all"); - cppcheck.settings().certainty.enable(Certainty::inconclusive); + CppcheckExecutor(const Settings& settings) + : stoptime(std::time(nullptr)+2U) + , cppcheck(settings, supprs, *this, false, nullptr) { } void run(const char code[]) { @@ -129,7 +126,10 @@ int main() std::cout << "Cppcheck " CPPCHECK_VERSION_STRING "
";
 
-    CppcheckExecutor cppcheckExecutor;
+    Settings s;
+    s.addEnabled("all");
+    s.certainty.enable(Certainty::inconclusive);
+    CppcheckExecutor cppcheckExecutor(s);
     cppcheckExecutor.run(code);
 
     std::fclose(logfile);
diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp
index a294084ef57..51f68e6e6e8 100644
--- a/gui/checkthread.cpp
+++ b/gui/checkthread.cpp
@@ -131,8 +131,7 @@ void CheckThread::run()
 {
     mState = Running;
 
-    CppCheck cppcheck(*mSuppressions, mResult, true, executeCommand);
-    cppcheck.settings() = std::move(mSettings);
+    CppCheck cppcheck(mSettings, *mSuppressions, mResult, true, executeCommand);
 
     if (!mFiles.isEmpty() || mAnalyseWholeProgram) {
         mAnalyseWholeProgram = false;
@@ -141,9 +140,9 @@ void CheckThread::run()
         qDebug() << "Whole program analysis";
         std::list files2;
         std::transform(mFiles.cbegin(), mFiles.cend(), std::back_inserter(files2), [&](const QString& file) {
-            return FileWithDetails{file.toStdString(), Path::identify(file.toStdString(), cppcheck.settings().cppHeaderProbe), 0};
+            return FileWithDetails{file.toStdString(), Path::identify(file.toStdString(), mSettings.cppHeaderProbe), 0};
         });
-        cppcheck.analyseWholeProgram(cppcheck.settings().buildDir, files2, {}, ctuInfo);
+        cppcheck.analyseWholeProgram(mSettings.buildDir, files2, {}, ctuInfo);
         mFiles.clear();
         emit done();
         return;
@@ -153,7 +152,7 @@ void CheckThread::run()
     while (!file.isEmpty() && mState == Running) {
         qDebug() << "Checking file" << file;
         cppcheck.check(FileWithDetails(file.toStdString()));
-        runAddonsAndTools(cppcheck.settings(), nullptr, file);
+        runAddonsAndTools(mSettings, nullptr, file);
         emit fileChecked(file);
 
         if (mState == Running)
@@ -166,7 +165,7 @@ void CheckThread::run()
         file = QString::fromStdString(fileSettings->filename());
         qDebug() << "Checking file" << file;
         cppcheck.check(*fileSettings);
-        runAddonsAndTools(cppcheck.settings(), fileSettings, QString::fromStdString(fileSettings->filename()));
+        runAddonsAndTools(mSettings, fileSettings, QString::fromStdString(fileSettings->filename()));
         emit fileChecked(file);
 
         if (mState == Running)
diff --git a/gui/checkthread.h b/gui/checkthread.h
index 3bb226628d4..239679c0e16 100644
--- a/gui/checkthread.h
+++ b/gui/checkthread.h
@@ -131,7 +131,7 @@ class CheckThread : public QThread {
 
     ThreadResult &mResult;
 
-    Settings mSettings;
+    Settings mSettings; // TODO: make ref
     Suppressions* mSuppressions;
 
 private:
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index fc897e2c198..64712462859 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -695,8 +695,7 @@ void MainWindow::analyzeCode(const QString& code, const QString& filename)
             mUI->mResults, SLOT(debugError(ErrorItem)));
 
     // Create CppCheck instance
-    CppCheck cppcheck(supprs, result, true, nullptr);
-    cppcheck.settings() = checkSettings;
+    CppCheck cppcheck(checkSettings, supprs, result, true, nullptr);
 
     // Check
     checkLockDownUI();
diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp
index bb197c25a8a..84653aefea2 100644
--- a/lib/cppcheck.cpp
+++ b/lib/cppcheck.cpp
@@ -32,6 +32,7 @@
 #include "path.h"
 #include "platform.h"
 #include "preprocessor.h"
+#include "settings.h"
 #include "standards.h"
 #include "suppressions.h"
 #include "timer.h"
@@ -528,11 +529,13 @@ static std::string getDefinesFlags(const std::string &semicolonSeparatedString)
     return flags;
 }
 
-CppCheck::CppCheck(Suppressions& supprs,
+CppCheck::CppCheck(const Settings& settings,
+                   Suppressions& supprs,
                    ErrorLogger &errorLogger,
                    bool useGlobalSuppressions,
                    ExecuteCmdFn executeCommand)
-    : mSuppressions(supprs)
+    : mSettings(settings)
+    , mSuppressions(supprs)
     , mLogger(new CppCheckLogger(errorLogger, mSettings, mSuppressions, useGlobalSuppressions))
     , mErrorLogger(*mLogger)
     , mErrorLoggerDirect(errorLogger)
@@ -783,31 +786,33 @@ unsigned int CppCheck::check(const FileSettings &fs)
     if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
         mUnusedFunctionsCheck.reset(new CheckUnusedFunctions());
 
-    // need to pass the externally provided ErrorLogger instead of our internal wrapper
-    CppCheck temp(mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand);
-    temp.mSettings = mSettings;
-    if (!temp.mSettings.userDefines.empty())
-        temp.mSettings.userDefines += ';';
+    Settings tempSettings = mSettings; // this is a copy
+    if (!tempSettings.userDefines.empty())
+        tempSettings.userDefines += ';';
     if (mSettings.clang)
-        temp.mSettings.userDefines += fs.defines;
+        tempSettings.userDefines += fs.defines;
     else
-        temp.mSettings.userDefines += fs.cppcheckDefines();
-    temp.mSettings.includePaths = fs.includePaths;
-    temp.mSettings.userUndefs.insert(fs.undefs.cbegin(), fs.undefs.cend());
+        tempSettings.userDefines += fs.cppcheckDefines();
+    tempSettings.includePaths = fs.includePaths;
+    tempSettings.userUndefs.insert(fs.undefs.cbegin(), fs.undefs.cend());
     if (fs.standard.find("++") != std::string::npos)
-        temp.mSettings.standards.setCPP(fs.standard);
+        tempSettings.standards.setCPP(fs.standard);
     else if (!fs.standard.empty())
-        temp.mSettings.standards.setC(fs.standard);
+        tempSettings.standards.setC(fs.standard);
     if (fs.platformType != Platform::Type::Unspecified)
-        temp.mSettings.platform.set(fs.platformType);
+        tempSettings.platform.set(fs.platformType);
     if (mSettings.clang) {
-        temp.mSettings.includePaths.insert(temp.mSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend());
+        tempSettings.includePaths.insert(tempSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend());
+        // need to pass the externally provided ErrorLogger instead of our internal wrapper
+        CppCheck temp(tempSettings, mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand);
         // TODO: propagate back mFileInfo
         const unsigned int returnValue = temp.check(fs.file);
         if (mUnusedFunctionsCheck)
             mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
         return returnValue;
     }
+    // need to pass the externally provided ErrorLogger instead of our internal wrapper
+    CppCheck temp(tempSettings, mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand);
     const unsigned int returnValue = temp.checkFile(fs.file, fs.cfg);
     if (mUnusedFunctionsCheck)
         mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
@@ -1791,11 +1796,6 @@ void CppCheck::executeAddonsWholeProgram(const std::list &files
     executeAddons(ctuInfoFiles, "");
 }
 
-Settings &CppCheck::settings()
-{
-    return mSettings;
-}
-
 void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfConfigurations)
 {
     if (!mSettings.severity.isEnabled(Severity::information) && !mTooManyConfigs)
@@ -1861,16 +1861,18 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
 
 void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
 {
-    Settings s;
-    s.addEnabled("all");
+    Settings settings;
     Suppressions supprs;
 
-    CppCheck cppcheck(supprs, errorlogger, true, nullptr);
+    CppCheck cppcheck(settings, supprs, errorlogger, true, nullptr);
     cppcheck.purgedConfigurationMessage("","");
     cppcheck.mTooManyConfigs = true;
     cppcheck.tooManyConfigsError("",0U);
     // TODO: add functions to get remaining error messages
 
+    Settings s;
+    s.addEnabled("all");
+
     // call all "getErrorMessages" in all registered Check classes
     for (auto it = Check::instances().cbegin(); it != Check::instances().cend(); ++it)
         (*it)->getErrorMessages(&errorlogger, &s);
diff --git a/lib/cppcheck.h b/lib/cppcheck.h
index b347c583d78..41610d84e58 100644
--- a/lib/cppcheck.h
+++ b/lib/cppcheck.h
@@ -23,7 +23,6 @@
 
 #include "check.h"
 #include "config.h"
-#include "settings.h"
 #include "standards.h"
 
 #include 
@@ -42,6 +41,8 @@ class Tokenizer;
 class FileWithDetails;
 class AnalyzerInformation;
 class ErrorLogger;
+class Settings;
+struct Suppressions;
 
 namespace simplecpp { class TokenList; }
 
@@ -61,7 +62,8 @@ class CPPCHECKLIB CppCheck {
     /**
      * @brief Constructor.
      */
-    CppCheck(Suppressions& supprs,
+    CppCheck(const Settings& settings,
+             Suppressions& supprs,
              ErrorLogger &errorLogger,
              bool useGlobalSuppressions,
              ExecuteCmdFn executeCommand);
@@ -101,12 +103,6 @@ class CPPCHECKLIB CppCheck {
      */
     unsigned int check(const FileWithDetails &file, const std::string &content);
 
-    /**
-     * @brief Get reference to current settings.
-     * @return a reference to current settings
-     */
-    Settings &settings();
-
     /**
      * @brief Returns current version number as a string.
      * @return version, e.g. "1.38"
@@ -209,7 +205,7 @@ class CPPCHECKLIB CppCheck {
 
     unsigned int checkClang(const FileWithDetails &file);
 
-    Settings mSettings;
+    const Settings& mSettings;
     Suppressions& mSuppressions;
 
     class CppCheckLogger;
diff --git a/oss-fuzz/main.cpp b/oss-fuzz/main.cpp
index f092184a12f..826fad91d05 100644
--- a/oss-fuzz/main.cpp
+++ b/oss-fuzz/main.cpp
@@ -50,10 +50,12 @@ static const FileWithDetails s_file("test.cpp");
 
 static void doCheck(const std::string& code)
 {
+    // TODO: create the settings only once
+    Settings s;
+    s.addEnabled("all");
+    s.certainty.setEnabled(Certainty::inconclusive, true);
     Suppressions supprs;
-    CppCheck cppcheck(supprs, s_errorLogger, false, nullptr);
-    cppcheck.settings().addEnabled("all");
-    cppcheck.settings().certainty.setEnabled(Certainty::inconclusive, true);
+    CppCheck cppcheck(s, supprs, s_errorLogger, false, nullptr);
     cppcheck.check(s_file, code);
 }
 
diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp
index d642c213bd3..3860ea6b316 100644
--- a/test/testcppcheck.cpp
+++ b/test/testcppcheck.cpp
@@ -112,9 +112,10 @@ class TestCppcheck : public TestFixture {
                         "  return 0;\n"
                         "}");
 
+        const Settings s;
         Suppressions supprs;
         ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
+        CppCheck cppcheck(s, supprs, errorLogger, false, {});
         ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(file.path())));
         // TODO: how to properly disable these warnings?
         errorLogger.ids.erase(std::remove_if(errorLogger.ids.begin(), errorLogger.ids.end(), [](const std::string& id) {
@@ -133,9 +134,10 @@ class TestCppcheck : public TestFixture {
                         "  return 0;\n"
                         "}");
 
+        const Settings s;
         Suppressions supprs;
         ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
+        CppCheck cppcheck(s, supprs, errorLogger, false, {});
         FileSettings fs{file.path()};
         ASSERT_EQUALS(1, cppcheck.check(fs));
         // TODO: how to properly disable these warnings?
@@ -155,12 +157,11 @@ class TestCppcheck : public TestFixture {
                         "  return 0;\n"
                         "}");
 
-        Suppressions supprs;
-        ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
         const char xmldata[] = R"()";
         const Settings s = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
-        cppcheck.settings() = s;
+        Suppressions supprs;
+        ErrorLogger2 errorLogger;
+        CppCheck cppcheck(s, supprs, errorLogger, false, {});
         ASSERT_EQUALS(0, cppcheck.check(FileWithDetails(file.path())));
         // TODO: how to properly disable these warnings?
         errorLogger.ids.erase(std::remove_if(errorLogger.ids.begin(), errorLogger.ids.end(), [](const std::string& id) {
@@ -182,9 +183,10 @@ class TestCppcheck : public TestFixture {
         ScopedFile test_file_b("b.cpp",
                                "#include \"inc.h\"");
 
+        const Settings s;
         Suppressions supprs;
         ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
+        CppCheck cppcheck(s, supprs, errorLogger, false, {});
         ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_a.path())));
         ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_b.path())));
         // TODO: how to properly disable these warnings?
@@ -202,36 +204,46 @@ class TestCppcheck : public TestFixture {
     void isPremiumCodingStandardId() const {
         Suppressions supprs;
         ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
-
-        cppcheck.settings().premiumArgs = "";
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
-        ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));
-
-        cppcheck.settings().premiumArgs = "--misra-c-2012 --cert-c++-2016 --autosar";
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
-        ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));
+
+        {
+            Settings s;
+            s.premiumArgs = "";
+            CppCheck cppcheck(s, supprs, errorLogger, false, {});
+
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
+            ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));
+        }
+
+        {
+            Settings s;
+            s.premiumArgs = "--misra-c-2012 --cert-c++-2016 --autosar";
+
+            CppCheck cppcheck(s, supprs, errorLogger, false, {});
+
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
+            ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));
+        }
     }
 
     void getDumpFileContentsRawTokens() const {
+        Settings s = settingsBuilder().build();
+        s.relativePaths = true;
+        s.basePaths.emplace_back("/some/path");
         Suppressions supprs;
         ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
-        cppcheck.settings() = settingsBuilder().build();
-        cppcheck.settings().relativePaths = true;
-        cppcheck.settings().basePaths.emplace_back("/some/path");
+        CppCheck cppcheck(s, supprs, errorLogger, false, {});
         std::vector files{"/some/path/test.cpp"};
         simplecpp::TokenList tokens1(files);
         const std::string expected = "  \n"
@@ -243,21 +255,32 @@ class TestCppcheck : public TestFixture {
     void getDumpFileContentsLibrary() const {
         Suppressions supprs;
         ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
-        cppcheck.settings().libraries.emplace_back("std.cfg");
-        std::vector files{ "/some/path/test.cpp" };
-        const std::string expected1 = "  \n";
-        ASSERT_EQUALS(expected1, cppcheck.getLibraryDumpData());
-        cppcheck.settings().libraries.emplace_back("posix.cfg");
-        const std::string expected2 = "  \n  \n";
-        ASSERT_EQUALS(expected2, cppcheck.getLibraryDumpData());
+
+        {
+            Settings s;
+            s.libraries.emplace_back("std.cfg");
+            CppCheck cppcheck(s, supprs, errorLogger, false, {});
+            //std::vector files{ "/some/path/test.cpp" };
+            const std::string expected = "  \n";
+            ASSERT_EQUALS(expected, cppcheck.getLibraryDumpData());
+        }
+
+        {
+            Settings s;
+            s.libraries.emplace_back("std.cfg");
+            s.libraries.emplace_back("posix.cfg");
+            CppCheck cppcheck(s, supprs, errorLogger, false, {});
+            const std::string expected = "  \n  \n";
+            ASSERT_EQUALS(expected, cppcheck.getLibraryDumpData());
+        }
     }
 
     void getClangFlagsIncludeFile() const {
+        Settings s;
+        s.userIncludes.emplace_back("1.h");
         Suppressions supprs;
         ErrorLogger2 errorLogger;
-        CppCheck cppcheck(supprs, errorLogger, false, {});
-        cppcheck.settings().userIncludes.emplace_back("1.h");
+        CppCheck cppcheck(s, supprs, errorLogger, false, {});
         ASSERT_EQUALS("-x c --include 1.h ", cppcheck.getClangFlags(Standards::Language::C));
     }
 
diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp
index 077e5414f42..736cd1f4d1b 100644
--- a/test/testsingleexecutor.cpp
+++ b/test/testsingleexecutor.cpp
@@ -107,13 +107,12 @@ class TestSingleExecutorBase : public TestFixture {
         std::string exe;
         std::vector args;
         // NOLINTNEXTLINE(performance-unnecessary-value-param)
-        CppCheck cppcheck(supprs, *this, true, [&executeCommandCalled, &exe, &args](std::string e,std::vector a,std::string,std::string&){
+        CppCheck cppcheck(s, supprs, *this, true, [&executeCommandCalled, &exe, &args](std::string e,std::vector a,std::string,std::string&){
             executeCommandCalled = true;
             exe = std::move(e);
             args = std::move(a);
             return EXIT_SUCCESS;
         });
-        cppcheck.settings() = s;
 
         std::vector> scopedfiles;
         scopedfiles.reserve(filelist.size());
diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp
index eb33c85b446..d603d33ccb1 100644
--- a/test/testsuppressions.cpp
+++ b/test/testsuppressions.cpp
@@ -246,8 +246,7 @@ class TestSuppressions : public TestFixture {
             ASSERT_EQUALS("", supprs.nomsg.addSuppressionLine(suppression));
         }
 
-        CppCheck cppCheck(supprs, *this, true, nullptr);
-        Settings& settings = cppCheck.settings();
+        Settings settings;
         settings.jobs = 1;
         settings.quiet = true;
         settings.inlineSuppressions = true;
@@ -264,6 +263,7 @@ class TestSuppressions : public TestFixture {
         if (useFS)
             filelist.clear();
 
+        CppCheck cppCheck(settings, supprs, *this, true, nullptr);
         SingleExecutor executor(cppCheck, filelist, fileSettings, settings, supprs, *this);
         const unsigned int exitCode = executor.check();
 
@@ -1195,13 +1195,14 @@ class TestSuppressions : public TestFixture {
     }
 
     void globalSuppressions() { // Testing that Cppcheck::useGlobalSuppressions works (#8515)
+        Settings settings;
+        settings.quiet = true;
+        settings.exitCode = 1;
+
         Suppressions supprs;
         ASSERT_EQUALS("", supprs.nomsg.addSuppressionLine("uninitvar"));
 
-        CppCheck cppCheck(supprs, *this, false, nullptr); // <- do not "use global suppressions". pretend this is a thread that just checks a file.
-        Settings& settings = cppCheck.settings();
-        settings.quiet = true;
-        settings.exitCode = 1;
+        CppCheck cppCheck(settings, supprs, *this, false, nullptr); // <- do not "use global suppressions". pretend this is a thread that just checks a file.
 
         const char code[] = "int f() { int a; return a; }";
         ASSERT_EQUALS(0, cppCheck.check(FileWithDetails("test.c"), code)); // <- no unsuppressed error is seen
@@ -1231,8 +1232,7 @@ class TestSuppressions : public TestFixture {
     void suppressionWithRelativePaths() {
         Suppressions supprs;
 
-        CppCheck cppCheck(supprs, *this, true, nullptr);
-        Settings& settings = cppCheck.settings();
+        Settings settings;
         settings.quiet = true;
         settings.severity.enable(Severity::style);
         settings.inlineSuppressions = true;
@@ -1246,6 +1246,7 @@ class TestSuppressions : public TestFixture {
             "    // cppcheck-suppress unusedStructMember\n"
             "    int y;\n"
             "};";
+        CppCheck cppCheck(settings, supprs, *this, true, nullptr);
         ASSERT_EQUALS(0, cppCheck.check(FileWithDetails("/somewhere/test.cpp"), code));
         ASSERT_EQUALS("",errout_str());
     }