Merge lp:~brianaker/gearmand/formatters into lp:gearmand

Proposed by Brian Aker
Status: Merged
Merged at revision: 797
Proposed branch: lp:~brianaker/gearmand/formatters
Merge into: lp:gearmand
Diff against target: 1093 lines (+542/-290)
8 files modified
libtest/collection.cc (+106/-35)
libtest/collection.h (+27/-15)
libtest/formatter.cc (+186/-106)
libtest/formatter.hpp (+59/-33)
libtest/framework.cc (+30/-52)
libtest/framework.h (+26/-20)
libtest/main.cc (+28/-29)
libtest/test.h (+80/-0)
To merge this branch: bzr merge lp:~brianaker/gearmand/formatters
Reviewer Review Type Date Requested Status
Tangent Trunk Pending
Review via email: mp+172640@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libtest/collection.cc'
--- libtest/collection.cc 2013-05-03 08:41:20 +0000
+++ libtest/collection.cc 2013-07-02 18:24:29 +0000
@@ -38,9 +38,11 @@
3838
39#include <libtest/common.h>39#include <libtest/common.h>
4040
41#include <algorithm>
42
41// @todo possibly have this code fork off so if it fails nothing goes bad43// @todo possibly have this code fork off so if it fails nothing goes bad
42static test_return_t runner_code(libtest::Framework* frame,44static test_return_t runner_code(libtest::Framework* frame,
43 test_st* run, 45 const struct test_st* run,
44 libtest::Timer& _timer)46 libtest::Timer& _timer)
45{ // Runner Code47{ // Runner Code
4648
@@ -84,46 +86,119 @@
8486
85namespace libtest {87namespace libtest {
8688
87Collection::Collection(Framework* frame_arg,89Collection::Collection(Framework* frame_,
88 collection_st* arg) :90 collection_st* tests_) :
89 _name(arg->name),91 _name(tests_->name),
90 _pre(arg->pre),92 _ret(TEST_SKIPPED),
91 _post(arg->post),93 _pre(tests_->pre),
92 _tests(arg->tests),94 _post(tests_->post),
93 _frame(frame_arg),95 _tests(tests_->tests),
96 _frame(frame_),
94 _success(0),97 _success(0),
95 _skipped(0),98 _skipped(0),
96 _failed(0),99 _failed(0),
97 _total(0),100 _formatter(frame_->formatter())
98 _formatter(frame_arg->name(), _name)101{
99{102 fatal_assert(tests_);
100 fatal_assert(arg);103 for (const test_st *run= _tests; run->name; run++)
104 {
105 push_testcase(run);
106 }
107
108 case_iter= _testcases.begin();
109}
110
111Collection::~Collection()
112{
113 std::for_each(_testcases.begin(), _testcases.end(), DeleteFromVector());
114 _testcases.clear();
115
116 std::for_each(_formatter.begin(), _formatter.end(), DeleteFromVector());
117 _formatter.clear();
118}
119
120void Collection::push_testcase(const test_st* test_)
121{
122 TestCase* _current_testcase= new TestCase(test_);
123 _testcases.push_back(_current_testcase);
124}
125
126void Collection::format()
127{
128 for (Formatters::iterator format_iter= _formatter.begin();
129 format_iter != _formatter.end();
130 ++format_iter)
131 {
132 (*format_iter)->report((*case_iter), std::distance(_testcases.begin(), case_iter));
133 }
134}
135
136void Collection::plan()
137{
138 for (Formatters::iterator format_iter= _formatter.begin();
139 format_iter != _formatter.end();
140 ++format_iter)
141 {
142 (*format_iter)->plan(this);
143 }
144}
145
146void Collection::complete()
147{
148 for (Formatters::iterator format_iter= _formatter.begin();
149 format_iter != _formatter.end();
150 ++format_iter)
151 {
152 (*format_iter)->complete();
153 }
154}
155
156void Collection::succeess()
157{
158 _success++;
159 (*case_iter)->success(_timer);
160 format();
161}
162
163void Collection::skip()
164{
165 _skipped++;
166 (*case_iter)->skipped();
167 format();
168}
169
170void Collection::fail()
171{
172 _failed++;
173 (*case_iter)->failed();
174 format();
101}175}
102176
103test_return_t Collection::exec()177test_return_t Collection::exec()
104{178{
179 // Write out any headers required by formatting.
180 plan();
181
105 if (test_success(_frame->runner()->setup(_pre, _frame->creators_ptr())))182 if (test_success(_frame->runner()->setup(_pre, _frame->creators_ptr())))
106 {183 {
107 for (test_st *run= _tests; run->name; run++)184 for (; case_iter != _testcases.end();
185 ++case_iter)
108 {186 {
109 formatter()->push_testcase(run->name);187 if (_frame->match((*case_iter)->name()))
110 if (_frame->match(run->name))
111 {188 {
112 formatter()->skipped();189 skip();
113 continue;190 continue;
114 }191 }
115 _total++;
116192
117 test_return_t return_code;193 test_return_t return_code;
118 try 194 try
119 {195 {
120 if (run->requires_flush)196 if ((*case_iter)->requires_flush())
121 {197 {
122 if (test_failed(_frame->runner()->flush(_frame->creators_ptr())))198 if (test_failed(_frame->runner()->flush(_frame->creators_ptr())))
123 {199 {
124 Error << "frame->runner()->flush(creators_ptr)";200 Error << "frame->runner()->flush(creators_ptr)";
125 _skipped++;201 skip();
126 formatter()->skipped();
127 continue;202 continue;
128 }203 }
129 }204 }
@@ -132,7 +207,7 @@
132207
133 try 208 try
134 {209 {
135 return_code= runner_code(_frame, run, _timer);210 return_code= runner_code(_frame, (*case_iter)->test(), _timer);
136 }211 }
137 catch (...)212 catch (...)
138 {213 {
@@ -145,26 +220,22 @@
145 catch (const libtest::fatal& e)220 catch (const libtest::fatal& e)
146 {221 {
147 stream::cerr(e.file(), e.line(), e.func()) << e.what();222 stream::cerr(e.file(), e.line(), e.func()) << e.what();
148 _failed++;223 fail();
149 formatter()->failed();
150 throw;224 throw;
151 }225 }
152226
153 switch (return_code)227 switch (return_code)
154 {228 {
155 case TEST_SUCCESS:229 case TEST_SUCCESS:
156 _success++;230 succeess();
157 formatter()->success(_timer);
158 break;231 break;
159232
160 case TEST_FAILURE:233 case TEST_FAILURE:
161 _failed++;234 fail();
162 formatter()->failed();
163 break;235 break;
164236
165 case TEST_SKIPPED:237 case TEST_SKIPPED:
166 _skipped++;238 skip();
167 formatter()->skipped();
168 break;239 break;
169240
170 default:241 default:
@@ -180,17 +251,17 @@
180251
181 if (_failed == 0 and _skipped == 0 and _success)252 if (_failed == 0 and _skipped == 0 and _success)
182 {253 {
183 return TEST_SUCCESS;254 _ret= TEST_SUCCESS;
184 }255 }
185256 else if (_failed)
186 if (_failed)
187 {257 {
188 return TEST_FAILURE;258 _ret= TEST_FAILURE;
189 }259 }
190260
191 fatal_assert(_skipped or _success == 0);261 // Complete any headers required by formatting.
262 complete();
192263
193 return TEST_SKIPPED;264 return _ret;
194}265}
195266
196} // namespace libtest267} // namespace libtest
197268
=== modified file 'libtest/collection.h'
--- libtest/collection.h 2013-01-10 12:05:49 +0000
+++ libtest/collection.h 2013-07-02 18:24:29 +0000
@@ -58,41 +58,52 @@
58class Collection {58class Collection {
59public:59public:
60 Collection(libtest::Framework*, collection_st*);60 Collection(libtest::Framework*, collection_st*);
61 ~Collection();
6162
62 test_return_t exec();63 test_return_t exec();
6364
64 const char* name()65 const char* name() const
65 {66 {
66 return _name.c_str();67 return _name.c_str();
67 }68 }
6869
69 uint32_t success()70 void succeess();
71
72 void skip();
73
74 void fail();
75
76 uint32_t succeeded() const
70 {77 {
71 return _success;78 return _success;
72 }79 }
7380
74 uint32_t skipped()81 uint32_t skipped() const
75 {82 {
76 return _skipped;83 return _skipped;
77 }84 }
7885
79 uint32_t failed()86 uint32_t failed() const
80 {87 {
81 return _failed;88 return _failed;
82 }89 }
8390
84 uint32_t total()91 void format();
85 {92
86 return _total;93 size_t total() const
87 }94 {
8895 return _testcases.size();
89 libtest::Formatter* formatter()96 }
90 {97
91 return &_formatter;98 void plan();
92 }99 void complete();
100
101private:
102 void push_testcase(const test_st* test_);
93103
94private:104private:
95 std::string _name;105 std::string _name;
106 test_return_t _ret;
96 test_callback_fn *_pre;107 test_callback_fn *_pre;
97 test_callback_fn *_post;108 test_callback_fn *_post;
98 struct test_st *_tests;109 struct test_st *_tests;
@@ -100,9 +111,10 @@
100 uint32_t _success;111 uint32_t _success;
101 uint32_t _skipped;112 uint32_t _skipped;
102 uint32_t _failed;113 uint32_t _failed;
103 uint32_t _total;
104 libtest::Timer _timer;114 libtest::Timer _timer;
105 libtest::Formatter _formatter;115 libtest::Formatters& _formatter;
116 TestCases _testcases;
117 TestCases::iterator case_iter;
106118
107private:119private:
108 Collection( const Collection& );120 Collection( const Collection& );
109121
=== modified file 'libtest/formatter.cc'
--- libtest/formatter.cc 2013-01-04 00:19:53 +0000
+++ libtest/formatter.cc 2013-07-02 18:24:29 +0000
@@ -44,101 +44,190 @@
44 44
45namespace libtest {45namespace libtest {
4646
47class TestCase {47Formatter::Formatter(const Framework* frame_, std::ostream& output_):
48public:48 _frame(frame_),
49 TestCase(const std::string& arg):49 _output(output_)
50 _name(arg),50{
51 _result(TEST_FAILURE)51}
52 {52
53 }53const std::string& Formatter::name() const
5454{
55 const std::string& name() const55 return _frame->name();
56 {56}
57 return _name;57
58 }58Legacy::Legacy(const Framework* frame_, std::ostream& output_):
5959 Formatter(frame_, output_),
60 test_return_t result() const60 _collection(NULL)
61 {61{
62 return _result;62}
63 }63
6464
65 void result(test_return_t arg)65Legacy::~Legacy()
66 {66{
67 _result= arg;67 if (getenv("YATL_SUMMARY"))
68 }68 {
6969 Outn();
70 void result(test_return_t arg, const libtest::Timer& timer_)70 Out << "Tests\t\t\t\t\t" << _frame->total();
71 {71 Out << "\tFailed\t\t\t\t\t" << _frame->failed();
72 _result= arg;72 Out << "\tSkipped\t\t\t\t\t" << _frame->skipped();
73 _timer= timer_;73 Out << "\tSucceeded\t\t\t\t" << _frame->success();
74 }74 }
7575}
76 const libtest::Timer& timer() const76
77 {77void Legacy::plan(const Collection* collection)
78 return _timer;78{
79 }79 _collection= collection;
8080}
81 void timer(libtest::Timer& arg)81
82 {82void Legacy::report(const libtest::TestCase* test, size_t) const
83 _timer= arg;83{
84 }84 switch (test->result())
8585 {
86private:86 case TEST_SUCCESS:
87 std::string _name;87 Out << name() << "."
88 test_return_t _result;88 << _collection->name() << "."
89 libtest::Timer _timer;89 << test->name()
90};90 << "\t\t\t\t\t"
9191 << test->timer()
92Formatter::Formatter(const std::string& frame_name, const std::string& arg)92 << " [ " << test_strerror(test->result()) << " ]";
93{93 break;
94 _suite_name= frame_name;94
95 _suite_name+= ".";95 case TEST_FAILURE:
96 _suite_name+= arg;96 Out << name() << "."
97}97 << _collection->name() << "."
9898 << test->name()
99Formatter::~Formatter()99 << "\t\t\t\t\t" << "[ " << test_strerror(test->result()) << " ]";
100{100 break;
101 std::for_each(_testcases.begin(), _testcases.end(), DeleteFromVector());101
102 _testcases.clear();102 case TEST_SKIPPED:
103}103 Out << name() << "."
104104 << _collection->name() << "."
105TestCase* Formatter::current()105 << test->name()
106{106 << "\t\t\t\t\t" << "[ " << test_strerror(test->result()) << " ]";
107 return _testcases.back();107 break;
108}108 }
109109}
110void Formatter::skipped()110
111{111Junit::Junit(const Framework* frame_, std::ostream& output_):
112 current()->result(TEST_SKIPPED);112 Formatter(frame_, output_)
113 Out << name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";113{
114114 _output << "<testsuites name=\"" << name() << "\">" << std::endl;
115 reset();115}
116}116
117117Junit::~Junit()
118void Formatter::failed()118{
119{119 _output << "</testsuites>" << std::endl;
120 assert(current());120}
121 current()->result(TEST_FAILURE);121
122122void Junit::report(const libtest::TestCase* test, size_t) const
123 Out << name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";123{
124124 _output << "\t\t<testcase name=\""
125 reset();125 << test->name()
126}126 << "\" time=\""
127127 << test->timer().elapsed_milliseconds()
128void Formatter::success(const libtest::Timer& timer_)128 << "\">"
129{129 << std::endl;
130 assert(current());130
131 current()->result(TEST_SUCCESS, timer_);131 switch (test->result())
132132 {
133 Out << name() << "."133 case TEST_SKIPPED:
134 << current()->name()134 _output << "\t\t <skipped/>" << std::endl;
135 << "\t\t\t\t\t" 135 break;
136 << current()->timer() 136
137 << " [ " << test_strerror(current()->result()) << " ]";137 case TEST_FAILURE:
138138 _output << "\t\t <failure message=\"\" type=\"\"/>"<< std::endl;
139 reset();139 break;
140}140
141141 case TEST_SUCCESS:
142 break;
143 }
144 _output << "\t\t</testcase>" << std::endl;
145}
146
147void Junit::plan(const Collection* collection)
148{
149 _output << "\t<testsuite name=\"" << collection->name() << "\" classname=\"\" package=\"\">" << std::endl;
150}
151
152void Junit::complete()
153{
154 _output << "\t</testsuite>" << std::endl;
155}
156
157TAP::TAP(const Framework* frame_, std::ostream& output_):
158 Formatter(frame_, output_)
159{
160}
161
162TAP::~TAP()
163{
164}
165
166void TAP::report(const libtest::TestCase* test, size_t position) const
167{
168 assert(test);
169 switch (test->result())
170 {
171 case TEST_SUCCESS:
172 _output << "ok " << position << " - " << test->name() << " # ";
173 _output << test->timer().elapsed_milliseconds();
174 break;
175
176 case TEST_FAILURE:
177 _output << "not ok " << position << " - " << test->name() << " # ";
178 break;
179
180 case TEST_SKIPPED:
181 _output << "ok " << position << " - # SKIP ";
182 break;
183 }
184
185 _output << std::endl;
186}
187
188void TAP::plan(const Collection* collection)
189{
190 _output << "0.." << collection->total() << std::endl;
191}
192
193#if 0
194void Formatter::tap(libtest::Framework& framework_, std::ofstream& output)
195{
196 for (Suites::iterator framework_iter= framework_.suites().begin();
197 framework_iter != framework_.suites().end();
198 ++framework_iter)
199 {
200 output << "1.." << (*framework_iter)->formatter()->testcases().size() << " # " << (*framework_iter)->name() << std::endl;
201
202 size_t test_count= 1;
203 for (TestCases::iterator case_iter= (*framework_iter)->formatter()->testcases().begin();
204 case_iter != (*framework_iter)->formatter()->testcases().end();
205 ++case_iter)
206 {
207 switch ((*case_iter)->result())
208 {
209 case TEST_SKIPPED:
210 output << "ok " << test_count << " - # SKIP ";
211 break;
212
213 case TEST_FAILURE:
214 output << "not ok " << test_count << " - " << (*case_iter)->name() << " # ";
215 break;
216
217 case TEST_SUCCESS:
218 output << "ok " << test_count << " - " << (*case_iter)->name() << " # ";
219 break;
220 }
221
222 output
223 << (*case_iter)->timer().elapsed_milliseconds()
224 << std::endl;
225 }
226 }
227}
228#endif
229
230#if 0
142void Formatter::xml(libtest::Framework& framework_, std::ofstream& output)231void Formatter::xml(libtest::Framework& framework_, std::ofstream& output)
143{232{
144 output << "<testsuites name=\"" << framework_.name() << "\">" << std::endl;233 output << "<testsuites name=\"" << framework_.name() << "\">" << std::endl;
@@ -178,15 +267,6 @@
178 }267 }
179 output << "</testsuites>" << std::endl;268 output << "</testsuites>" << std::endl;
180}269}
181270#endif
182void Formatter::push_testcase(const std::string& arg)271
183{
184 assert(_suite_name.empty() == false);
185 TestCase* _current_testcase= new TestCase(arg);
186 _testcases.push_back(_current_testcase);
187}
188
189void Formatter::reset()
190{
191}
192} // namespace libtest272} // namespace libtest
193273
=== modified file 'libtest/formatter.hpp'
--- libtest/formatter.hpp 2012-12-10 09:06:07 +0000
+++ libtest/formatter.hpp 2013-07-02 18:24:29 +0000
@@ -43,43 +43,69 @@
4343
44namespace libtest {44namespace libtest {
4545
46class TestCase;46class Collection;
47typedef std::vector<libtest::TestCase*> TestCases;47
48class Formatter;
49typedef std::vector<libtest::Formatter*> Formatters;
4850
49class Formatter {51class Formatter {
50public:52public:
51 Formatter(const std::string& frame_name, const std::string& arg);53 Formatter(const Framework* frame_, std::ostream&);
5254
53 ~Formatter();55 virtual ~Formatter() {}
5456
55 void skipped();57 virtual void plan(const libtest::Collection*) {}
5658 virtual void report(const libtest::TestCase*, size_t) const {}
57 void failed();59 virtual void complete() {}
5860
59 void success(const libtest::Timer&);61protected:
6062 const std::string& name() const;
61 void push_testcase(const std::string&);63
6264#if 0
63 const std::string& name() const
64 {
65 return _suite_name;
66 }
67
68 TestCases& testcases()
69 {
70 return _testcases;
71 }
72
73 static void xml(libtest::Framework&, std::ofstream&);65 static void xml(libtest::Framework&, std::ofstream&);
7466 static void tap(libtest::Framework&, std::ofstream&);
75private:67#endif
76 void reset();68
7769protected:
78 TestCase* current();70 const Framework* _frame;
7971
80private:72protected:
81 std::string _suite_name;73 std::ostream& _output;
82 TestCases _testcases;74};
75
76class Junit : public Formatter
77{
78public:
79 Junit(const Framework*, std::ostream&);
80 ~Junit();
81
82 void report(const libtest::TestCase*, size_t position) const;
83
84 void plan(const libtest::Collection*);
85 void complete();
86};
87
88class TAP : public Formatter
89{
90public:
91 TAP(const Framework*, std::ostream&);
92 ~TAP();
93
94 void plan(const libtest::Collection*);
95 void report(const libtest::TestCase*, size_t position) const;
96};
97
98class Legacy : public Formatter
99{
100public:
101 Legacy(const Framework*, std::ostream&);
102 ~Legacy();
103
104 void plan(const libtest::Collection*);
105 void report(const libtest::TestCase*, size_t position) const;
106
107private:
108 const libtest::Collection* _collection;
83};109};
84110
85} // namespace libtest111} // namespace libtest
86112
=== modified file 'libtest/framework.cc'
--- libtest/framework.cc 2013-05-03 08:41:20 +0000
+++ libtest/framework.cc 2013-07-02 18:24:29 +0000
@@ -125,6 +125,33 @@
125 _name(name_)125 _name(name_)
126{126{
127 get_world(this);127 get_world(this);
128
129 {
130 std::string file_name;
131 if (getenv("WORKSPACE"))
132 {
133 file_name.append(getenv("WORKSPACE"));
134 file_name.append("/");
135 }
136 file_name.append(name());
137 file_name.append(".xml");
138 xml_file.open(file_name.c_str(), std::ios::trunc);
139 _formatter.push_back(new libtest::Junit(this, xml_file));
140 }
141
142 {
143 std::string file_name;
144 if (getenv("WORKSPACE"))
145 {
146 file_name.append(getenv("WORKSPACE"));
147 file_name.append("/");
148 }
149 file_name.append(name());
150 file_name.append(".tap");
151 tap_file.open(file_name.c_str(), std::ios::trunc);
152 _formatter.push_back(new libtest::TAP(this, tap_file));
153 }
154 _formatter.push_back(new libtest::Legacy(this, std::cout));
128}155}
129156
130void Framework::collections(collection_st collections_[])157void Framework::collections(collection_st collections_[])
@@ -148,6 +175,9 @@
148175
149 std::for_each(_collection.begin(), _collection.end(), DeleteFromVector());176 std::for_each(_collection.begin(), _collection.end(), DeleteFromVector());
150 _collection.clear();177 _collection.clear();
178
179 std::for_each(_formatter.begin(), _formatter.end(), DeleteFromVector());
180 _formatter.clear();
151}181}
152182
153bool Framework::match(const char* arg)183bool Framework::match(const char* arg)
@@ -232,58 +262,6 @@
232 }262 }
233}263}
234264
235uint32_t Framework::sum_total()
236{
237 uint32_t count= 0;
238 for (std::vector<Collection*>::iterator iter= _collection.begin();
239 iter != _collection.end();
240 ++iter)
241 {
242 count+= (*iter)->total();
243 }
244
245 return count;
246}
247
248uint32_t Framework::sum_success()
249{
250 uint32_t count= 0;
251 for (std::vector<Collection*>::iterator iter= _collection.begin();
252 iter != _collection.end();
253 ++iter)
254 {
255 count+= (*iter)->success();
256 }
257
258 return count;
259}
260
261uint32_t Framework::sum_skipped()
262{
263 uint32_t count= 0;
264 for (std::vector<Collection*>::iterator iter= _collection.begin();
265 iter != _collection.end();
266 ++iter)
267 {
268 count+= (*iter)->skipped();
269 }
270
271 return count;
272}
273
274uint32_t Framework::sum_failed()
275{
276 uint32_t count= 0;
277 for (std::vector<Collection*>::iterator iter= _collection.begin();
278 iter != _collection.end();
279 ++iter)
280 {
281 count+= (*iter)->failed();
282 }
283
284 return count;
285}
286
287libtest::Runner *Framework::runner()265libtest::Runner *Framework::runner()
288{266{
289 if (_runner == NULL)267 if (_runner == NULL)
290268
=== modified file 'libtest/framework.h'
--- libtest/framework.h 2013-05-03 06:03:28 +0000
+++ libtest/framework.h 2013-07-02 18:24:29 +0000
@@ -2,7 +2,7 @@
2 *2 *
3 * Data Differential YATL (i.e. libtest) library3 * Data Differential YATL (i.e. libtest) library
4 *4 *
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/5 * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
6 *6 *
7 * Redistribution and use in source and binary forms, with or without7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are8 * modification, are permitted provided that the following conditions are
@@ -45,6 +45,7 @@
45*/45*/
4646
47#include <vector>47#include <vector>
48#include <fstream>
4849
49namespace { class Collection; }50namespace { class Collection; }
50typedef std::vector<libtest::Collection*> Suites;51typedef std::vector<libtest::Collection*> Suites;
@@ -126,47 +127,48 @@
126 return _signal;127 return _signal;
127 }128 }
128129
129 uint32_t sum_total();
130 uint32_t sum_success();
131 uint32_t sum_skipped();
132 uint32_t sum_failed();
133
134 size_t size() 130 size_t size()
135 {131 {
136 return _collection.size();132 return _collection.size();
137 }133 }
138134
139 uint32_t total() const135 Suites& suites()
136 {
137 return _collection;
138 }
139
140 libtest::Formatters& formatter()
141 {
142 return _formatter;
143 }
144
145 size_t total() const
140 {146 {
141 return _total;147 return _total;
142 }148 }
143149
144 uint32_t success() const150 size_t success() const
145 {151 {
146 return _success;152 return _success;
147 }153 }
148154
149 uint32_t skipped() const155 size_t skipped() const
150 {156 {
151 return _skipped;157 return _skipped;
152 }158 }
153159
154 uint32_t failed() const160 size_t failed() const
155 {161 {
156 return _failed;162 return _failed;
157 }163 }
158164
159 Suites& suites()
160 {
161 return _collection;
162 }
163
164private:165private:
165 uint32_t _total;166 // Sums
166 uint32_t _success;167 size_t _total;
167 uint32_t _skipped;168 size_t _success;
168 uint32_t _failed;169 size_t _skipped;
169 170 size_t _failed;
171
170 /* These methods are called outside of any collection call. */172 /* These methods are called outside of any collection call. */
171 test_callback_create_fn *_create;173 test_callback_create_fn *_create;
172 test_callback_destroy_fn *_destroy;174 test_callback_destroy_fn *_destroy;
@@ -195,6 +197,10 @@
195private:197private:
196 Framework( const Framework& );198 Framework( const Framework& );
197 const Framework& operator=( const Framework& );199 const Framework& operator=( const Framework& );
200 libtest::Formatters _formatter;
201 std::ofstream xml_file;
202 std::ofstream tap_file;
203
198};204};
199205
200} // namespace libtest206} // namespace libtest
201207
=== modified file 'libtest/main.cc'
--- libtest/main.cc 2013-06-28 19:13:48 +0000
+++ libtest/main.cc 2013-07-02 18:24:29 +0000
@@ -60,25 +60,6 @@
6060
61using namespace libtest;61using namespace libtest;
6262
63static void stats_print(libtest::Framework *frame)
64{
65 if (frame->failed() == 0 and frame->success() == 0)
66 {
67 return;
68 }
69
70 Outn();
71 Out << "Collections\t\t\t\t\t" << frame->total();
72 Out << "\tFailed\t\t\t\t\t" << frame->failed();
73 Out << "\tSkipped\t\t\t\t\t" << frame->skipped();
74 Out << "\tSucceeded\t\t\t\t" << frame->success();
75 Outn();
76 Out << "Tests\t\t\t\t\t" << frame->sum_total();
77 Out << "\tFailed\t\t\t\t" << frame->sum_failed();
78 Out << "\tSkipped\t\t\t\t" << frame->sum_skipped();
79 Out << "\tSucceeded\t\t\t" << frame->sum_success();
80}
81
82#include <getopt.h>63#include <getopt.h>
83#include <unistd.h>64#include <unistd.h>
8465
@@ -380,19 +361,37 @@
380 Out << "All tests completed successfully.";361 Out << "All tests completed successfully.";
381 }362 }
382363
383 stats_print(frame.get());364#if 0
365 {
366 std::ofstream xml_file;
367 std::string file_name;
368 if (getenv("WORKSPACE"))
369 {
370 file_name.append(getenv("WORKSPACE"));
371 file_name.append("/");
372 }
373 file_name.append(frame->name());
374 file_name.append(".xml");
375 xml_file.open(file_name.c_str(), std::ios::trunc);
376 libtest::Formatter::xml(*frame, xml_file);
377 }
378#endif
384379
385 std::ofstream xml_file;380#if 0
386 std::string file_name;
387 if (getenv("WORKSPACE"))
388 {381 {
389 file_name.append(getenv("WORKSPACE"));382 std::ofstream tap_file;
390 file_name.append("/");383 std::string file_name;
384 if (getenv("WORKSPACE"))
385 {
386 file_name.append(getenv("WORKSPACE"));
387 file_name.append("/");
388 }
389 file_name.append(frame->name());
390 file_name.append(".tap");
391 tap_file.open(file_name.c_str(), std::ios::trunc);
392 libtest::Formatter::tap(*frame, tap_file);
391 }393 }
392 file_name.append(frame->name());394#endif
393 file_name.append(".xml");
394 xml_file.open(file_name.c_str(), std::ios::trunc);
395 libtest::Formatter::xml(*frame, xml_file);
396395
397 Outn(); // Generate a blank to break up the messages if make check/test has been run396 Outn(); // Generate a blank to break up the messages if make check/test has been run
398 } while (exit_code == EXIT_SUCCESS and --opt_repeat);397 } while (exit_code == EXIT_SUCCESS and --opt_repeat);
399398
=== modified file 'libtest/test.h'
--- libtest/test.h 2012-12-31 11:03:44 +0000
+++ libtest/test.h 2013-07-02 18:24:29 +0000
@@ -51,6 +51,86 @@
51 test_callback_fn *test_fn;51 test_callback_fn *test_fn;
52};52};
5353
54namespace libtest {
55
56class TestCase;
57typedef std::vector<libtest::TestCase*> TestCases;
58
59class TestCase {
60public:
61 TestCase(const struct test_st* test_):
62 _result(TEST_FAILURE)
63 {
64 _test.name= test_->name;
65 _test.requires_flush= test_->requires_flush;
66 _test.test_fn= test_->test_fn;
67 }
68
69 const char* name() const
70 {
71 return _test.name;
72 }
73
74 test_return_t result() const
75 {
76 return _result;
77 }
78
79 void result(test_return_t result_)
80 {
81 _result= result_;
82 }
83
84 void result(test_return_t result_, const libtest::Timer& timer_)
85 {
86 _result= result_;
87 _timer= timer_;
88 }
89
90 const libtest::Timer& timer() const
91 {
92 return _timer;
93 }
94
95 void timer(libtest::Timer& timer_)
96 {
97 _timer= timer_;
98 }
99
100 void skipped()
101 {
102 _result= TEST_SKIPPED;
103 }
104
105 void failed()
106 {
107 _result= TEST_FAILURE;
108 }
109
110 void success(const libtest::Timer& timer_)
111 {
112 _result= TEST_SUCCESS;
113 _timer= timer_;
114 }
115
116
117 const struct test_st* test() const
118 {
119 return &_test;
120 }
121
122 bool requires_flush() const
123 {
124 return _test.requires_flush;
125 }
126
127private:
128 struct test_st _test;
129 test_return_t _result;
130 libtest::Timer _timer;
131};
132} // namespace libtest
133
54#define test_assert_errno(A) \134#define test_assert_errno(A) \
55do \135do \
56{ \136{ \

Subscribers

People subscribed via source and target branches

to all changes: