From c13123953807224508f42c0db5418293b1f9abd5 Mon Sep 17 00:00:00 2001 From: Oleksandr Labetskyi Date: Fri, 30 Aug 2024 10:53:43 +0000 Subject: [PATCH] Nits --- lib/cppcheck.cpp | 11 +- lib/cppcheck.h | 3 - .../invalid-project/invalid-project.vcxproj | 123 ---------------- test/cli/more-projects_test.py | 133 +++++++++++++++++- test/testcppcheck.cpp | 2 +- test/testsuppressions.cpp | 16 ++- 6 files changed, 142 insertions(+), 146 deletions(-) delete mode 100644 test/cli/invalid-project/invalid-project.vcxproj diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 3fec328d3f9..54b6e38ea2e 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -583,13 +583,6 @@ unsigned int CppCheck::check(const FileSettings &fs) // TODO: move to constructor when CppCheck no longer owns the settings if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck) mUnusedFunctionsCheck.reset(new CheckUnusedFunctions()); - if (!Path::isFile(fs.filename)) { - std::string fixedpath = Path::simplifyPath(fs.filename); - fixedpath = Path::toNativeSeparators(fixedpath); - const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file."); - fileNotFoundError(fs.filename, errorMsg); - return 0; - } CppCheck temp(mErrorLogger, mUseGlobalSuppressions, mExecuteCommand); temp.mSettings = mSettings; if (!temp.mSettings.userDefines.empty()) @@ -708,7 +701,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string if (mSettings.relativePaths) locfile = Path::getRelativePath(locfile, mSettings.basePaths); if(output.type == simplecpp::Output::Type::FILE_NOT_FOUND){ - const std::string fixedpath = Path::toNativeSeparators(file); + const std::string fixedpath = Path::toNativeSeparators(file.path()); const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file."); reportErr(ErrorMessage(std::list (), @@ -719,7 +712,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string Certainty::normal)); } else{ - reportErr(makeError(file, output.location.line, output.location.col, output.msg, "syntaxError")); + reportErr(makeError(file.path(), output.location.line, output.location.col, output.msg, "syntaxError")); } return mExitCode; } diff --git a/lib/cppcheck.h b/lib/cppcheck.h index e5790f2a599..9143760dcff 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -172,9 +172,6 @@ class CPPCHECKLIB CppCheck : ErrorLogger { /** @brief There has been an internal error => Report information message */ void internalError(const std::string &filename, const std::string &msg); - /** @brief File is missing => Report information message */ - void fileNotFoundError(const std::string &filename, const std::string &msg); - /** * @brief Check a file using stream * @param file the file diff --git a/test/cli/invalid-project/invalid-project.vcxproj b/test/cli/invalid-project/invalid-project.vcxproj deleted file mode 100644 index 12114b955f2..00000000000 --- a/test/cli/invalid-project/invalid-project.vcxproj +++ /dev/null @@ -1,123 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {7319858B-261C-4F0D-B022-92BB896242DD} - invalidProjet - 10.0.16299.0 - - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - - - Level3 - Disabled - true - true - - - - - Level3 - Disabled - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - - - - - \ No newline at end of file diff --git a/test/cli/more-projects_test.py b/test/cli/more-projects_test.py index 6599f052328..aaf17c12795 100644 --- a/test/cli/more-projects_test.py +++ b/test/cli/more-projects_test.py @@ -865,9 +865,136 @@ def test_shared_items_project(tmpdir = ""): assert any('2/2 files checked 100% done' in x for x in lines) assert stderr == '' +import shutil -def test_project_missing_files(): - filename = os.path.join('invalid-project', 'main.c') - ret, _, stderr = cppcheck(['--template=cppcheck1', '--project=' + os.path.join('invalid-project', 'invalid-project.vcxproj')]) +def test_project_missing_files(tmpdir): + filename = os.path.join(tmpdir, 'main.c') + project_file = os.path.join(tmpdir, 'helloworld.vcxproj') + with open(project_file, 'wt') as f: + f.write( +""" + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {7319858B-261C-4F0D-B022-92BB896242DD} + invalidProjet + 10.0.16299.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + +""") + ret, _, stderr = cppcheck(['--template=cppcheck1', '--project=' + os.path.join(tmpdir, 'helloworld.vcxproj')]) assert ret == 0 assert stderr == ': (error) File {} does not exists. Skipping file.\n'.format(filename) diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 19497fd9fc2..9198708dd33 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -117,7 +117,7 @@ class TestCppcheck : public TestFixture { { ErrorLogger2 errorLogger; CppCheck cppcheck(errorLogger, false, {}); - ASSERT_EQUALS(1, cppcheck.check("NotAFile")); + ASSERT_EQUALS(1, cppcheck.check(FileWithDetails("NotAFile"))); ASSERT_EQUALS(1, errorLogger.ids.size()); ASSERT_EQUALS("fileNotFound", *errorLogger.ids.cbegin()); diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index a22845de980..153d3410cb2 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -1190,9 +1190,10 @@ class TestSuppressions : public TestFixture { ASSERT_EQUALS("", settings.supprs.nomsg.addSuppressionLine("uninitvar")); settings.exitCode = 1; - const char code[] = "int f() { int a; return a; }"; - ASSERT_EQUALS(0, cppCheck.check("test.c", code)); // <- no unsuppressed error is seen - ASSERT_EQUALS("[test.c:1]: (error) Uninitialized variable: a\n", errout.str()); // <- report error so ThreadExecutor can suppress it and make sure the global suppression is matched. + ScopedFile file("test.c", "int f() { int a; return a; }"); + FileSettings fs{file.path()}; + ASSERT_EQUALS(0, cppCheck.check(fs)); // <- no unsuppressed error is seen + ASSERT_EQUALS("[test.c:1]: (error) Uninitialized variable: a\n", errout_str()); // <- report error so ThreadExecutor can suppress it and make sure the global suppression is matched. } void inlinesuppress_unusedFunction() const { // #4210, #4946 - wrong report of "unmatchedSuppression" for "unusedFunction" @@ -1223,16 +1224,17 @@ class TestSuppressions : public TestFixture { settings.inlineSuppressions = true; settings.relativePaths = true; settings.basePaths.emplace_back("/somewhere"); - const char code[] = + ScopedFile file("test.cpp", "struct Point\n" "{\n" " // cppcheck-suppress unusedStructMember\n" " int x;\n" " // cppcheck-suppress unusedStructMember\n" " int y;\n" - "};"; - ASSERT_EQUALS(0, cppCheck.check("/somewhere/test.cpp", code)); - ASSERT_EQUALS("",errout.str()); + "};"); + FileSettings fs{file.path()}; + ASSERT_EQUALS(0, cppCheck.check(fs)); + ASSERT_EQUALS("", errout_str()); } void suppressingSyntaxErrorsInternal(unsigned int (TestSuppressions::*check)(const char[], const std::string &)) { // syntaxErrors should be suppressible (#7076)