Skip to content

Commit 6f7e9a6

Browse files
author
Daniel Marjamäki
committed
Fixed danmar#2684 (TestFileLister test assumes there are source files in the same directory)
1 parent 0d76d87 commit 6f7e9a6

File tree

5 files changed

+77
-68
lines changed

5 files changed

+77
-68
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ TESTOBJ = test/options.o \
7676
test/testdivision.o \
7777
test/testerrorlogger.o \
7878
test/testexceptionsafety.o \
79-
test/testfilelister_unix.o \
79+
test/testfilelister.o \
8080
test/testincompletestatement.o \
8181
test/testmathlib.o \
8282
test/testmemleak.o \
@@ -271,8 +271,8 @@ test/testerrorlogger.o: test/testerrorlogger.cpp lib/cppcheck.h lib/settings.h l
271271
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
272272
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testexceptionsafety.o test/testexceptionsafety.cpp
273273

274-
test/testfilelister_unix.o: test/testfilelister_unix.cpp test/testsuite.h lib/errorlogger.h lib/settings.h test/redirect.h
275-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testfilelister_unix.o test/testfilelister_unix.cpp
274+
test/testfilelister.o: test/testfilelister.cpp test/testsuite.h lib/errorlogger.h lib/settings.h test/redirect.h
275+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testfilelister.o test/testfilelister.cpp
276276

277277
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
278278
$(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testincompletestatement.o test/testincompletestatement.cpp

test/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SET(CHECKTEST_SRCS
1919
testdivision.cpp
2020
testerrorlogger.cpp
2121
testexceptionsafety.cpp
22+
testfilelister.cpp
2223
testincompletestatement.cpp
2324
testmathlib.cpp
2425
testmemleak.cpp
@@ -56,8 +57,6 @@ if(WIN32)
5657
# Windows needs additional shlwapi library.
5758
set(CHECK_LIBS ${CHECK_LIBS} shlwapi)
5859
endif()
59-
else()
60-
set(CHECKTEST_SRCS ${CHECKTEST_SRCS} testfilelister_unix.cpp)
6160
endif()
6261

6362
if (CMAKE_COMPILER_IS_GNUCXX)

test/test.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SOURCES += options.cpp \
4848
testdivision.cpp \
4949
testerrorlogger.cpp \
5050
testexceptionsafety.cpp \
51+
testfilelister.cpp \
5152
testincompletestatement.cpp \
5253
testmathlib.cpp \
5354
testmemleak.cpp \

test/testfilelister.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "testsuite.h"
20+
#include "filelister.h"
21+
#include <fstream>
22+
#include <algorithm>
23+
24+
class TestFileLister: public TestFixture
25+
{
26+
public:
27+
TestFileLister()
28+
:TestFixture("TestFileLister")
29+
{}
30+
31+
private:
32+
void run()
33+
{
34+
// bail out if the tests are not executed from the base folder
35+
{
36+
std::ifstream fin("test/testfilelister.cpp");
37+
if (!fin.is_open())
38+
return;
39+
}
40+
41+
TEST_CASE(isDirectory);
42+
TEST_CASE(recursiveAddFiles);
43+
}
44+
45+
void isDirectory()
46+
{
47+
ASSERT_EQUALS(false, FileLister::isDirectory("readme.txt"));
48+
ASSERT_EQUALS(true, FileLister::isDirectory("lib"));
49+
}
50+
51+
void recursiveAddFiles()
52+
{
53+
// Recursively add add files..
54+
std::vector<std::string> filenames;
55+
FileLister::recursiveAddFiles(filenames, ".");
56+
/*
57+
for (unsigned int i = 0; i < filenames.size(); ++i)
58+
std::cout << filenames[i] << std::endl;
59+
*/
60+
// Make sure source files are added..
61+
ASSERT(std::find(filenames.begin(), filenames.end(), "./cli/main.cpp") != filenames.end());
62+
ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/token.cpp") != filenames.end());
63+
ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/tokenize.cpp") != filenames.end());
64+
ASSERT(std::find(filenames.begin(), filenames.end(), "./test/testfilelister.cpp") != filenames.end());
65+
66+
// Make sure headers are not added..
67+
ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/tokenize.h") == filenames.end());
68+
}
69+
};
70+
71+
REGISTER_TEST(TestFileLister)
72+

test/testfilelister_unix.cpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)