Fixed #2684 (TestFileLister test assumes there are source files in the same directory)
This commit is contained in:
parent
0d76d87770
commit
6f7e9a67b0
6
Makefile
6
Makefile
|
@ -76,7 +76,7 @@ TESTOBJ = test/options.o \
|
|||
test/testdivision.o \
|
||||
test/testerrorlogger.o \
|
||||
test/testexceptionsafety.o \
|
||||
test/testfilelister_unix.o \
|
||||
test/testfilelister.o \
|
||||
test/testincompletestatement.o \
|
||||
test/testmathlib.o \
|
||||
test/testmemleak.o \
|
||||
|
@ -271,8 +271,8 @@ test/testerrorlogger.o: test/testerrorlogger.cpp lib/cppcheck.h lib/settings.h l
|
|||
test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/tokenize.h lib/checkexceptionsafety.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testexceptionsafety.o test/testexceptionsafety.cpp
|
||||
|
||||
test/testfilelister_unix.o: test/testfilelister_unix.cpp test/testsuite.h lib/errorlogger.h lib/settings.h test/redirect.h
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testfilelister_unix.o test/testfilelister_unix.cpp
|
||||
test/testfilelister.o: test/testfilelister.cpp test/testsuite.h lib/errorlogger.h lib/settings.h test/redirect.h
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testfilelister.o test/testfilelister.cpp
|
||||
|
||||
test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h lib/errorlogger.h lib/settings.h test/redirect.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testincompletestatement.o test/testincompletestatement.cpp
|
||||
|
|
|
@ -19,6 +19,7 @@ SET(CHECKTEST_SRCS
|
|||
testdivision.cpp
|
||||
testerrorlogger.cpp
|
||||
testexceptionsafety.cpp
|
||||
testfilelister.cpp
|
||||
testincompletestatement.cpp
|
||||
testmathlib.cpp
|
||||
testmemleak.cpp
|
||||
|
@ -56,8 +57,6 @@ if(WIN32)
|
|||
# Windows needs additional shlwapi library.
|
||||
set(CHECK_LIBS ${CHECK_LIBS} shlwapi)
|
||||
endif()
|
||||
else()
|
||||
set(CHECKTEST_SRCS ${CHECKTEST_SRCS} testfilelister_unix.cpp)
|
||||
endif()
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
|
|
@ -48,6 +48,7 @@ SOURCES += options.cpp \
|
|||
testdivision.cpp \
|
||||
testerrorlogger.cpp \
|
||||
testexceptionsafety.cpp \
|
||||
testfilelister.cpp \
|
||||
testincompletestatement.cpp \
|
||||
testmathlib.cpp \
|
||||
testmemleak.cpp \
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "testsuite.h"
|
||||
#include "filelister.h"
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
class TestFileLister: public TestFixture
|
||||
{
|
||||
public:
|
||||
TestFileLister()
|
||||
:TestFixture("TestFileLister")
|
||||
{}
|
||||
|
||||
private:
|
||||
void run()
|
||||
{
|
||||
// bail out if the tests are not executed from the base folder
|
||||
{
|
||||
std::ifstream fin("test/testfilelister.cpp");
|
||||
if (!fin.is_open())
|
||||
return;
|
||||
}
|
||||
|
||||
TEST_CASE(isDirectory);
|
||||
TEST_CASE(recursiveAddFiles);
|
||||
}
|
||||
|
||||
void isDirectory()
|
||||
{
|
||||
ASSERT_EQUALS(false, FileLister::isDirectory("readme.txt"));
|
||||
ASSERT_EQUALS(true, FileLister::isDirectory("lib"));
|
||||
}
|
||||
|
||||
void recursiveAddFiles()
|
||||
{
|
||||
// Recursively add add files..
|
||||
std::vector<std::string> filenames;
|
||||
FileLister::recursiveAddFiles(filenames, ".");
|
||||
/*
|
||||
for (unsigned int i = 0; i < filenames.size(); ++i)
|
||||
std::cout << filenames[i] << std::endl;
|
||||
*/
|
||||
// Make sure source files are added..
|
||||
ASSERT(std::find(filenames.begin(), filenames.end(), "./cli/main.cpp") != filenames.end());
|
||||
ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/token.cpp") != filenames.end());
|
||||
ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/tokenize.cpp") != filenames.end());
|
||||
ASSERT(std::find(filenames.begin(), filenames.end(), "./test/testfilelister.cpp") != filenames.end());
|
||||
|
||||
// Make sure headers are not added..
|
||||
ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/tokenize.h") == filenames.end());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestFileLister)
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "testsuite.h"
|
||||
|
||||
#include "filelister.h"
|
||||
|
||||
class TestFileLister: public TestFixture
|
||||
{
|
||||
public:
|
||||
TestFileLister()
|
||||
:TestFixture("TestFileLister")
|
||||
{}
|
||||
|
||||
private:
|
||||
void run()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
TEST_CASE(test_recursiveAddFiles2);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
void test_recursiveAddFiles2()
|
||||
{
|
||||
std::vector<std::string> relative, absolute;
|
||||
FileLister::recursiveAddFiles2(relative, absolute, ".");
|
||||
|
||||
ASSERT(!relative.empty());
|
||||
ASSERT_EQUALS((int)relative.size(), (int)absolute.size());
|
||||
|
||||
for (std::vector<std::string>::const_iterator r = relative.begin(), r_end = relative.end(),
|
||||
a = absolute.begin(), a_end = absolute.end();
|
||||
r != r_end && a != a_end;
|
||||
++r, ++a
|
||||
)
|
||||
{
|
||||
static const size_t start_at_relative = std::string("./").size();
|
||||
static const size_t start_at_absolute = std::string("./").size() + a->size() - r->size();
|
||||
|
||||
ASSERT_EQUALS(r->substr(start_at_relative), a->substr(start_at_absolute));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestFileLister)
|
||||
|
Loading…
Reference in New Issue