Skip to content

Commit 072212e

Browse files
authored
added TestCheck and moved some tests from TestCppcheck (#5289)
1 parent 988edd2 commit 072212e

4 files changed

Lines changed: 58 additions & 25 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ TESTOBJ = test/fixture.o \
278278
test/testboost.o \
279279
test/testbufferoverrun.o \
280280
test/testcharvar.o \
281+
test/testcheck.o \
281282
test/testclangimport.o \
282283
test/testclass.o \
283284
test/testcmdlineparser.o \
@@ -706,6 +707,9 @@ test/testbufferoverrun.o: test/testbufferoverrun.cpp externals/simplecpp/simplec
706707
test/testcharvar.o: test/testcharvar.cpp lib/check.h lib/checkother.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
707708
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcharvar.cpp
708709

710+
test/testcheck.o: test/testcheck.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
711+
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcheck.cpp
712+
709713
test/testclangimport.o: test/testclangimport.cpp lib/check.h lib/clangimport.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
710714
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclangimport.cpp
711715

test/testcheck.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2023 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 "check.h"
20+
#include "fixture.h"
21+
22+
class TestCheck : public TestFixture {
23+
public:
24+
TestCheck() : TestFixture("TestCheck") {}
25+
26+
private:
27+
void run() override {
28+
TEST_CASE(instancesSorted);
29+
TEST_CASE(classInfoFormat);
30+
}
31+
32+
void instancesSorted() const {
33+
for (std::list<Check *>::const_iterator i = Check::instances().cbegin(); i != Check::instances().cend(); ++i) {
34+
std::list<Check *>::const_iterator j = i;
35+
++j;
36+
if (j != Check::instances().cend()) {
37+
ASSERT_EQUALS(true, (*i)->name() < (*j)->name());
38+
}
39+
}
40+
}
41+
42+
void classInfoFormat() const {
43+
for (std::list<Check *>::const_iterator i = Check::instances().cbegin(); i != Check::instances().cend(); ++i) {
44+
const std::string info = (*i)->classInfo();
45+
if (!info.empty()) {
46+
ASSERT('\n' != info[0]); // No \n in the beginning
47+
ASSERT('\n' == info.back()); // \n at end
48+
if (info.size() > 1)
49+
ASSERT('\n' != info[info.length()-2]); // Only one \n at end
50+
}
51+
}
52+
}
53+
};

test/testcppcheck.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "check.h"
2019
#include "color.h"
2120
#include "cppcheck.h"
2221
#include "errorlogger.h"
@@ -45,33 +44,9 @@ class TestCppcheck : public TestFixture {
4544
};
4645

4746
void run() override {
48-
TEST_CASE(instancesSorted);
49-
TEST_CASE(classInfoFormat);
5047
TEST_CASE(getErrorMessages);
5148
}
5249

53-
void instancesSorted() const {
54-
for (std::list<Check *>::const_iterator i = Check::instances().cbegin(); i != Check::instances().cend(); ++i) {
55-
std::list<Check *>::const_iterator j = i;
56-
++j;
57-
if (j != Check::instances().cend()) {
58-
ASSERT_EQUALS(true, (*i)->name() < (*j)->name());
59-
}
60-
}
61-
}
62-
63-
void classInfoFormat() const {
64-
for (std::list<Check *>::const_iterator i = Check::instances().cbegin(); i != Check::instances().cend(); ++i) {
65-
const std::string info = (*i)->classInfo();
66-
if (!info.empty()) {
67-
ASSERT('\n' != info[0]); // No \n in the beginning
68-
ASSERT('\n' == info.back()); // \n at end
69-
if (info.size() > 1)
70-
ASSERT('\n' != info[info.length()-2]); // Only one \n at end
71-
}
72-
}
73-
}
74-
7550
void getErrorMessages() const {
7651
ErrorLogger2 errorLogger;
7752
CppCheck::getErrorMessages(errorLogger);

test/testrunner.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<ClCompile Include="testboost.cpp" />
7373
<ClCompile Include="testbufferoverrun.cpp" />
7474
<ClCompile Include="testcharvar.cpp" />
75+
<ClCompile Include="testcheck.cpp" />
7576
<ClCompile Include="testclangimport.cpp" />
7677
<ClCompile Include="testclass.cpp" />
7778
<ClCompile Include="testcmdlineparser.cpp" />

0 commit comments

Comments
 (0)