Main returns now EXIT_SUCCESS or EXIT_FAILURE instead of 0. Feature request fixed: [ 2489787 ] Return value of cppcheck is always 0
This commit is contained in:
parent
42b661630b
commit
46f4701c26
|
@ -144,7 +144,7 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
|
|||
return "";
|
||||
}
|
||||
|
||||
void CppCheck::check()
|
||||
unsigned int CppCheck::check()
|
||||
{
|
||||
_checkFunctionUsage.setErrorLogger(this);
|
||||
std::sort(_filenames.begin(), _filenames.end());
|
||||
|
@ -209,7 +209,9 @@ void CppCheck::check()
|
|||
_checkFunctionUsage.check();
|
||||
}
|
||||
|
||||
unsigned int result = _errorList.size();
|
||||
_errorList.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,8 +50,9 @@ public:
|
|||
/**
|
||||
* This starts the actual checking. Note that you must call
|
||||
* parseFromArgs() or settings() and addFile() before calling this.
|
||||
* @return amount of errors found or 0 if none were found.
|
||||
*/
|
||||
void check();
|
||||
unsigned int check();
|
||||
|
||||
/**
|
||||
* Adjust the settings before doing the check. E.g. show only
|
||||
|
|
|
@ -30,14 +30,19 @@ CppCheckExecutor::~CppCheckExecutor()
|
|||
//dtor
|
||||
}
|
||||
|
||||
void CppCheckExecutor::check(int argc, const char* const argv[])
|
||||
unsigned int CppCheckExecutor::check(int argc, const char* const argv[])
|
||||
{
|
||||
CppCheck cppCheck(*this);
|
||||
std::string result = cppCheck.parseFromArgs(argc, argv);
|
||||
if (result.length() == 0)
|
||||
cppCheck.check();
|
||||
{
|
||||
return cppCheck.check();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << result;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void CppCheckExecutor::reportErr(const std::string &errmsg)
|
||||
|
|
|
@ -46,8 +46,12 @@ public:
|
|||
*
|
||||
* @param argc from main()
|
||||
* @param argv from main()
|
||||
* @return amount of errors found in the checking or 0
|
||||
* if no errors were found. If parsing of the arguments failed
|
||||
* and checking is not even started, 1 is returned to indicate
|
||||
* about an error.
|
||||
*/
|
||||
void check(int argc, const char* const argv[]);
|
||||
unsigned int check(int argc, const char* const argv[]);
|
||||
|
||||
/**
|
||||
* Errors and warnings are directed here. This should be
|
||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/
|
||||
*/
|
||||
|
||||
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
|
||||
#include "cppcheckexecutor.h"
|
||||
|
||||
/**
|
||||
|
@ -23,11 +24,17 @@
|
|||
*
|
||||
* @param argc Passed to CppCheck::parseFromArgs()
|
||||
* @param argv Passed to CppCheck::parseFromArgs()
|
||||
* @return 0
|
||||
* @return EXIT_SUCCESS if no errors are found or
|
||||
* EXIT_FAILURE if errors are found or checking was
|
||||
* not done because of invalid arguments given.
|
||||
*/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
CppCheckExecutor exec;
|
||||
exec.check(argc, argv);
|
||||
return 0;
|
||||
if (exec.check(argc, argv) == 0)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue