diff --git a/gui/test/projectfile/testprojectfile.cpp b/gui/test/projectfile/testprojectfile.cpp index 43bf382d629..e20b2ab38e2 100644 --- a/gui/test/projectfile/testprojectfile.cpp +++ b/gui/test/projectfile/testprojectfile.cpp @@ -25,8 +25,6 @@ #include "settings.h" #include "suppressions.h" -#include - #include #include #include @@ -45,9 +43,6 @@ Platform::Platform() = default; Library::Library() = default; Library::~Library() = default; struct Library::LibraryData {}; -bool ImportProject::sourceFileExists(const std::string & /*file*/) { - return true; -} void TestProjectFile::loadInexisting() const { diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 1af563ed439..3f465da606c 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -430,10 +430,6 @@ bool ImportProject::importCompileCommands(std::istream &istr) #endif else path = Path::simplifyPath(directory + file); - if (!sourceFileExists(path)) { - printError("'" + path + "' from compilation database does not exist"); - return false; - } FileSettings fs{path, Standards::Language::None, 0}; // file will be identified later on fsParseCommand(fs, command); // read settings; -D, -I, -U, -std, -m*, -f* std::map variables; @@ -1547,8 +1543,3 @@ void ImportProject::printError(const std::string &message) { std::cout << "cppcheck: error: " << message << std::endl; } - -bool ImportProject::sourceFileExists(const std::string &file) -{ - return Path::isFile(file); -} diff --git a/lib/importproject.h b/lib/importproject.h index 8a03474528a..54438584ff9 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -102,7 +102,6 @@ class CPPCHECKLIB WARN_UNUSED ImportProject { protected: bool importCompileCommands(std::istream &istr); bool importCppcheckGuiProject(std::istream &istr, Settings &settings, Suppressions &supprs); - virtual bool sourceFileExists(const std::string &file); private: struct SharedItemsProject { diff --git a/test/cli/project_test.py b/test/cli/project_test.py index e95c1df61e8..47752e08bd4 100644 --- a/test/cli/project_test.py +++ b/test/cli/project_test.py @@ -49,11 +49,19 @@ def test_json_entry_file_not_found(tmpdir): "output": "bug1.o"} ] - expected = "'{}' from compilation database does not exist".format(os.path.join(tmpdir, "bug1.cpp")) + project_file = os.path.join(tmpdir, "file.json") + missing_file = os.path.join(tmpdir, "bug1.cpp") + missing_file_posix = missing_file + if sys.platform == "win32": - expected = expected.replace('\\', '/') + missing_file_posix = missing_file_posix.replace('\\', '/') - __test_project_error(tmpdir, "json", json.dumps(compilation_db), expected) + with open(project_file, 'w') as f: + f.write(json.dumps(compilation_db)) + + ret, _, stderr = cppcheck(["--project=" + str(project_file)]) + assert 0 == ret + assert f"{missing_file}:1:0: error: File is missing: {missing_file_posix} [syntaxError]\n\n^\n" == stderr def test_json_no_arguments(tmpdir): diff --git a/test/testimportproject.cpp b/test/testimportproject.cpp index 843c42c0d11..71b1ba5c6dc 100644 --- a/test/testimportproject.cpp +++ b/test/testimportproject.cpp @@ -38,10 +38,6 @@ class TestImporter : public ImportProject { using ImportProject::importCppcheckGuiProject; using ImportProject::importVcxproj; using ImportProject::SharedItemsProject; - - bool sourceFileExists(const std::string & /*file*/) override { - return true; - } };