8
8
#include " CppUnit/TestSuite.h"
9
9
#include " CppUnit/TextTestResult.h"
10
10
#include < iostream>
11
- #include < fstream>
12
11
13
12
14
13
namespace CppUnit {
@@ -28,8 +27,8 @@ TestRunner::TestRunner(std::ostream& ostr):
28
27
29
28
TestRunner::~TestRunner ()
30
29
{
31
- for (Mappings::iterator it = _mappings. begin (); it != _mappings. end (); ++it )
32
- delete it-> second ;
30
+ for (auto & _mapping : _mappings)
31
+ delete _mapping. second ;
33
32
}
34
33
35
34
@@ -80,9 +79,9 @@ bool TestRunner::run(const std::vector<std::string>& args, const Test::Callback&
80
79
}
81
80
else if (arg == " -print" )
82
81
{
83
- for (Mappings::iterator it = _mappings. begin (); it != _mappings. end (); ++it )
82
+ for (auto & _mapping : _mappings)
84
83
{
85
- print (it-> first , it-> second , 0 );
84
+ print (_mapping. first , _mapping. second , 0 );
86
85
}
87
86
printed = true ;
88
87
continue ;
@@ -104,8 +103,8 @@ bool TestRunner::run(const std::vector<std::string>& args, const Test::Callback&
104
103
return false ;
105
104
}
106
105
107
- Test* testToRun = 0 ;
108
- for (Mappings::iterator it = _mappings.begin (); !testToRun && it != _mappings.end (); ++it)
106
+ Test* testToRun = nullptr ;
107
+ for (auto it = _mappings.begin (); !testToRun && it != _mappings.end (); ++it)
109
108
{
110
109
testToRun = find (testCase, it->second , it->first );
111
110
}
@@ -124,18 +123,18 @@ bool TestRunner::run(const std::vector<std::string>& args, const Test::Callback&
124
123
if (all)
125
124
{
126
125
tests.clear ();
127
- for (Mappings::iterator it = _mappings. begin (); it != _mappings. end (); ++it )
126
+ for (auto & _mapping : _mappings)
128
127
{
129
- collectAllTestCases (it-> second , tests);
128
+ collectAllTestCases (_mapping. second , tests);
130
129
}
131
130
}
132
131
133
132
TextTestResult result (_ostr, ignore);
134
- for (std::vector<Test*>::const_iterator it = tests. begin (); it != tests. end (); ++it )
133
+ for (auto testToRun : tests)
135
134
{
136
- Test* testToRun = *it;
137
135
if (testToRun->getType () == Test::Long && !longRunning)
138
136
continue ;
137
+
139
138
if (setup.size () > 0 )
140
139
testToRun->addSetup (setup);
141
140
@@ -163,7 +162,7 @@ bool TestRunner::run(const std::vector<std::string>& args, const Test::Callback&
163
162
164
163
void TestRunner::addTest (const std::string& name, Test* test)
165
164
{
166
- _mappings.push_back ( Mapping ( name, test) );
165
+ _mappings.emplace_back ( name, test);
167
166
}
168
167
169
168
@@ -176,9 +175,9 @@ void TestRunner::print(const std::string& name, Test* pTest, int indent)
176
175
if (pSuite)
177
176
{
178
177
const std::vector<Test*>& tests = pSuite->tests ();
179
- for (std::vector<Test*>::const_iterator it = tests. begin (); it != tests. end (); ++it )
178
+ for (auto * test : tests)
180
179
{
181
- print ((*it) ->toString (), *it , indent + 1 );
180
+ print (test ->toString (), test , indent + 1 );
182
181
}
183
182
}
184
183
}
@@ -192,17 +191,17 @@ Test* TestRunner::find(const std::string& name, Test* pTest, const std::string&
192
191
}
193
192
else
194
193
{
195
- TestSuite * pSuite = dynamic_cast <TestSuite*>(pTest);
194
+ auto * pSuite = dynamic_cast <TestSuite*>(pTest);
196
195
if (pSuite)
197
196
{
198
197
const std::vector<Test*>& tests = pSuite->tests ();
199
- for (std::vector<Test*>::const_iterator it = tests. begin (); it != tests. end (); ++it )
198
+ for (auto * test : tests)
200
199
{
201
- Test* result = find (name, *it, (*it) ->toString ());
200
+ Test* result = find (name, test, test ->toString ());
202
201
if (result) return result;
203
202
}
204
203
}
205
- return 0 ;
204
+ return nullptr ;
206
205
}
207
206
}
208
207
@@ -212,14 +211,14 @@ int TestRunner::collectAllTestCases(Test* pTest, std::vector<Test*>& testcases)
212
211
int added = 0 ;
213
212
if (pTest->getType () == Test::Suite)
214
213
{
215
- TestSuite * pSuite = dynamic_cast <TestSuite*>(pTest);
214
+ auto * pSuite = dynamic_cast <TestSuite*>(pTest);
216
215
217
216
if (pSuite)
218
217
{
219
218
const std::vector<Test*>& tests = pSuite->tests ();
220
- for (std::vector<Test*>::const_iterator it = tests. begin (); it != tests. end (); ++it )
219
+ for (auto * test : tests)
221
220
{
222
- added += collectAllTestCases (*it , testcases);
221
+ added += collectAllTestCases (test , testcases);
223
222
}
224
223
}
225
224
}
0 commit comments