Fixed #2099 (Show an error if none of the given paths was found)

This commit is contained in:
Lauri Nurmi 2010-10-22 17:09:50 +02:00 committed by Daniel Marjamäki
parent 8bc12c204f
commit 91e66e74d0
5 changed files with 32 additions and 5 deletions

View File

@ -94,8 +94,8 @@ cppcheck: $(LIBOBJ) $(CLIOBJ)
all: cppcheck testrunner
testrunner: $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o
$(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o $(LDFLAGS)
testrunner: $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o
$(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o $(LDFLAGS)
test: all
./testrunner

View File

@ -70,7 +70,15 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
cppcheck->addFile(*iter);
}
return true;
if(filenames.empty())
{
std::cout << "cppcheck: error: could not find or open any of the paths given." << std::endl;
return false;
}
else
{
return true;
}
}
int CppCheckExecutor::check(int argc, const char* const argv[])

View File

@ -238,6 +238,10 @@
RelativePath="..\lib\cppcheck.cpp"
>
</File>
<File
RelativePath="..\cli\cppcheckexecutor.cpp"
>
</File>
<File
RelativePath="..\lib\errorlogger.cpp"
>
@ -484,6 +488,10 @@
RelativePath="..\lib\cppcheck.h"
>
</File>
<File
RelativePath="..\cli\cppcheckexecutor.h"
>
</File>
<File
RelativePath="..\lib\errorlogger.h"
>

View File

@ -22,6 +22,7 @@
#include "cppcheck.h"
#include "cppcheckexecutor.h"
#include "testsuite.h"
#include "path.h"
@ -55,6 +56,7 @@ private:
void run()
{
TEST_CASE(nonexistingpath);
TEST_CASE(linenumbers);
// TEST_CASE(linenumbers2);
@ -342,6 +344,15 @@ private:
}
#endif
void nonexistingpath()
{
CppCheckExecutor exec;
char *argv[] = { "", "idontexist" };
int retval = exec.check(2, argv);
ASSERT_EQUALS(retval, EXIT_FAILURE);
}
void linenumbers()
{
const char filedata[] = "void f()\n"

View File

@ -221,8 +221,8 @@ int main(int argc, char **argv)
fout << "cppcheck:\t$(LIBOBJ)\t$(CLIOBJ)\n";
fout << "\t$(CXX) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(LDFLAGS)\n\n";
fout << "all:\tcppcheck\ttestrunner\n\n";
fout << "testrunner:\t$(TESTOBJ)\t$(LIBOBJ)\tcli/threadexecutor.o\tcli/cmdlineparser.o\n";
fout << "\t$(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o $(LDFLAGS)\n\n";
fout << "testrunner:\t$(TESTOBJ)\t$(LIBOBJ)\tcli/threadexecutor.o\tcli/cmdlineparser.o\tcli/cppcheckexecutor.o\n";
fout << "\t$(CXX) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o $(LDFLAGS)\n\n";
fout << "test:\tall\n";
fout << "\t./testrunner\n\n";
fout << "check:\tall\n";