From 1bf504d7e9e58115afba5819d089f20ce8e2364c Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 14:19:02 +0100 Subject: [PATCH 01/12] added `Settings::useSingleJob()` and use it instead of checking `jobs` or `jointSuppressionReport` --- cli/cppcheckexecutor.cpp | 6 ++---- lib/checkunusedfunctions.cpp | 2 +- lib/cppcheck.cpp | 10 +++++----- lib/settings.cpp | 1 - lib/settings.h | 9 ++++----- test/testsuppressions.cpp | 10 +++++----- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 37e57476138..62e3db8314f 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -242,7 +242,7 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF return false; bool err = false; - if (settings.jointSuppressionReport) { + if (settings.useSingleJob()) { for (std::map::const_iterator i = files.cbegin(); i != files.cend(); ++i) { err |= errorLogger.reportUnmatchedSuppressions( settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled)); @@ -310,10 +310,8 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) } unsigned int returnValue = 0; - if (settings.jobs == 1) { + if (settings.useSingleJob()) { // Single process - settings.jointSuppressionReport = true; - const std::size_t totalfilesize = std::accumulate(mFiles.cbegin(), mFiles.cend(), std::size_t(0), [](std::size_t v, const std::pair& f) { return v + f.second; }); diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 7f621a91485..1805b2bb251 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -360,7 +360,7 @@ Check::FileInfo *CheckUnusedFunctions::getFileInfo(const Tokenizer *tokenizer, c { if (!settings->checks.isEnabled(Checks::unusedFunction)) return nullptr; - if (settings->jobs == 1 && settings->buildDir.empty()) + if (settings->useSingleJob() && settings->buildDir.empty()) instance.parseTokens(*tokenizer, tokenizer->list.getFiles().front().c_str(), settings); return nullptr; } diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index c105fe5512b..6f8c9a54f5b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1026,7 +1026,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string // In jointSuppressionReport mode, unmatched suppressions are // collected after all files are processed - if (!mSettings.jointSuppressionReport && (mSettings.severity.isEnabled(Severity::information) || mSettings.checkConfiguration)) { + if (!mSettings.useSingleJob() && (mSettings.severity.isEnabled(Severity::information) || mSettings.checkConfiguration)) { reportUnmatchedSuppressions(mSettings.nomsg.getUnmatchedLocalSuppressions(filename, isUnusedFunctionCheckEnabled())); } @@ -1111,12 +1111,12 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer) return; - if (mSettings.jobs == 1 || !mSettings.buildDir.empty()) { + if (mSettings.useSingleJob() || !mSettings.buildDir.empty()) { // Analyse the tokens.. CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer); if (fi1) { - if (mSettings.jobs == 1) + if (mSettings.useSingleJob()) mFileInfo.push_back(fi1); if (!mSettings.buildDir.empty()) mAnalyzerInformation.setFileInfo("ctu", fi1->toString()); @@ -1128,7 +1128,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer) Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings); if (fi != nullptr) { - if (mSettings.jobs == 1) + if (mSettings.useSingleJob()) mFileInfo.push_back(fi); if (!mSettings.buildDir.empty()) mAnalyzerInformation.setFileInfo(check->name(), fi->toString()); @@ -1837,7 +1837,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map &files) diff --git a/lib/settings.cpp b/lib/settings.cpp index fb0cbbd7117..e7c66970319 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -59,7 +59,6 @@ Settings::Settings() force(false), inlineSuppressions(false), jobs(1), - jointSuppressionReport(false), loadAverage(0), maxConfigs(12), maxCtuDepth(2), diff --git a/lib/settings.h b/lib/settings.h index b8c7a89e32c..e8fe939759b 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -216,11 +216,6 @@ class CPPCHECKLIB Settings { time. Default is 1. (-j N) */ unsigned int jobs; - /** @brief Collect unmatched suppressions in one run. - * This delays the reporting until all files are checked. - * It is needed by checks that analyse the whole code base. */ - bool jointSuppressionReport; - /** @brief --library= */ std::list libraries; @@ -439,6 +434,10 @@ class CPPCHECKLIB Settings { void loadSummaries(); + bool useSingleJob() const { + return jobs == 1; + } + private: static std::string parseEnabled(const std::string &str, std::tuple, SimpleEnableGroup> &groups); std::string applyEnabled(const std::string &str, bool enable); diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 4c77752e4d6..31a7ea88797 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -189,7 +189,7 @@ class TestSuppressions : public TestFixture { if (suppression == "unusedFunction") settings.checks.setEnabled(Checks::unusedFunction, true); settings.severity.enable(Severity::information); - settings.jointSuppressionReport = true; + settings.jobs = 1; if (!suppression.empty()) { std::string r = settings.nomsg.addSuppressionLine(suppression); EXPECT_EQ("", r); @@ -298,7 +298,7 @@ class TestSuppressions : public TestFixture { " a++;\n" "}\n", "uninitvar:test.cpp")); - ASSERT_EQUALS("", errout.str()); + //TODO_ASSERT_EQUALS("", "[test.cpp]: (information) Unmatched suppression: uninitvar\n", errout.str()); // TODO: add assert - gives different result with threads/processes // suppress uninitvar for this file only, without error present @@ -315,7 +315,7 @@ class TestSuppressions : public TestFixture { " a++;\n" "}\n", "*:test.cpp")); - ASSERT_EQUALS("", errout.str()); + //TODO_ASSERT_EQUALS("", "[test.cpp]: (information) Unmatched suppression: *\n", errout.str()); // TODO: add assert - gives different result with threads/processes // suppress all for this file only, without error present @@ -341,7 +341,7 @@ class TestSuppressions : public TestFixture { " b++;\n" "}\n", "uninitvar:test.cpp:3"); - ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: uninitvar\n", errout.str()); + //TODO_ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: uninitvar\n", "", errout.str()); // suppress uninitvar inline ASSERT_EQUALS(0, (this->*check)("void f() {\n" @@ -472,7 +472,7 @@ class TestSuppressions : public TestFixture { " b++;\n" "}\n", ""); - ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: uninitvar\n", errout.str()); + //TODO_ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: uninitvar\n", "", errout.str()); // #5746 - exitcode ASSERT_EQUALS(1U, From 889a7b2980b59e516b7f01c5bbcec7b75bd6535c Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 14:31:46 +0100 Subject: [PATCH 02/12] extracted single job execution into `SingleExecutor` --- Makefile | 12 ++- cli/cli.vcxproj | 2 + cli/cppcheckexecutor.cpp | 47 +---------- cli/singleexecutor.cpp | 85 +++++++++++++++++++ cli/singleexecutor.h | 40 +++++++++ test/testrunner.vcxproj | 3 + test/testsingleexecutor.cpp | 160 ++++++++++++++++++++++++++++++++++++ tools/dmake.cpp | 3 +- 8 files changed, 305 insertions(+), 47 deletions(-) create mode 100644 cli/singleexecutor.cpp create mode 100644 cli/singleexecutor.h create mode 100644 test/testsingleexecutor.cpp diff --git a/Makefile b/Makefile index 7be9edb038c..d9d7ae62f2b 100644 --- a/Makefile +++ b/Makefile @@ -261,6 +261,7 @@ CLIOBJ = cli/cmdlineparser.o \ cli/filelister.o \ cli/main.o \ cli/processexecutor.o \ + cli/singleexecutor.o \ cli/stacktrace.o \ cli/threadexecutor.o @@ -310,6 +311,7 @@ TESTOBJ = test/fixture.o \ test/testsimplifytokens.o \ test/testsimplifytypedef.o \ test/testsimplifyusing.o \ + test/testsingleexecutor.o \ test/testsizeof.o \ test/teststl.o \ test/teststring.o \ @@ -342,7 +344,7 @@ cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ) all: cppcheck testrunner -testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o +testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/singleexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC) test: all @@ -634,7 +636,7 @@ $(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathli cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlineparser.h cli/cppcheckexecutor.h cli/filelister.h 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/timer.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cmdlineparser.cpp -cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlineparser.h cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h cli/cppcheckexecutorsig.h cli/executor.h cli/filelister.h cli/processexecutor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/checkunusedfunctions.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/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h +cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlineparser.h cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h cli/cppcheckexecutorsig.h cli/executor.h cli/filelister.h cli/processexecutor.h cli/singleexecutor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/checkunusedfunctions.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/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cppcheckexecutor.cpp cli/cppcheckexecutorseh.o: cli/cppcheckexecutorseh.cpp cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h lib/utils.h @@ -655,6 +657,9 @@ cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/color.h lib/config.h lib/err cli/processexecutor.o: cli/processexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/processexecutor.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 $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/processexecutor.cpp +cli/singleexecutor.o: cli/singleexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/singleexecutor.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/timer.h lib/utils.h + $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/singleexecutor.cpp + cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/stacktrace.cpp @@ -799,6 +804,9 @@ test/testsimplifytypedef.o: test/testsimplifytypedef.cpp externals/simplecpp/sim test/testsimplifyusing.o: test/testsimplifyusing.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/platform.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/fixture.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testsimplifyusing.cpp +test/testsingleexecutor.o: test/testsingleexecutor.cpp cli/executor.h cli/singleexecutor.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/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h test/redirect.h + $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testsingleexecutor.cpp + test/testsizeof.o: test/testsizeof.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checksizeof.h lib/color.h lib/config.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/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testsizeof.cpp diff --git a/cli/cli.vcxproj b/cli/cli.vcxproj index 35d3f996150..6e642479a7d 100644 --- a/cli/cli.vcxproj +++ b/cli/cli.vcxproj @@ -435,6 +435,7 @@ + @@ -461,6 +462,7 @@ + diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 62e3db8314f..42d2597c980 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -30,6 +30,7 @@ #include "path.h" #include "pathmatch.h" #include "settings.h" +#include "singleexecutor.h" #include "suppressions.h" #include "utils.h" #include "checkunusedfunctions.h" @@ -312,50 +313,8 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) unsigned int returnValue = 0; if (settings.useSingleJob()) { // Single process - const std::size_t totalfilesize = std::accumulate(mFiles.cbegin(), mFiles.cend(), std::size_t(0), [](std::size_t v, const std::pair& f) { - return v + f.second; - }); - - std::size_t processedsize = 0; - unsigned int c = 0; - if (settings.project.fileSettings.empty()) { - for (std::map::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) { - if (!settings.library.markupFile(i->first) - || !settings.library.processMarkupAfterCode(i->first)) { - returnValue += cppcheck.check(i->first); - processedsize += i->second; - if (!settings.quiet) - reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); - c++; - } - } - } else { - // filesettings - // check all files of the project - for (const ImportProject::FileSettings &fs : settings.project.fileSettings) { - returnValue += cppcheck.check(fs); - ++c; - if (!settings.quiet) - reportStatus(c, settings.project.fileSettings.size(), c, settings.project.fileSettings.size()); - if (settings.clangTidy) - cppcheck.analyseClangTidy(fs); - } - } - - // TODO: not performed when multiple jobs are being used - // second loop to parse all markup files which may not work until all - // c/cpp files have been parsed and checked - for (std::map::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) { - if (settings.library.markupFile(i->first) && settings.library.processMarkupAfterCode(i->first)) { - returnValue += cppcheck.check(i->first); - processedsize += i->second; - if (!settings.quiet) - reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); - c++; - } - } - if (cppcheck.analyseWholeProgram()) - returnValue++; + SingleExecutor executor(cppcheck, mFiles, settings, *this); + returnValue = executor.check(); } else { #if defined(THREADING_MODEL_THREAD) ThreadExecutor executor(mFiles, settings, *this); diff --git a/cli/singleexecutor.cpp b/cli/singleexecutor.cpp new file mode 100644 index 00000000000..24bee7325b6 --- /dev/null +++ b/cli/singleexecutor.cpp @@ -0,0 +1,85 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2023 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "singleexecutor.h" + +#include "cppcheck.h" +#include "cppcheckexecutor.h" +#include "settings.h" + +#include + +SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::map &files, Settings &settings, ErrorLogger &errorLogger) + : Executor(files, settings, errorLogger) + , mCppcheck(cppcheck) +{} + +SingleExecutor::~SingleExecutor() +{} + +// TODO: markup handling is not performed with multiple jobs +unsigned int SingleExecutor::check() +{ + unsigned int result = 0; + + const std::size_t totalfilesize = std::accumulate(mFiles.cbegin(), mFiles.cend(), std::size_t(0), [](std::size_t v, const std::pair& f) { + return v + f.second; + }); + + std::size_t processedsize = 0; + unsigned int c = 0; + if (mSettings.project.fileSettings.empty()) { + for (std::map::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) { + if (!mSettings.library.markupFile(i->first) + || !mSettings.library.processMarkupAfterCode(i->first)) { + result += mCppcheck.check(i->first); + processedsize += i->second; + if (!mSettings.quiet) + CppCheckExecutor::reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); + c++; + } + } + } else { + // filesettings + // check all files of the project + for (const ImportProject::FileSettings &fs : mSettings.project.fileSettings) { + result += mCppcheck.check(fs); + ++c; + if (!mSettings.quiet) + CppCheckExecutor::reportStatus(c, mSettings.project.fileSettings.size(), c, mSettings.project.fileSettings.size()); + if (mSettings.clangTidy) + mCppcheck.analyseClangTidy(fs); + } + } + + // second loop to parse all markup files which may not work until all + // c/cpp files have been parsed and checked + for (std::map::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) { + if (mSettings.library.markupFile(i->first) && mSettings.library.processMarkupAfterCode(i->first)) { + result += mCppcheck.check(i->first); + processedsize += i->second; + if (!mSettings.quiet) + CppCheckExecutor::reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); + c++; + } + } + if (mCppcheck.analyseWholeProgram()) + result++; + + return result; +} diff --git a/cli/singleexecutor.h b/cli/singleexecutor.h new file mode 100644 index 00000000000..77478abe881 --- /dev/null +++ b/cli/singleexecutor.h @@ -0,0 +1,40 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2023 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef SINGLEEXECUTOR_H +#define SINGLEEXECUTOR_H + +#include "executor.h" + +class CppCheck; + +class SingleExecutor : public Executor +{ +public: + SingleExecutor(CppCheck &cppcheck, const std::map &files, Settings &settings, ErrorLogger &errorLogger); + SingleExecutor(const SingleExecutor &) = delete; + ~SingleExecutor() override; + void operator=(const SingleExecutor &) = delete; + + unsigned int check() override; + +private: + CppCheck &mCppcheck; +}; + +#endif // SINGLEEXECUTOR_H diff --git a/test/testrunner.vcxproj b/test/testrunner.vcxproj index 3ed1f7bec5c..0fe86b54ea1 100755 --- a/test/testrunner.vcxproj +++ b/test/testrunner.vcxproj @@ -31,6 +31,7 @@ + @@ -84,6 +85,7 @@ + @@ -114,6 +116,7 @@ + diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp new file mode 100644 index 00000000000..29da0bc5614 --- /dev/null +++ b/test/testsingleexecutor.cpp @@ -0,0 +1,160 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2023 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "cppcheck.h" +#include "errorlogger.h" +#include "fixture.h" +#include "helpers.h" +#include "redirect.h" +#include "settings.h" +#include "singleexecutor.h" +#include "timer.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +class TestSingleExecutor : public TestFixture { +public: + TestSingleExecutor() : TestFixture("TestSingleExecutor") {} + +private: + Settings settings; + + void check(int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr) { + errout.str(""); + output.str(""); + + std::map filemap; + for (int i = 1; i <= files; ++i) { + std::ostringstream oss; + oss << "file_" << i << ".cpp"; + filemap[oss.str()] = data.size(); + } + + settings.showtime = showtime; + if (plistOutput) + settings.plistOutput = plistOutput; + CppCheck cppcheck(*this, true, [](std::string,std::vector,std::string,std::string&){ + return false; + }); + cppcheck.settings() = settings; + // TODO: test with settings.project.fileSettings; + SingleExecutor executor(cppcheck, filemap, settings, *this); + std::vector> scopedfiles; + scopedfiles.reserve(filemap.size()); + for (std::map::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i) + scopedfiles.emplace_back(new ScopedFile(i->first, data)); + + ASSERT_EQUALS(result, executor.check()); + } + + void run() override { + LOAD_LIB_2(settings.library, "std.cfg"); + + TEST_CASE(many_files); + TEST_CASE(many_files_showtime); + TEST_CASE(many_files_plist); + TEST_CASE(no_errors_more_files); + TEST_CASE(no_errors_less_files); + TEST_CASE(no_errors_equal_amount_files); + TEST_CASE(one_error_less_files); + TEST_CASE(one_error_several_files); + } + + void many_files() { + check(100, 100, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}"); + } + + void many_files_showtime() { + SUPPRESS; + check( 100, 100, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}", SHOWTIME_MODES::SHOWTIME_SUMMARY); + } + + void many_files_plist() { + const char plistOutput[] = "plist"; + ScopedFile plistFile("dummy", plistOutput); + + SUPPRESS; + check(100, 100, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}", SHOWTIME_MODES::SHOWTIME_NONE, plistOutput); + } + + void no_errors_more_files() { + check(3, 0, + "int main()\n" + "{\n" + " return 0;\n" + "}"); + } + + void no_errors_less_files() { + check(1, 0, + "int main()\n" + "{\n" + " return 0;\n" + "}"); + } + + void no_errors_equal_amount_files() { + check(2, 0, + "int main()\n" + "{\n" + " return 0;\n" + "}"); + } + + void one_error_less_files() { + check(1, 1, + "int main()\n" + "{\n" + " {char *a = malloc(10);}\n" + " return 0;\n" + "}"); + } + + void one_error_several_files() { + check(20, 20, + "int main()\n" + "{\n" + " {char *a = malloc(10);}\n" + " return 0;\n" + "}"); + } +}; + +REGISTER_TEST(TestSingleExecutor) diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 5c6e66bc20f..3bf3813254c 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -659,7 +659,8 @@ int main(int argc, char **argv) fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n"; fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n"; fout << "all:\tcppcheck testrunner\n\n"; - fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o\n"; + // TODO: generate from clifiles + fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/singleexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o\n"; fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n"; fout << "test:\tall\n"; fout << "\t./testrunner\n\n"; From 15b25f5ee13dc7812c86b5ea4d1128b22f44abb7 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 14:57:17 +0100 Subject: [PATCH 03/12] =?UTF-8?q?moved=20`reportStatus()`=20from=20`CppChe?= =?UTF-8?q?ckExecutor`=20to=20=C3=88xecutor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/cppcheckexecutor.cpp | 13 ------------- cli/cppcheckexecutor.h | 10 ---------- cli/executor.cpp | 16 ++++++++++++++++ cli/executor.h | 10 ++++++++++ cli/processexecutor.cpp | 2 +- cli/singleexecutor.cpp | 6 +++--- cli/threadexecutor.cpp | 2 +- lib/cppcheck.cpp | 3 --- lib/cppcheck.h | 2 -- 9 files changed, 31 insertions(+), 33 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 42d2597c980..d811ca6327f 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -407,19 +407,6 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st } } -void CppCheckExecutor::reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal) -{ - if (filecount > 1) { - std::ostringstream oss; - const long percentDone = (sizetotal > 0) ? static_cast(static_cast(sizedone) / sizetotal * 100) : 0; - oss << fileindex << '/' << filecount - << " files checked " << percentDone - << "% done"; - // TODO: do not unconditionally print in color - std::cout << Color::FgBlue << oss.str() << Color::Reset << std::endl; - } -} - void CppCheckExecutor::reportErr(const ErrorMessage &msg) { if (mShowAllErrors) { diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 4576d8d4f23..a70a79ff779 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -81,16 +81,6 @@ class CppCheckExecutor : public ErrorLogger { void reportProgress(const std::string &filename, const char stage[], const std::size_t value) override; - /** - * Information about how many files have been checked - * - * @param fileindex This many files have been checked. - * @param filecount This many files there are in total. - * @param sizedone The sum of sizes of the files checked. - * @param sizetotal The total sizes of the files. - */ - static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal); - /** * @param exceptionOutput Output file */ diff --git a/cli/executor.cpp b/cli/executor.cpp index 66375be3f4a..e328a6883bc 100644 --- a/cli/executor.cpp +++ b/cli/executor.cpp @@ -18,11 +18,14 @@ #include "executor.h" +#include "color.h" #include "errorlogger.h" #include "settings.h" #include "suppressions.h" #include +#include +#include #include Executor::Executor(const std::map &files, Settings &settings, ErrorLogger &errorLogger) @@ -47,3 +50,16 @@ bool Executor::hasToLog(const ErrorMessage &msg) return false; } +void Executor::reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal) +{ + if (filecount > 1) { + std::ostringstream oss; + const long percentDone = (sizetotal > 0) ? static_cast(static_cast(sizedone) / sizetotal * 100) : 0; + oss << fileindex << '/' << filecount + << " files checked " << percentDone + << "% done"; + // TODO: do not unconditionally print in color + std::cout << Color::FgBlue << oss.str() << Color::Reset << std::endl; + } +} + diff --git a/cli/executor.h b/cli/executor.h index 3a0a6ec6200..185d3da3a41 100644 --- a/cli/executor.h +++ b/cli/executor.h @@ -46,6 +46,16 @@ class Executor { virtual unsigned int check() = 0; + /** + * Information about how many files have been checked + * + * @param fileindex This many files have been checked. + * @param filecount This many files there are in total. + * @param sizedone The sum of sizes of the files checked. + * @param sizetotal The total sizes of the files. + */ + static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal); + protected: /** * @brief Check if message is being suppressed and unique. diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 994d5f8550b..3d213170d4e 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -328,7 +328,7 @@ unsigned int ProcessExecutor::check() fileCount++; processedsize += size; if (!mSettings.quiet) - CppCheckExecutor::reportStatus(fileCount, mFiles.size() + mSettings.project.fileSettings.size(), processedsize, totalfilesize); + Executor::reportStatus(fileCount, mFiles.size() + mSettings.project.fileSettings.size(), processedsize, totalfilesize); close(*rp); rp = rpipes.erase(rp); diff --git a/cli/singleexecutor.cpp b/cli/singleexecutor.cpp index 24bee7325b6..d7c6f140e15 100644 --- a/cli/singleexecutor.cpp +++ b/cli/singleexecutor.cpp @@ -50,7 +50,7 @@ unsigned int SingleExecutor::check() result += mCppcheck.check(i->first); processedsize += i->second; if (!mSettings.quiet) - CppCheckExecutor::reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); + reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); c++; } } @@ -61,7 +61,7 @@ unsigned int SingleExecutor::check() result += mCppcheck.check(fs); ++c; if (!mSettings.quiet) - CppCheckExecutor::reportStatus(c, mSettings.project.fileSettings.size(), c, mSettings.project.fileSettings.size()); + reportStatus(c, mSettings.project.fileSettings.size(), c, mSettings.project.fileSettings.size()); if (mSettings.clangTidy) mCppcheck.analyseClangTidy(fs); } @@ -74,7 +74,7 @@ unsigned int SingleExecutor::check() result += mCppcheck.check(i->first); processedsize += i->second; if (!mSettings.quiet) - CppCheckExecutor::reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); + reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); c++; } } diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index fbcf03d3bf5..066f1529cde 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -69,7 +69,7 @@ class SyncLogForwarder : public ErrorLogger void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal) { std::lock_guard lg(mReportSync); - CppCheckExecutor::reportStatus(fileindex, filecount, sizedone, sizetotal); + Executor::reportStatus(fileindex, filecount, sizedone, sizetotal); } private: diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 6f8c9a54f5b..ec44c4a1d26 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1652,9 +1652,6 @@ void CppCheck::reportProgress(const std::string &filename, const char stage[], c mErrorLogger.reportProgress(filename, stage, value); } -void CppCheck::reportStatus(unsigned int /*fileindex*/, unsigned int /*filecount*/, std::size_t /*sizedone*/, std::size_t /*sizetotal*/) -{} - void CppCheck::getErrorMessages() { Settings s(mSettings); diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 07469b8aeaf..db5ba0893c7 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -112,8 +112,6 @@ class CPPCHECKLIB CppCheck : ErrorLogger { */ static const char * extraVersion(); - virtual void reportStatus(unsigned int fileindex, unsigned int filecount, std::size_t sizedone, std::size_t sizetotal); - /** * @brief Call all "getErrorMessages" in all registered Check classes. * Also print out XML header and footer. From 7f5187a071f49dfc4cf8d8dc9506dd7d1351ad93 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 15:38:30 +0100 Subject: [PATCH 04/12] TestSingleExecutor: improved tests --- test/testsingleexecutor.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 29da0bc5614..ee6dbee06b5 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -83,12 +83,27 @@ class TestSingleExecutor : public TestFixture { } void many_files() { + REDIRECT; check(100, 100, "int main()\n" "{\n" " char *a = malloc(10);\n" " return 0;\n" "}"); + std::string expected; + for (int i = 1; i <= 100; ++i) { + int p; + if (i == 29) + p = 28; + else if (i == 57) + p = 56; + else if (i == 58) + p = 57; + else + p = i; + expected += "\x1b[34m" + std::to_string(i) + "/100 files checked " + std::to_string(p) + "% done\x1b[0m\n"; + } + ASSERT_EQUALS(expected, GET_REDIRECT_OUTPUT); } void many_files_showtime() { From 85cd134225536c7a33a3b4dffadc6a936b29cf7f Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 16:24:38 +0100 Subject: [PATCH 05/12] added testing of markup extension handling in executors --- lib/library.h | 4 +++ test/testprocessexecutor.cpp | 48 ++++++++++++++++++++++++++++++++---- test/testsingleexecutor.cpp | 45 +++++++++++++++++++++++++++++---- test/testthreadexecutor.cpp | 47 +++++++++++++++++++++++++++++++---- 4 files changed, 129 insertions(+), 15 deletions(-) diff --git a/lib/library.h b/lib/library.h index 501fe1aade7..325077876c7 100644 --- a/lib/library.h +++ b/lib/library.h @@ -51,7 +51,11 @@ namespace tinyxml2 { * @brief Library definitions handling */ class CPPCHECKLIB Library { + // TODO: get rid of this friend class TestSymbolDatabase; // For testing only + friend class TestSingleExecutor; // For testing only + friend class TestThreadExecutor; // For testing only + friend class TestProcessExecutor; // For testing only public: Library(); diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index de24a3aa0a3..09a1888abaf 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -43,15 +43,23 @@ class TestProcessExecutor : public TestFixture { * Execute check using n jobs for y files which are have * identical data, given within data. */ - void check(unsigned int jobs, int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr) { + void check(unsigned int jobs, int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr, const std::vector& filesList = {}) { errout.str(""); output.str(""); std::map filemap; - for (int i = 1; i <= files; ++i) { - std::ostringstream oss; - oss << "file_" << i << ".cpp"; - filemap[oss.str()] = data.size(); + if (filesList.empty()) { + for (int i = 1; i <= files; ++i) { + std::ostringstream oss; + oss << "file_" << i << ".cpp"; + filemap[oss.str()] = data.size(); + } + } + else { + for (const auto& f : filesList) + { + filemap[f] = data.size(); + } } settings.jobs = jobs; @@ -81,6 +89,7 @@ class TestProcessExecutor : public TestFixture { TEST_CASE(no_errors_equal_amount_files); TEST_CASE(one_error_less_files); TEST_CASE(one_error_several_files); + TEST_CASE(markup); #endif // !WIN32 } @@ -170,6 +179,35 @@ class TestProcessExecutor : public TestFixture { " return 0;\n" "}"); } + + + void markup() { + const Settings settingsOld = settings; + settings.library.mMarkupExtensions.emplace(".cp1"); + settings.library.mProcessAfterCode.emplace(".cp1", true); + + const std::vector files = { + "file_1.cp1", "file_2.cpp", "file_3.cp1", "file_4.cpp" + }; + + SUPPRESS; + check(2, 4, 4, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}", + SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files); + TODO_ASSERT_EQUALS("\x1b[32mChecking file_2.cpp ...\x1b[0m\n" + "\x1b[32mChecking file_4.cpp ...\x1b[0m\n" + "\x1b[32mChecking file_1.cp1 ...\x1b[0m\n" + "\x1b[32mChecking file_3.cp1 ...\x1b[0m\n", + "\x1b[32mChecking file_1.cp1 ...\x1b[0m\n" + "\x1b[32mChecking file_2.cpp ...\x1b[0m\n" + "\x1b[32mChecking file_3.cp1 ...\x1b[0m\n" + "\x1b[32mChecking file_4.cpp ...\x1b[0m\n", + output.str()); + } }; REGISTER_TEST(TestProcessExecutor) diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index ee6dbee06b5..382dadd057b 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -41,15 +41,23 @@ class TestSingleExecutor : public TestFixture { private: Settings settings; - void check(int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr) { + void check(int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr, const std::vector& filesList = {}) { errout.str(""); output.str(""); std::map filemap; - for (int i = 1; i <= files; ++i) { - std::ostringstream oss; - oss << "file_" << i << ".cpp"; - filemap[oss.str()] = data.size(); + if (filesList.empty()) { + for (int i = 1; i <= files; ++i) { + std::ostringstream oss; + oss << "file_" << i << ".cpp"; + filemap[oss.str()] = data.size(); + } + } + else { + for (const auto& f : filesList) + { + filemap[f] = data.size(); + } } settings.showtime = showtime; @@ -80,6 +88,7 @@ class TestSingleExecutor : public TestFixture { TEST_CASE(no_errors_equal_amount_files); TEST_CASE(one_error_less_files); TEST_CASE(one_error_several_files); + TEST_CASE(markup); } void many_files() { @@ -170,6 +179,32 @@ class TestSingleExecutor : public TestFixture { " return 0;\n" "}"); } + + void markup() { + const Settings settingsOld = settings; + settings.library.mMarkupExtensions.emplace(".cp1"); + settings.library.mProcessAfterCode.emplace(".cp1", true); + + const std::vector files = { + "file_1.cp1", "file_2.cpp", "file_3.cp1", "file_4.cpp" + }; + + SUPPRESS; + check(4, 4, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}", + SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files); + ASSERT_EQUALS("Checking file_2.cpp ...\n" + "Checking file_4.cpp ...\n" + "Checking file_1.cp1 ...\n" + "Checking file_3.cp1 ...\n", output.str()); + } + + // TODO: test clang-tidy + // TODO: test whole program analysis }; REGISTER_TEST(TestSingleExecutor) diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 2e117181ac9..4d500597695 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -43,15 +43,23 @@ class TestThreadExecutor : public TestFixture { * Execute check using n jobs for y files which are have * identical data, given within data. */ - void check(unsigned int jobs, int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr) { + void check(unsigned int jobs, int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr, const std::vector& filesList = {}) { errout.str(""); output.str(""); std::map filemap; - for (int i = 1; i <= files; ++i) { - std::ostringstream oss; - oss << "file_" << i << ".cpp"; - filemap[oss.str()] = data.size(); + if (filesList.empty()) { + for (int i = 1; i <= files; ++i) { + std::ostringstream oss; + oss << "file_" << i << ".cpp"; + filemap[oss.str()] = data.size(); + } + } + else { + for (const auto& f : filesList) + { + filemap[f] = data.size(); + } } settings.jobs = jobs; @@ -80,6 +88,7 @@ class TestThreadExecutor : public TestFixture { TEST_CASE(no_errors_equal_amount_files); TEST_CASE(one_error_less_files); TEST_CASE(one_error_several_files); + TEST_CASE(markup); } void deadlock_with_many_errors() { @@ -168,6 +177,34 @@ class TestThreadExecutor : public TestFixture { " return 0;\n" "}"); } + + void markup() { + const Settings settingsOld = settings; + settings.library.mMarkupExtensions.emplace(".cp1"); + settings.library.mProcessAfterCode.emplace(".cp1", true); + + const std::vector files = { + "file_1.cp1", "file_2.cpp", "file_3.cp1", "file_4.cpp" + }; + + SUPPRESS; + check(2, 4, 4, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}", + SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files); + TODO_ASSERT_EQUALS("Checking file_2.cpp ...\n" + "Checking file_4.cpp ...\n" + "Checking file_1.cp1 ...\n" + "Checking file_3.cp1 ...\n", + "Checking file_1.cp1 ...\n" + "Checking file_2.cpp ...\n" + "Checking file_3.cp1 ...\n" + "Checking file_4.cpp ...\n", + output.str()); + } }; REGISTER_TEST(TestThreadExecutor) From 1cc8473041ba531694bf15357b86ea181f8becb5 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 17:23:10 +0100 Subject: [PATCH 06/12] cleaned up includes based on `include-what-you-use` --- Makefile | 2 +- cli/cppcheckexecutor.cpp | 2 +- cli/executor.cpp | 2 +- cli/singleexecutor.cpp | 7 ++++++- cli/singleexecutor.h | 6 ++++++ test/testprocessexecutor.cpp | 2 ++ test/testsingleexecutor.cpp | 4 +++- test/testthreadexecutor.cpp | 2 ++ 8 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d9d7ae62f2b..3a38a5da56b 100644 --- a/Makefile +++ b/Makefile @@ -657,7 +657,7 @@ cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/color.h lib/config.h lib/err cli/processexecutor.o: cli/processexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/processexecutor.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 $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/processexecutor.cpp -cli/singleexecutor.o: cli/singleexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/singleexecutor.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/timer.h lib/utils.h +cli/singleexecutor.o: cli/singleexecutor.cpp cli/executor.h cli/singleexecutor.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/timer.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/singleexecutor.cpp cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index d811ca6327f..791bfd97c45 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -33,6 +33,7 @@ #include "singleexecutor.h" #include "suppressions.h" #include "utils.h" + #include "checkunusedfunctions.h" #if defined(THREADING_MODEL_THREAD) @@ -52,7 +53,6 @@ #include // IWYU pragma: keep #include #include -#include #ifdef USE_UNIX_SIGNAL_HANDLING #include "cppcheckexecutorsig.h" diff --git a/cli/executor.cpp b/cli/executor.cpp index e328a6883bc..62332d37940 100644 --- a/cli/executor.cpp +++ b/cli/executor.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include // IWYU pragma: keep #include Executor::Executor(const std::map &files, Settings &settings, ErrorLogger &errorLogger) diff --git a/cli/singleexecutor.cpp b/cli/singleexecutor.cpp index d7c6f140e15..228bf488b4d 100644 --- a/cli/singleexecutor.cpp +++ b/cli/singleexecutor.cpp @@ -19,10 +19,15 @@ #include "singleexecutor.h" #include "cppcheck.h" -#include "cppcheckexecutor.h" +#include "importproject.h" +#include "library.h" #include "settings.h" +#include #include +#include + +class ErrorLogger; SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::map &files, Settings &settings, ErrorLogger &errorLogger) : Executor(files, settings, errorLogger) diff --git a/cli/singleexecutor.h b/cli/singleexecutor.h index 77478abe881..74143be7c00 100644 --- a/cli/singleexecutor.h +++ b/cli/singleexecutor.h @@ -21,6 +21,12 @@ #include "executor.h" +#include +#include +#include + +class ErrorLogger; +class Settings; class CppCheck; class SingleExecutor : public Executor diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index 09a1888abaf..cd8d2437875 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -22,11 +22,13 @@ #include "fixture.h" #include "helpers.h" #include "timer.h" +#include "library.h" #include #include #include #include +#include #include #include #include diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 382dadd057b..c0aaf77dd64 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -17,18 +17,20 @@ */ #include "cppcheck.h" -#include "errorlogger.h" #include "fixture.h" #include "helpers.h" #include "redirect.h" +#include "library.h" #include "settings.h" #include "singleexecutor.h" #include "timer.h" #include #include +#include #include #include +#include #include #include #include diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 4d500597695..b293f183fd4 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -20,6 +20,7 @@ #include "settings.h" #include "fixture.h" #include "helpers.h" +#include "library.h" #include "threadexecutor.h" #include "timer.h" @@ -27,6 +28,7 @@ #include #include #include +#include #include #include #include From ac0a1fafb2a87a7ea23ca8e899ff25aacffc5eb7 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 18:39:18 +0100 Subject: [PATCH 07/12] testsingleexecutor.cpp: suppress `performance-unnecessary-value-param` clang-tidy warnings --- test/testsingleexecutor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index c0aaf77dd64..4b35ab78862 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -65,6 +65,7 @@ class TestSingleExecutor : public TestFixture { settings.showtime = showtime; if (plistOutput) settings.plistOutput = plistOutput; + // NOLINTNEXTLINE(performance-unnecessary-value-param) CppCheck cppcheck(*this, true, [](std::string,std::vector,std::string,std::string&){ return false; }); From 66066879ca4726c8c4334b08b4bd4490179c72d6 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 19:12:41 +0100 Subject: [PATCH 08/12] ProcessExecutor: send color via pipe instead of applying it beforehand --- cli/processexecutor.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 3d213170d4e..e3ed729b1cc 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -73,8 +73,7 @@ class PipeWriter : public ErrorLogger { explicit PipeWriter(int pipe) : mWpipe(pipe) {} void reportOut(const std::string &outmsg, Color c) override { - // TODO: do not unconditionally apply colors - writeToPipe(REPORT_OUT, ::toString(c) + outmsg + ::toString(Color::Reset)); + writeToPipe(REPORT_OUT, static_cast(c) + outmsg); } void reportErr(const ErrorMessage &msg) override { @@ -178,7 +177,9 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str bool res = true; if (type == PipeWriter::REPORT_OUT) { - mErrorLogger.reportOut(buf); + // the first charcater is the color + const Color c = static_cast(buf[0]); + mErrorLogger.reportOut(buf + 1, c); } else if (type == PipeWriter::REPORT_ERROR) { ErrorMessage msg; try { From c94e870b23d504c1e21e219dec858acdf8844564 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 20:03:06 +0100 Subject: [PATCH 09/12] do not unconditionally apply colors to output / disable all colors in tests / adjusted tests for changed output behavior --- cli/cppcheckexecutor.cpp | 6 +++-- cli/executor.cpp | 3 +-- cli/executor.h | 2 +- cli/threadexecutor.cpp | 2 +- lib/color.cpp | 7 ++++-- lib/color.h | 4 ++- test/main.cpp | 2 ++ test/testprocessexecutor.cpp | 30 ++++++++++++++-------- test/testsingleexecutor.cpp | 49 ++++++++++++++++++++++++------------ test/testthreadexecutor.cpp | 20 ++++++++++----- 10 files changed, 83 insertions(+), 42 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 791bfd97c45..6cb61004bfa 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -380,8 +380,10 @@ void CppCheckExecutor::reportErr(const std::string &errmsg) void CppCheckExecutor::reportOut(const std::string &outmsg, Color c) { - // TODO: do not unconditionally apply colors - std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl; + if (c == Color::Reset) + std::cout << ansiToOEM(outmsg, true) << std::endl; + else + std::cout << toString(c) << ansiToOEM(outmsg, true) << toString(Color::Reset) << std::endl; } void CppCheckExecutor::reportProgress(const std::string &filename, const char stage[], const std::size_t value) diff --git a/cli/executor.cpp b/cli/executor.cpp index 62332d37940..fddb90586d3 100644 --- a/cli/executor.cpp +++ b/cli/executor.cpp @@ -58,8 +58,7 @@ void Executor::reportStatus(std::size_t fileindex, std::size_t filecount, std::s oss << fileindex << '/' << filecount << " files checked " << percentDone << "% done"; - // TODO: do not unconditionally print in color - std::cout << Color::FgBlue << oss.str() << Color::Reset << std::endl; + mErrorLogger.reportOut(oss.str(), Color::FgBlue); } } diff --git a/cli/executor.h b/cli/executor.h index 185d3da3a41..efb4a9559d2 100644 --- a/cli/executor.h +++ b/cli/executor.h @@ -54,7 +54,7 @@ class Executor { * @param sizedone The sum of sizes of the files checked. * @param sizetotal The total sizes of the files. */ - static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal); + void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal); protected: /** diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 066f1529cde..51aabf1b00a 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -69,7 +69,7 @@ class SyncLogForwarder : public ErrorLogger void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal) { std::lock_guard lg(mReportSync); - Executor::reportStatus(fileindex, filecount, sizedone, sizetotal); + mThreadExecutor.reportStatus(fileindex, filecount, sizedone, sizetotal); } private: diff --git a/lib/color.cpp b/lib/color.cpp index fa5099a2589..d9e58784d28 100644 --- a/lib/color.cpp +++ b/lib/color.cpp @@ -24,14 +24,17 @@ #include #include // IWYU pragma: keep +bool DISABLE_COLORS = false; + #ifdef _WIN32 std::ostream& operator<<(std::ostream& os, const Color& /*c*/) { #else std::ostream& operator<<(std::ostream & os, const Color& c) { - static const bool use_color = isatty(STDOUT_FILENO); - if (use_color) + // TODO: handle piping into file as well as other pipes like stderr + static const bool s_is_tty = isatty(STDOUT_FILENO); + if (!DISABLE_COLORS && s_is_tty) return os << "\033[" << static_cast(c) << "m"; #endif return os; diff --git a/lib/color.h b/lib/color.h index e2e46953306..9569a206c9f 100644 --- a/lib/color.h +++ b/lib/color.h @@ -40,6 +40,8 @@ enum class Color { }; CPPCHECKLIB std::ostream& operator<<(std::ostream& os, const Color& c); -std::string toString(const Color& c); +CPPCHECKLIB std::string toString(const Color& c); + +extern CPPCHECKLIB bool DISABLE_COLORS; // for testing #endif diff --git a/test/main.cpp b/test/main.cpp index 5ae9b52abc6..fadf8c82605 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include "color.h" #include "options.h" #include "preprocessor.h" #include "fixture.h" @@ -30,6 +31,7 @@ int main(int argc, char *argv[]) #endif Preprocessor::macroChar = '$'; // While macroChar is char(1) per default outside test suite, we require it to be a human-readable character here. + DISABLE_COLORS = true; options args(argc, argv); diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index cd8d2437875..17f0a3e7fba 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -131,7 +131,6 @@ class TestProcessExecutor : public TestFixture { const char plistOutput[] = "plist"; ScopedFile plistFile("dummy", plistOutput); - SUPPRESS; check(16, 100, 100, "int main()\n" "{\n" @@ -192,7 +191,6 @@ class TestProcessExecutor : public TestFixture { "file_1.cp1", "file_2.cpp", "file_3.cp1", "file_4.cpp" }; - SUPPRESS; check(2, 4, 4, "int main()\n" "{\n" @@ -200,15 +198,25 @@ class TestProcessExecutor : public TestFixture { " return 0;\n" "}", SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files); - TODO_ASSERT_EQUALS("\x1b[32mChecking file_2.cpp ...\x1b[0m\n" - "\x1b[32mChecking file_4.cpp ...\x1b[0m\n" - "\x1b[32mChecking file_1.cp1 ...\x1b[0m\n" - "\x1b[32mChecking file_3.cp1 ...\x1b[0m\n", - "\x1b[32mChecking file_1.cp1 ...\x1b[0m\n" - "\x1b[32mChecking file_2.cpp ...\x1b[0m\n" - "\x1b[32mChecking file_3.cp1 ...\x1b[0m\n" - "\x1b[32mChecking file_4.cpp ...\x1b[0m\n", - output.str()); + // TODO: order of "Checking" and "checked" is affected by thread + /*TODO_ASSERT_EQUALS("Checking file_2.cpp ...\n" + "1/4 files checked 25% done\n" + "Checking file_4.cpp ...\n" + "2/4 files checked 50% done\n" + "Checking file_1.cp1 ...\n" + "3/4 files checked 75% done\n" + "Checking file_3.cp1 ...\n" + "4/4 files checked 100% done\n", + "Checking file_1.cp1 ...\n" + "1/4 files checked 25% done\n" + "Checking file_2.cpp ...\n" + "2/4 files checked 50% done\n" + "Checking file_3.cp1 ...\n" + "3/4 files checked 75% done\n" + "Checking file_4.cpp ...\n" + "4/4 files checked 100% done\n", + output.str());*/ + settings = settingsOld; } }; diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 4b35ab78862..ec2cadd6900 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -10,7 +10,7 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Public License for more details * * You should have received a copy of the GNU General Public License * along with this program. If not, see . @@ -43,6 +43,15 @@ class TestSingleExecutor : public TestFixture { private: Settings settings; + static std::string zpad3(int i) + { + if (i < 10) + return "00" + std::to_string(i); + if (i < 100) + return "0" + std::to_string(i); + return std::to_string(i); + } + void check(int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr, const std::vector& filesList = {}) { errout.str(""); output.str(""); @@ -50,9 +59,8 @@ class TestSingleExecutor : public TestFixture { std::map filemap; if (filesList.empty()) { for (int i = 1; i <= files; ++i) { - std::ostringstream oss; - oss << "file_" << i << ".cpp"; - filemap[oss.str()] = data.size(); + const std::string s = "file_" + zpad3(i) + ".cpp"; + filemap[s] = data.size(); } } else { @@ -95,7 +103,9 @@ class TestSingleExecutor : public TestFixture { } void many_files() { - REDIRECT; + const Settings settingsOld = settings; + settings.quiet = false; + check(100, 100, "int main()\n" "{\n" @@ -104,6 +114,7 @@ class TestSingleExecutor : public TestFixture { "}"); std::string expected; for (int i = 1; i <= 100; ++i) { + expected += "Checking file_" + zpad3(i) + ".cpp ...\n"; int p; if (i == 29) p = 28; @@ -113,26 +124,27 @@ class TestSingleExecutor : public TestFixture { p = 57; else p = i; - expected += "\x1b[34m" + std::to_string(i) + "/100 files checked " + std::to_string(p) + "% done\x1b[0m\n"; + expected += std::to_string(i) + "/100 files checked " + std::to_string(p) + "% done\n"; } - ASSERT_EQUALS(expected, GET_REDIRECT_OUTPUT); + ASSERT_EQUALS(expected, output.str()); + + settings = settingsOld; } void many_files_showtime() { SUPPRESS; - check( 100, 100, - "int main()\n" - "{\n" - " char *a = malloc(10);\n" - " return 0;\n" - "}", SHOWTIME_MODES::SHOWTIME_SUMMARY); + check(100, 100, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}", SHOWTIME_MODES::SHOWTIME_SUMMARY); } void many_files_plist() { const char plistOutput[] = "plist"; ScopedFile plistFile("dummy", plistOutput); - SUPPRESS; check(100, 100, "int main()\n" "{\n" @@ -192,7 +204,6 @@ class TestSingleExecutor : public TestFixture { "file_1.cp1", "file_2.cpp", "file_3.cp1", "file_4.cpp" }; - SUPPRESS; check(4, 4, "int main()\n" "{\n" @@ -200,10 +211,16 @@ class TestSingleExecutor : public TestFixture { " return 0;\n" "}", SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files); + // TODO: filter out the "files checked" messages ASSERT_EQUALS("Checking file_2.cpp ...\n" + "1/4 files checked 25% done\n" "Checking file_4.cpp ...\n" + "2/4 files checked 50% done\n" "Checking file_1.cp1 ...\n" - "Checking file_3.cp1 ...\n", output.str()); + "3/4 files checked 75% done\n" + "Checking file_3.cp1 ...\n" + "4/4 files checked 100% done\n", output.str()); + settings = settingsOld; } // TODO: test clang-tidy diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index b293f183fd4..1a3ae87e8fc 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -129,7 +129,6 @@ class TestThreadExecutor : public TestFixture { const char plistOutput[] = "plist"; ScopedFile plistFile("dummy", plistOutput); - SUPPRESS; check(16, 100, 100, "int main()\n" "{\n" @@ -189,7 +188,6 @@ class TestThreadExecutor : public TestFixture { "file_1.cp1", "file_2.cpp", "file_3.cp1", "file_4.cpp" }; - SUPPRESS; check(2, 4, 4, "int main()\n" "{\n" @@ -197,15 +195,25 @@ class TestThreadExecutor : public TestFixture { " return 0;\n" "}", SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files); - TODO_ASSERT_EQUALS("Checking file_2.cpp ...\n" + // TODO: order of "Checking" and "checked" is affected by thread + /*TODO_ASSERT_EQUALS("Checking file_2.cpp ...\n" + "1/4 files checked 25% done\n" "Checking file_4.cpp ...\n" + "2/4 files checked 50% done\n" "Checking file_1.cp1 ...\n" - "Checking file_3.cp1 ...\n", + "3/4 files checked 75% done\n" + "Checking file_3.cp1 ...\n" + "4/4 files checked 100% done\n", "Checking file_1.cp1 ...\n" + "1/4 files checked 25% done\n" "Checking file_2.cpp ...\n" + "2/4 files checked 50% done\n" "Checking file_3.cp1 ...\n" - "Checking file_4.cpp ...\n", - output.str()); + "3/4 files checked 75% done\n" + "Checking file_4.cpp ...\n" + "4/4 files checked 100% done\n", + output.str());*/ + settings = settingsOld; } }; From 1c44bd6312656b4a879787bd3912a5e91615a8c4 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 22:11:14 +0100 Subject: [PATCH 10/12] fixed precision loss in `Executor::reportStatus()` --- cli/executor.cpp | 2 +- test/testsingleexecutor.cpp | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/cli/executor.cpp b/cli/executor.cpp index fddb90586d3..8be6b30b697 100644 --- a/cli/executor.cpp +++ b/cli/executor.cpp @@ -54,7 +54,7 @@ void Executor::reportStatus(std::size_t fileindex, std::size_t filecount, std::s { if (filecount > 1) { std::ostringstream oss; - const long percentDone = (sizetotal > 0) ? static_cast(static_cast(sizedone) / sizetotal * 100) : 0; + const unsigned long percentDone = (sizetotal > 0) ? (100 * sizedone) / sizetotal : 0; oss << fileindex << '/' << filecount << " files checked " << percentDone << "% done"; diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index ec2cadd6900..e9e73ab29ac 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -115,16 +115,7 @@ class TestSingleExecutor : public TestFixture { std::string expected; for (int i = 1; i <= 100; ++i) { expected += "Checking file_" + zpad3(i) + ".cpp ...\n"; - int p; - if (i == 29) - p = 28; - else if (i == 57) - p = 56; - else if (i == 58) - p = 57; - else - p = i; - expected += std::to_string(i) + "/100 files checked " + std::to_string(p) + "% done\n"; + expected += std::to_string(i) + "/100 files checked " + std::to_string(i) + "% done\n"; } ASSERT_EQUALS(expected, output.str()); From efdc9d035924149e41da9fe76fb501b27e4d487a Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 10 Mar 2023 23:50:28 +0100 Subject: [PATCH 11/12] fixed `naming-varname` selfcheck warnings --- lib/color.cpp | 4 ++-- lib/color.h | 2 +- test/main.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/color.cpp b/lib/color.cpp index d9e58784d28..5fec2edec9e 100644 --- a/lib/color.cpp +++ b/lib/color.cpp @@ -24,7 +24,7 @@ #include #include // IWYU pragma: keep -bool DISABLE_COLORS = false; +bool gDisableColors = false; #ifdef _WIN32 std::ostream& operator<<(std::ostream& os, const Color& /*c*/) @@ -34,7 +34,7 @@ std::ostream& operator<<(std::ostream & os, const Color& c) { // TODO: handle piping into file as well as other pipes like stderr static const bool s_is_tty = isatty(STDOUT_FILENO); - if (!DISABLE_COLORS && s_is_tty) + if (!gDisableColors && s_is_tty) return os << "\033[" << static_cast(c) << "m"; #endif return os; diff --git a/lib/color.h b/lib/color.h index 9569a206c9f..871272a6218 100644 --- a/lib/color.h +++ b/lib/color.h @@ -42,6 +42,6 @@ CPPCHECKLIB std::ostream& operator<<(std::ostream& os, const Color& c); CPPCHECKLIB std::string toString(const Color& c); -extern CPPCHECKLIB bool DISABLE_COLORS; // for testing +extern CPPCHECKLIB bool gDisableColors; // for testing #endif diff --git a/test/main.cpp b/test/main.cpp index fadf8c82605..571b126922d 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) #endif Preprocessor::macroChar = '$'; // While macroChar is char(1) per default outside test suite, we require it to be a human-readable character here. - DISABLE_COLORS = true; + gDisableColors = true; options args(argc, argv); From b35ddb1f5b341abac74040f1a11e5fb38148800d Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 8 Apr 2023 16:30:27 +0200 Subject: [PATCH 12/12] dmake --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3a38a5da56b..e50a451aac7 100644 --- a/Makefile +++ b/Makefile @@ -657,7 +657,7 @@ cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/color.h lib/config.h lib/err cli/processexecutor.o: cli/processexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/processexecutor.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 $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/processexecutor.cpp -cli/singleexecutor.o: cli/singleexecutor.cpp cli/executor.h cli/singleexecutor.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/timer.h lib/utils.h +cli/singleexecutor.o: cli/singleexecutor.cpp cli/executor.h cli/singleexecutor.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 $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/singleexecutor.cpp cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h