Skip to content

Commit 97a68bd

Browse files
committed
Added check target.
Runs the test as per `make test`, but with less verbosity. -g GCC-style errors -q quiet tests
1 parent 1039691 commit 97a68bd

File tree

8 files changed

+286
-26
lines changed

8 files changed

+286
-26
lines changed

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ CLIOBJ = cli/cmdlineparser.o \
5050
cli/main.o \
5151
cli/threadexecutor.o
5252

53-
TESTOBJ = test/testautovariables.o \
53+
TESTOBJ = test/options.o \
54+
test/testautovariables.o \
5455
test/testbufferoverrun.o \
5556
test/testcharvar.o \
5657
test/testclass.o \
@@ -64,6 +65,7 @@ TESTOBJ = test/testautovariables.o \
6465
test/testmathlib.o \
6566
test/testmemleak.o \
6667
test/testobsoletefunctions.o \
68+
test/testoptions.o \
6769
test/testother.o \
6870
test/testpreprocessor.o \
6971
test/testrunner.o \
@@ -96,6 +98,9 @@ testrunner: $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cmdlineparser.o
9698
test: all
9799
./testrunner
98100

101+
check: all
102+
./testrunner -g -q
103+
99104
dmake: tools/dmake.cpp
100105
$(CXX) -o dmake tools/dmake.cpp lib/filelister*.cpp
101106

@@ -193,6 +198,9 @@ cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h
193198
cli/threadexecutor.o: cli/threadexecutor.cpp cli/threadexecutor.h lib/settings.h lib/errorlogger.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h
194199
$(CXX) $(CXXFLAGS) -Ilib -c -o cli/threadexecutor.o cli/threadexecutor.cpp
195200

201+
test/options.o: test/options.cpp test/options.h
202+
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/options.o test/options.cpp
203+
196204
test/testautovariables.o: test/testautovariables.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkautovariables.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
197205
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testautovariables.o test/testautovariables.cpp
198206

@@ -235,13 +243,16 @@ test/testmemleak.o: test/testmemleak.cpp lib/tokenize.h lib/classinfo.h lib/toke
235243
test/testobsoletefunctions.o: test/testobsoletefunctions.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkobsoletefunctions.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
236244
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testobsoletefunctions.o test/testobsoletefunctions.cpp
237245

246+
test/testoptions.o: test/testoptions.cpp test/options.h test/testsuite.h lib/errorlogger.h
247+
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testoptions.o test/testoptions.cpp
248+
238249
test/testother.o: test/testother.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
239250
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testother.o test/testother.cpp
240251

241252
test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h lib/errorlogger.h lib/preprocessor.h lib/tokenize.h lib/classinfo.h lib/token.h lib/settings.h
242253
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testpreprocessor.o test/testpreprocessor.cpp
243254

244-
test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h
255+
test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h test/options.h
245256
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testrunner.o test/testrunner.cpp
246257

247258
test/testsettings.o: test/testsettings.cpp lib/settings.h test/testsuite.h lib/errorlogger.h
@@ -253,7 +264,7 @@ test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h lib/erro
253264
test/teststl.o: test/teststl.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkstl.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
254265
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/teststl.o test/teststl.cpp
255266

256-
test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h
267+
test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h test/options.h
257268
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testsuite.o test/testsuite.cpp
258269

259270
test/testthreadexecutor.o: test/testthreadexecutor.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h test/testsuite.h

test/options.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Cppcheck - A tool for static C/C++ code analysis
2+
// Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "options.h"
18+
19+
options::options(int argc, const char* argv[])
20+
:_options(&argv[1], &argv[0] + argc)
21+
,_gcc_style_errors(_options.count("-g") != 0)
22+
,_quiet(_options.count("-q") != 0)
23+
{
24+
_options.erase("-g");
25+
_options.erase("-q");
26+
}
27+
28+
bool options::quiet() const
29+
{
30+
return _quiet;
31+
}
32+
33+
bool options::gcc_style_errors() const
34+
{
35+
return _gcc_style_errors;
36+
}
37+
38+
const std::string& options::which_test() const
39+
{
40+
static std::string ret = "";
41+
if (not _options.empty())
42+
{
43+
ret = *_options.rbegin();
44+
}
45+
return ret;
46+
}
47+

test/options.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Cppcheck - A tool for static C/C++ code analysis
2+
// Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#ifndef OPTIONS_H
18+
#define OPTIONS_H
19+
20+
#include <set>
21+
#include <string>
22+
23+
class options
24+
{
25+
public:
26+
options(int argc, const char* argv[]);
27+
bool quiet() const;
28+
bool gcc_style_errors() const;
29+
const std::string& which_test() const;
30+
31+
private:
32+
options();
33+
options(const options& non_copy);
34+
const options& operator =(const options& non_assign);
35+
36+
private:
37+
std::set<std::string> _options;
38+
const bool _gcc_style_errors;
39+
const bool _quiet;
40+
};
41+
42+
#endif

test/testoptions.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Cppcheck - A tool for static C/C++ code analysis
2+
// Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "options.h"
18+
#include "testsuite.h"
19+
#include <sstream>
20+
21+
extern std::ostringstream errout;
22+
23+
class TestOptions: public TestFixture
24+
{
25+
public:
26+
TestOptions()
27+
:TestFixture("TestOptions")
28+
{
29+
}
30+
31+
32+
private:
33+
void run()
34+
{
35+
TEST_CASE(which_test);
36+
TEST_CASE(which_test_method);
37+
TEST_CASE(not_quiet);
38+
TEST_CASE(quiet);
39+
TEST_CASE(gcc_errors);
40+
TEST_CASE(multiple_testcases);
41+
TEST_CASE(invalid_switches);
42+
}
43+
44+
45+
void which_test()
46+
{
47+
const char* argv[] = {"./test_runner", "TestClass"};
48+
options args(sizeof argv / sizeof argv[0], argv);
49+
ASSERT_EQUALS("TestClass", args.which_test());
50+
}
51+
52+
53+
void which_test_method()
54+
{
55+
const char* argv[] = {"./test_runner", "TestClass::TestMethod"};
56+
options args(sizeof argv / sizeof argv[0], argv);
57+
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
58+
}
59+
60+
61+
void not_quiet()
62+
{
63+
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-v"};
64+
options args(sizeof argv / sizeof argv[0], argv);
65+
ASSERT_EQUALS(false, args.quiet());
66+
}
67+
68+
69+
void quiet()
70+
{
71+
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-q"};
72+
options args(sizeof argv / sizeof argv[0], argv);
73+
ASSERT_EQUALS(true, args.quiet());
74+
}
75+
76+
77+
void gcc_errors()
78+
{
79+
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-g"};
80+
options args(sizeof argv / sizeof argv[0], argv);
81+
ASSERT_EQUALS(true, args.gcc_style_errors());
82+
}
83+
84+
85+
void multiple_testcases()
86+
{
87+
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "Ignore::ThisOne"};
88+
options args(sizeof argv / sizeof argv[0], argv);
89+
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
90+
}
91+
92+
93+
void invalid_switches()
94+
{
95+
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-a", "-v", "-q", "-g"};
96+
options args(sizeof argv / sizeof argv[0], argv);
97+
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
98+
ASSERT_EQUALS(true, args.gcc_style_errors());
99+
ASSERT_EQUALS(true, args.quiet());
100+
}
101+
};
102+
103+
REGISTER_TEST(TestOptions)

test/testrunner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
#include <cstdlib>
2020
#include "testsuite.h"
21+
#include "options.h"
2122

2223
int main(int argc, const char *argv[])
2324
{
24-
size_t ret = TestFixture::runTests((argc == 2) ? argv[1] : NULL);
25+
options args(argc, argv);
26+
27+
size_t ret = TestFixture::runTests(args);
2528

2629
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
2730
}

0 commit comments

Comments
 (0)