From 7fd4118d606b64dcb1c324d37248210a27094347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sat, 4 Mar 2023 09:02:35 +0100 Subject: [PATCH] Fix #10039 (integrate `--check-config` include findings with normal analysis) / also fixes #11283 (#3229) --- .github/workflows/CI-unixish.yml | 6 - .github/workflows/asan.yml | 20 +++- .github/workflows/ubsan.yml | 20 +++- .selfcheck_suppressions | 3 + cli/cmdlineparser.cpp | 3 +- cli/cppcheckexecutor.cpp | 26 ----- lib/preprocessor.cpp | 26 ++--- lib/preprocessor.h | 4 - man/cppcheck.1.xml | 2 +- releasenotes.txt | 5 +- test/cli/test-helloworld.py | 9 +- test/cli/test-other.py | 11 +- test/fixture.cpp | 16 +++ test/fixture.h | 5 +- test/testpreprocessor.cpp | 195 ++++++++----------------------- 15 files changed, 124 insertions(+), 227 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 1d280d1db..da3b62a77 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -449,12 +449,6 @@ jobs: selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings" ec=0 - # work around missingInclude not being reported with -j and the --check-config requirement for detailed warnings - ./cppcheck $selfcheck_options -DCHECK_INTERNAL cli lib --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1 - ./cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1 - ./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1 - ./cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1 - # early exit if [ $ec -eq 1 ]; then exit $ec diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 343e89401..ff59f86b5 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -13,6 +13,7 @@ jobs: runs-on: ubuntu-22.04 env: + QT_VERSION: 5.15.2 ASAN_OPTIONS: detect_stack_use_after_return=1 steps: @@ -35,9 +36,16 @@ jobs: chmod +x llvm.sh sudo ./llvm.sh 16 + - name: Install Qt ${{ env.QT_VERSION }} + uses: jurplel/install-qt-action@v3 + with: + version: ${{ env.QT_VERSION }} + modules: 'qtcharts' + cache: true + - name: CMake run: | - cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On + cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On env: CC: clang-16 CXX: clang++-16 @@ -53,6 +61,12 @@ jobs: - name: Run tests run: ./cmake.output/bin/testrunner + - name: Generate dependencies + run: | + # make sure auto-generated GUI files exist + make -C cmake.output autogen + make -C cmake.output gui-build-deps triage-build-ui-deps + # TODO: this is currently way too slow (~60 minutes) to enable it # TODO: only fail the step on sanitizer issues - name: Self check @@ -61,7 +75,7 @@ jobs: selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings" ec=0 ./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1 ./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1 exit $ec diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index 5bddbba85..c422c7272 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -13,6 +13,7 @@ jobs: runs-on: ubuntu-22.04 env: + QT_VERSION: 5.15.2 UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1:report_error_type=1 steps: @@ -35,9 +36,16 @@ jobs: chmod +x llvm.sh sudo ./llvm.sh 16 + - name: Install Qt ${{ env.QT_VERSION }} + uses: jurplel/install-qt-action@v3 + with: + version: ${{ env.QT_VERSION }} + modules: 'qtcharts' + cache: true + - name: CMake run: | - cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On + cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On env: CC: clang-16 CXX: clang++-16 @@ -53,13 +61,19 @@ jobs: - name: Run tests run: ./cmake.output/bin/testrunner + - name: Generate dependencies + run: | + # make sure auto-generated GUI files exist + make -C cmake.output autogen + make -C cmake.output gui-build-deps triage-build-ui-deps + # TODO: only fail the step on sanitizer issues - name: Self check run: | selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings" ec=0 ./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1 ./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1 exit $ec diff --git a/.selfcheck_suppressions b/.selfcheck_suppressions index 7e1de66f2..ba35bede7 100644 --- a/.selfcheck_suppressions +++ b/.selfcheck_suppressions @@ -1,3 +1,4 @@ +missingIncludeSystem shadowFunction bitwiseOnBoolean @@ -11,7 +12,9 @@ simplifyUsing:gui/temp/moc_*.cpp funcArgNamesDifferent:gui/temp/moc_*.cpp symbolDatabaseWarning:tools/triage/temp/moc_*.cpp naming-varname:gui/temp/ui_*.h +naming-varname:cmake.output/gui/ui_*.h functionStatic:gui/temp/ui_fileview.h +functionStatic:cmake.output/gui/ui_fileview.h # --debug-warnings suppressions valueFlowBailout diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 9439fb30a..0d3079b8e 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -1136,8 +1136,7 @@ void CmdLineParser::printHelp() " to only enable this when the whole program is\n" " scanned.\n" " * missingInclude\n" - " Warn if there are missing includes. For\n" - " detailed information, use '--check-config'.\n" + " Warn if there are missing includes.\n" " Several ids can be given if you separate them with\n" " commas. See also --std\n" " --error-exitcode= If errors are found, integer [n] is returned instead of\n" diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 293e62fe8..40375b39c 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -198,9 +198,6 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c int CppCheckExecutor::check(int argc, const char* const argv[]) { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - CheckUnusedFunctions::clear(); CppCheck cppCheck(*this, true, executeCommand); @@ -380,29 +377,6 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) if (!settings.checkConfiguration) { cppcheck.tooManyConfigsError(emptyString,0U); - - if (settings.checks.isEnabled(Checks::missingInclude) && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) { - const std::list callStack; - ErrorMessage msg(callStack, - emptyString, - Severity::information, - "Cppcheck cannot find all the include files (use --check-config for details)\n" - "Cppcheck cannot find all the include files. Cppcheck can check the code without the " - "include files found. But the results will probably be more accurate if all the include " - "files are found. Please check your project's include directories and add all of them " - "as include directories for Cppcheck. To see what files Cppcheck cannot find use " - "--check-config.", - "", - Certainty::normal); - if (Preprocessor::missingIncludeFlag) { - msg.id = "missingInclude"; - reportInfo(msg); - } - if (Preprocessor::missingSystemIncludeFlag) { - msg.id = "missingIncludeSystem"; - reportInfo(msg); - } - } } if (settings.xml) { diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 0e7ff273d..25e1377c0 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -62,9 +62,6 @@ Directive::Directive(std::string _file, const int _linenr, const std::string &_s str(trim(_str)) {} -std::atomic Preprocessor::missingIncludeFlag; -std::atomic Preprocessor::missingSystemIncludeFlag; - char Preprocessor::macroChar = char(1); Preprocessor::Preprocessor(Settings& settings, ErrorLogger *errorLogger) : mSettings(settings), mErrorLogger(errorLogger) @@ -836,27 +833,19 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const // Report that include is missing void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType) { - if (!mSettings.checks.isEnabled(Checks::missingInclude) && !mSettings.checkConfiguration) + if (!mSettings.checks.isEnabled(Checks::missingInclude)) return; std::string fname = Path::fromNativeSeparators(filename); + std::string errorId = (headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude"; Suppressions::ErrorMessage errorMessage; - errorMessage.errorId = "missingInclude"; + errorMessage.errorId = errorId; errorMessage.setFileName(std::move(fname)); errorMessage.lineNumber = linenr; if (mSettings.nomsg.isSuppressed(errorMessage)) return; - errorMessage.errorId = "missingIncludeSystem"; - if (headerType == SystemHeader && mSettings.nomsg.isSuppressed(errorMessage)) - return; - - if (headerType == SystemHeader) - missingSystemIncludeFlag = true; - else - missingIncludeFlag = true; - - if (mErrorLogger && mSettings.checkConfiguration) { + if (mErrorLogger) { std::list locationList; if (!filename.empty()) { ErrorMessage::FileLocation loc; @@ -864,13 +853,13 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line loc.setfile(Path::toNativeSeparators(filename)); locationList.push_back(std::move(loc)); } - ErrorMessage errmsg(locationList, mFile0, Severity::information, + ErrorMessage errmsg(std::move(locationList), mFile0, Severity::information, (headerType==SystemHeader) ? "Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results." : "Include file: \"" + header + "\" not found.", - (headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude", + std::move(errorId), Certainty::normal); - mErrorLogger->reportInfo(errmsg); + mErrorLogger->reportErr(errmsg); } } @@ -878,7 +867,6 @@ void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *se { Settings settings2(*settings); Preprocessor preprocessor(settings2, errorLogger); - settings2.checkConfiguration = true; preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader); preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader); preprocessor.error(emptyString, 1, "#error message"); // #error .. diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 0c97333da..a78c3d776 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -23,7 +23,6 @@ #include "config.h" -#include #include #include #include @@ -87,9 +86,6 @@ public: explicit Preprocessor(Settings& settings, ErrorLogger *errorLogger = nullptr); virtual ~Preprocessor(); - static std::atomic missingIncludeFlag; - static std::atomic missingSystemIncludeFlag; - void inlineSuppressions(const simplecpp::TokenList &tokens); void setDirectives(const simplecpp::TokenList &tokens); diff --git a/man/cppcheck.1.xml b/man/cppcheck.1.xml index 9f6914d0f..bea2a2809 100644 --- a/man/cppcheck.1.xml +++ b/man/cppcheck.1.xml @@ -295,7 +295,7 @@ Example: '-UDEBUG' enables unusedFunction.warningEnable warning messagesstyleEnable all coding style checks. All messages with the severities 'style', 'performance' and 'portability' are enabled.performanceEnable performance messagesportabilityEnable portability messagesinformationEnable information messagesunusedFunctionCheck for unused functions. It is recommend to only - enable this when the whole program is scannedmissingIncludeWarn if there are missing includes. For detailed information use --check-config + enable this when the whole program is scannedmissingIncludeWarn if there are missing includes By default none of the additional checks are enabled. Several ids can be given if you separate them with commas, e.g. --enable=style,unusedFunction. See also --std diff --git a/releasenotes.txt b/releasenotes.txt index 9f18da67d..be9e51342 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -1,3 +1,6 @@ release notes for cppcheck-2.11 -- The platform type 'Unspecified' within .cppcheck projects has been deprecated and will be removed in Cppcheck 2.14. Please use 'unspecified' instead. \ No newline at end of file +- The platform type 'Unspecified' within .cppcheck projects has been deprecated and will be removed in Cppcheck 2.14. Please use 'unspecified' instead. +- It is no longer necessary to run "--check-config" to get detailed "missingInclude" and "missingIncludeSystem" messages. They will always be issued in the regular analysis if "missingInclude" is enabled. +- "missingInclude" and "missingIncludeSystem" are reported with "-j" is > 1 and processes are used in the backend (default in non-Windows binaries) +- "missingInclude" and "missingIncludeSystem" will now cause the "--error-exitcode" to be applied \ No newline at end of file diff --git a/test/cli/test-helloworld.py b/test/cli/test-helloworld.py index 0090cfda3..9e6e40c63 100644 --- a/test/cli/test-helloworld.py +++ b/test/cli/test-helloworld.py @@ -198,16 +198,15 @@ def test_build_dir_dump_output(): assert '' in dump, 'invalid dump data: ...' + dump[-100:] def __test_missing_include_system(use_j): - args = '--enable=missingInclude --suppress=zerodiv helloworld' + args = ['--enable=missingInclude', '--suppress=zerodiv', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', 'helloworld'] if use_j: - args = '-j2 ' + args + args.insert(0, '-j2') - _, _, stderr = cppcheck(args.split()) - assert stderr == 'nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingIncludeSystem]\n\n' + _, _, stderr = cppcheck(args) + assert stderr.replace('\\', '/') == 'helloworld/main.c:1:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n' def test_missing_include_system(): __test_missing_include_system(False) -@pytest.mark.xfail def test_missing_include_system_j(): #11283 __test_missing_include_system(True) diff --git a/test/cli/test-other.py b/test/cli/test-other.py index d7a0d3466..80dd63180 100644 --- a/test/cli/test-other.py +++ b/test/cli/test-other.py @@ -13,17 +13,16 @@ def __test_missing_include(tmpdir, use_j): #include "test.h" """) - args = '--enable=missingInclude {}'.format(test_file) + args = ['--enable=missingInclude', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file] if use_j: - args = '-j2 ' + args + args.insert(0, '-j2') - _, _, stderr = cppcheck(args.split()) - assert stderr == 'nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingInclude]\n\n' + _, _, stderr = cppcheck(args) + assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n'.format(test_file) def test_missing_include(tmpdir): __test_missing_include(tmpdir, False) -@pytest.mark.xfail def test_missing_include_j(tmpdir): #11283 __test_missing_include(tmpdir, True) @@ -40,7 +39,7 @@ def __test_missing_include_check_config(tmpdir, use_j): args = '-j2 ' + args _, _, stderr = cppcheck(args.split()) - assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n\n^\n'.format(test_file) + assert stderr == '' # --check-config no longer reports the missing includes def test_missing_include_check_config(tmpdir): __test_missing_include_check_config(tmpdir, False) diff --git a/test/fixture.cpp b/test/fixture.cpp index 7eaf460cf..b76c0777a 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -394,3 +394,19 @@ void TestFixture::reportErr(const ErrorMessage &msg) if (errout.str().find(errormessage) == std::string::npos) errout << errormessage << std::endl; } + +void TestFixture::setTemplateFormat(const std::string &templateFormat) +{ + if (templateFormat == "multiline") { + mTemplateFormat = "{file}:{line}:{severity}:{message}"; + mTemplateLocation = "{file}:{line}:note:{info}"; + } + else if (templateFormat == "simple") { + mTemplateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]"; + mTemplateLocation = ""; + } + else { + mTemplateFormat = templateFormat; + mTemplateLocation = ""; + } +} diff --git a/test/fixture.h b/test/fixture.h index 64a21eee2..818c0e6bd 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -102,9 +102,10 @@ protected: mVerbose = v; } + void setTemplateFormat(const std::string &templateFormat); + void setMultiline() { - mTemplateFormat = "{file}:{line}:{severity}:{message}"; - mTemplateLocation = "{file}:{line}:note:{info}"; + setTemplateFormat("multiline"); } void processOptions(const options& args); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 5e754f584..b1a3071b5 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -204,7 +204,6 @@ private: // inline suppression, missingInclude/missingIncludeSystem TEST_CASE(inline_suppression_for_missing_include); - TEST_CASE(inline_suppression_for_missing_include_check_config); // Using -D to predefine symbols TEST_CASE(predefine1); @@ -1946,16 +1945,11 @@ private: preprocess("#define () {(int f(x) }\n", actual); // don't hang } - void inline_suppression_for_missing_include_internal(bool checkConfig) { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + void inline_suppression_for_missing_include() { Settings settings; - settings.checkConfiguration = checkConfig; settings.inlineSuppressions = true; settings.severity.clear(); - // --check-config needs to report this regardless of the emanled checks - if (!checkConfig) - settings.checks.enable(Checks::missingInclude); + settings.checks.enable(Checks::missingInclude); Preprocessor preprocessor(settings, this); const std::string code("// cppcheck-suppress missingInclude\n" @@ -1966,8 +1960,6 @@ private: errout.str(""); preprocessor.getcode(code, "", "test.c"); ASSERT_EQUALS("", errout.str()); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); auto suppressions = settings.nomsg.getSuppressions(); ASSERT_EQUALS(2, suppressions.size()); @@ -1989,14 +1981,6 @@ private: ASSERT_EQUALS(true, suppr.matched); } - void inline_suppression_for_missing_include() { - inline_suppression_for_missing_include_internal(false); - } - - void inline_suppression_for_missing_include_check_config() { - inline_suppression_for_missing_include_internal(true); - } - void predefine1() { const std::string src("#if defined X || Y\n" "Fred & Wilma\n" @@ -2412,13 +2396,12 @@ private: // test for existing local include void testMissingInclude() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); ScopedFile header("header.h", ""); @@ -2426,49 +2409,35 @@ private: std::string code("#include \"header.h\""); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; } // test for missing local include void testMissingInclude2() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); std::string code("#include \"header.h\""); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(true, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor - ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: \"header.h\" not found. [missingInclude]\n", errout.str()); } // test for missing local include - no include path given void testMissingInclude3() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); ScopedFile header("header.h", "", "inc"); @@ -2476,26 +2445,19 @@ private: std::string code("#include \"header.h\""); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(true, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor - ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: \"header.h\" not found. [missingInclude]\n", errout.str()); } // test for existing local include - include path provided void testMissingInclude4() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); settings.includePaths.emplace_back("inc"); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); ScopedFile header("header.h", "", "inc"); @@ -2503,26 +2465,19 @@ private: std::string code("#include \"inc/header.h\""); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; } // test for existing local include - absolute path void testMissingInclude5() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); settings.includePaths.emplace_back("inc"); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); ScopedFile header("header.h", "", Path::getCurrentPath()); @@ -2530,25 +2485,18 @@ private: std::string code("#include \"" + header.path() + "\""); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; } // test for missing local include - absolute path void testMissingInclude6() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); const std::string header = Path::join(Path::getCurrentPath(), "header.h"); @@ -2556,25 +2504,18 @@ private: std::string code("#include \"" + header + "\""); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(true, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor - ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: \"" + header + "\" not found. [missingInclude]\n", errout.str()); } // test for missing system include - system includes are not searched for in relative path void testMissingSystemInclude() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); ScopedFile header("header.h", ""); @@ -2582,50 +2523,37 @@ private: std::string code("#include "); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor - ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout.str()); } // test for missing system include void testMissingSystemInclude2() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); std::string code("#include "); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor - ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout.str()); } // test for existing system include in system include path void testMissingSystemInclude3() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); settings.includePaths.emplace_back("system"); + Preprocessor preprocessor(settings, this); ScopedFile header("header.h", "", "system"); @@ -2633,26 +2561,19 @@ private: std::string code("#include "); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; } // test for existing system include - absolute path void testMissingSystemInclude4() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); settings.includePaths.emplace_back("inc"); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); ScopedFile header("header.h", "", Path::getCurrentPath()); @@ -2660,25 +2581,18 @@ private: std::string code("#include <" + header.path() + ">"); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(false, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; } // test for missing system include - absolute path void testMissingSystemInclude5() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); const std::string header = Path::join(Path::getCurrentPath(), "header.h"); @@ -2686,25 +2600,18 @@ private: std::string code("#include <" + header + ">"); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor - ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout.str()); } // test for missing local and system include void testMissingIncludeMixed() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; settings.severity.clear(); settings.checks.enable(Checks::missingInclude); + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); Preprocessor preprocessor(settings, this); ScopedFile header("header.h", ""); @@ -2716,26 +2623,21 @@ private: "#include \"header2.h\""); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(true, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag); - // the expected messages are emitted outside of the Preprocessor - ASSERT_EQUALS("", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: \"missing.h\" not found. [missingInclude]\n" + "test.c:2:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n" + "test.c:3:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout.str()); } void testMissingIncludeCheckConfig() { - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; - Settings settings; settings.clearIncludeCache = true; - settings.checkConfiguration = true; settings.severity.clear(); + settings.checks.enable(Checks::missingInclude); settings.includePaths.emplace_back("system"); - // needs to be reported regardless of enabled checks + settings.templateFormat = "simple"; // has no effect + setTemplateFormat("simple"); + Preprocessor preprocessor(settings, this); ScopedFile header("header.h", ""); @@ -2761,18 +2663,13 @@ private: "#include <" + missing4 + ">\n"); errout.str(""); preprocessor.getcode(code, "", "test.c"); - ASSERT_EQUALS(true, Preprocessor::missingIncludeFlag); - ASSERT_EQUALS(true, Preprocessor::missingSystemIncludeFlag); - ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing.h\" not found.\n" - "[test.c:2]: (information) Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.\n" - "[test.c:3]: (information) Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.\n" - "[test.c:6]: (information) Include file: \"header4.h\" not found.\n" - "[test.c:9]: (information) Include file: \"" + missing3 + "\" not found.\n" - "[test.c:11]: (information) Include file: <" + missing4 + "> not found. Please note: Cppcheck does not need standard library headers to get proper results.\n", errout.str()); - - Preprocessor::missingIncludeFlag = false; - Preprocessor::missingSystemIncludeFlag = false; + ASSERT_EQUALS("test.c:1:0: information: Include file: \"missing.h\" not found. [missingInclude]\n" + "test.c:2:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n" + "test.c:3:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n" + "test.c:6:0: information: Include file: \"header4.h\" not found. [missingInclude]\n" + "test.c:9:0: information: Include file: \"" + missing3 + "\" not found. [missingInclude]\n" + "test.c:11:0: information: Include file: <" + missing4 + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout.str()); } };