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:
Reijo Tomperi 2009-01-08 21:30:25 +00:00
parent 42b661630b
commit 46f4701c26
5 changed files with 27 additions and 8 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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;
}