diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 06dcd5972..30ed27a0e 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -43,6 +43,7 @@ #endif #include +#include #include #include // EXIT_SUCCESS and EXIT_FAILURE #include @@ -66,6 +67,8 @@ #include #endif +// TODO: do not directly write to stdout + /*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout; @@ -319,21 +322,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) bool CppCheckExecutor::loadLibraries(Settings& settings) { - const bool std = tryLoadLibrary(settings.library, settings.exename, "std.cfg"); - - const auto failed_lib = std::find_if(settings.libraries.begin(), settings.libraries.end(), [&](const std::string& lib) { - return !tryLoadLibrary(settings.library, settings.exename, lib.c_str()); - }); - if (failed_lib != settings.libraries.end()) { - const std::string msg("Failed to load the library " + *failed_lib); - const std::list callstack; - ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", Certainty::normal); - reportErr(errmsg); - return false; - } - - if (!std) { - const std::list callstack; + if (!tryLoadLibrary(settings.library, settings.exename, "std.cfg")) { const std::string msg("Failed to load std.cfg. Your Cppcheck installation is broken, please re-install."); #ifdef FILESDIR const std::string details("The Cppcheck binary was compiled with FILESDIR set to \"" @@ -345,12 +334,17 @@ bool CppCheckExecutor::loadLibraries(Settings& settings) "std.cfg should be available in " + cfgfolder + " or the FILESDIR " "should be configured."); #endif - ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", Certainty::normal); - reportErr(errmsg); + std::cout << msg << " " << details << std::endl; return false; } - return true; + bool result = true; + for (const auto& lib : settings.libraries) { + if (!tryLoadLibrary(settings.library, settings.exename, lib.c_str())) { + result = false; + } + } + return result; } #ifdef _WIN32 @@ -424,6 +418,8 @@ void CppCheckExecutor::reportErr(const ErrorMessage &msg) return; } + assert(mSettings != nullptr); + // Alert only about unique errors if (!mShownErrors.insert(msg.toString(mSettings->verbose)).second) return; diff --git a/test/cli/test-other.py b/test/cli/test-other.py index 29db8ea0c..d1e329434 100644 --- a/test/cli/test-other.py +++ b/test/cli/test-other.py @@ -60,4 +60,15 @@ def test_missing_include_inline_suppr(tmpdir): args = ['--enable=missingInclude', '--inline-suppr', test_file] _, _, stderr = cppcheck(args) - assert stderr == '' \ No newline at end of file + assert stderr == '' + +def test_invalid_library(tmpdir): + args = ['--library=none', '--library=posix', '--library=none2', '--platform=native', 'file.c'] + + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 1 + assert (stdout == "cppcheck: Failed to load library configuration file 'none'. File not found\n" + "cppcheck: Failed to load library configuration file 'none2'. File not found\n") + assert stderr == "" + +# TODO: test missing std.cfg \ No newline at end of file