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
1=== modified file 'libtest/collection.cc'
2--- libtest/collection.cc 2013-05-03 08:41:20 +0000
3+++ libtest/collection.cc 2013-07-02 18:24:29 +0000
4@@ -38,9 +38,11 @@
5
6 #include <libtest/common.h>
7
8+#include <algorithm>
9+
10 // @todo possibly have this code fork off so if it fails nothing goes bad
11 static test_return_t runner_code(libtest::Framework* frame,
12- test_st* run,
13+ const struct test_st* run,
14 libtest::Timer& _timer)
15 { // Runner Code
16
17@@ -84,46 +86,119 @@
18
19 namespace libtest {
20
21-Collection::Collection(Framework* frame_arg,
22- collection_st* arg) :
23- _name(arg->name),
24- _pre(arg->pre),
25- _post(arg->post),
26- _tests(arg->tests),
27- _frame(frame_arg),
28+Collection::Collection(Framework* frame_,
29+ collection_st* tests_) :
30+ _name(tests_->name),
31+ _ret(TEST_SKIPPED),
32+ _pre(tests_->pre),
33+ _post(tests_->post),
34+ _tests(tests_->tests),
35+ _frame(frame_),
36 _success(0),
37 _skipped(0),
38 _failed(0),
39- _total(0),
40- _formatter(frame_arg->name(), _name)
41-{
42- fatal_assert(arg);
43+ _formatter(frame_->formatter())
44+{
45+ fatal_assert(tests_);
46+ for (const test_st *run= _tests; run->name; run++)
47+ {
48+ push_testcase(run);
49+ }
50+
51+ case_iter= _testcases.begin();
52+}
53+
54+Collection::~Collection()
55+{
56+ std::for_each(_testcases.begin(), _testcases.end(), DeleteFromVector());
57+ _testcases.clear();
58+
59+ std::for_each(_formatter.begin(), _formatter.end(), DeleteFromVector());
60+ _formatter.clear();
61+}
62+
63+void Collection::push_testcase(const test_st* test_)
64+{
65+ TestCase* _current_testcase= new TestCase(test_);
66+ _testcases.push_back(_current_testcase);
67+}
68+
69+void Collection::format()
70+{
71+ for (Formatters::iterator format_iter= _formatter.begin();
72+ format_iter != _formatter.end();
73+ ++format_iter)
74+ {
75+ (*format_iter)->report((*case_iter), std::distance(_testcases.begin(), case_iter));
76+ }
77+}
78+
79+void Collection::plan()
80+{
81+ for (Formatters::iterator format_iter= _formatter.begin();
82+ format_iter != _formatter.end();
83+ ++format_iter)
84+ {
85+ (*format_iter)->plan(this);
86+ }
87+}
88+
89+void Collection::complete()
90+{
91+ for (Formatters::iterator format_iter= _formatter.begin();
92+ format_iter != _formatter.end();
93+ ++format_iter)
94+ {
95+ (*format_iter)->complete();
96+ }
97+}
98+
99+void Collection::succeess()
100+{
101+ _success++;
102+ (*case_iter)->success(_timer);
103+ format();
104+}
105+
106+void Collection::skip()
107+{
108+ _skipped++;
109+ (*case_iter)->skipped();
110+ format();
111+}
112+
113+void Collection::fail()
114+{
115+ _failed++;
116+ (*case_iter)->failed();
117+ format();
118 }
119
120 test_return_t Collection::exec()
121 {
122+ // Write out any headers required by formatting.
123+ plan();
124+
125 if (test_success(_frame->runner()->setup(_pre, _frame->creators_ptr())))
126 {
127- for (test_st *run= _tests; run->name; run++)
128+ for (; case_iter != _testcases.end();
129+ ++case_iter)
130 {
131- formatter()->push_testcase(run->name);
132- if (_frame->match(run->name))
133+ if (_frame->match((*case_iter)->name()))
134 {
135- formatter()->skipped();
136+ skip();
137 continue;
138 }
139- _total++;
140
141 test_return_t return_code;
142 try
143 {
144- if (run->requires_flush)
145+ if ((*case_iter)->requires_flush())
146 {
147 if (test_failed(_frame->runner()->flush(_frame->creators_ptr())))
148 {
149 Error << "frame->runner()->flush(creators_ptr)";
150- _skipped++;
151- formatter()->skipped();
152+ skip();
153 continue;
154 }
155 }
156@@ -132,7 +207,7 @@
157
158 try
159 {
160- return_code= runner_code(_frame, run, _timer);
161+ return_code= runner_code(_frame, (*case_iter)->test(), _timer);
162 }
163 catch (...)
164 {
165@@ -145,26 +220,22 @@
166 catch (const libtest::fatal& e)
167 {
168 stream::cerr(e.file(), e.line(), e.func()) << e.what();
169- _failed++;
170- formatter()->failed();
171+ fail();
172 throw;
173 }
174
175 switch (return_code)
176 {
177 case TEST_SUCCESS:
178- _success++;
179- formatter()->success(_timer);
180+ succeess();
181 break;
182
183 case TEST_FAILURE:
184- _failed++;
185- formatter()->failed();
186+ fail();
187 break;
188
189 case TEST_SKIPPED:
190- _skipped++;
191- formatter()->skipped();
192+ skip();
193 break;
194
195 default:
196@@ -180,17 +251,17 @@
197
198 if (_failed == 0 and _skipped == 0 and _success)
199 {
200- return TEST_SUCCESS;
201+ _ret= TEST_SUCCESS;
202 }
203-
204- if (_failed)
205+ else if (_failed)
206 {
207- return TEST_FAILURE;
208+ _ret= TEST_FAILURE;
209 }
210
211- fatal_assert(_skipped or _success == 0);
212+ // Complete any headers required by formatting.
213+ complete();
214
215- return TEST_SKIPPED;
216+ return _ret;
217 }
218
219 } // namespace libtest
220
221=== modified file 'libtest/collection.h'
222--- libtest/collection.h 2013-01-10 12:05:49 +0000
223+++ libtest/collection.h 2013-07-02 18:24:29 +0000
224@@ -58,41 +58,52 @@
225 class Collection {
226 public:
227 Collection(libtest::Framework*, collection_st*);
228+ ~Collection();
229
230 test_return_t exec();
231
232- const char* name()
233+ const char* name() const
234 {
235 return _name.c_str();
236 }
237
238- uint32_t success()
239+ void succeess();
240+
241+ void skip();
242+
243+ void fail();
244+
245+ uint32_t succeeded() const
246 {
247 return _success;
248 }
249
250- uint32_t skipped()
251+ uint32_t skipped() const
252 {
253 return _skipped;
254 }
255
256- uint32_t failed()
257+ uint32_t failed() const
258 {
259 return _failed;
260 }
261
262- uint32_t total()
263- {
264- return _total;
265- }
266-
267- libtest::Formatter* formatter()
268- {
269- return &_formatter;
270- }
271+ void format();
272+
273+ size_t total() const
274+ {
275+ return _testcases.size();
276+ }
277+
278+ void plan();
279+ void complete();
280+
281+private:
282+ void push_testcase(const test_st* test_);
283
284 private:
285 std::string _name;
286+ test_return_t _ret;
287 test_callback_fn *_pre;
288 test_callback_fn *_post;
289 struct test_st *_tests;
290@@ -100,9 +111,10 @@
291 uint32_t _success;
292 uint32_t _skipped;
293 uint32_t _failed;
294- uint32_t _total;
295 libtest::Timer _timer;
296- libtest::Formatter _formatter;
297+ libtest::Formatters& _formatter;
298+ TestCases _testcases;
299+ TestCases::iterator case_iter;
300
301 private:
302 Collection( const Collection& );
303
304=== modified file 'libtest/formatter.cc'
305--- libtest/formatter.cc 2013-01-04 00:19:53 +0000
306+++ libtest/formatter.cc 2013-07-02 18:24:29 +0000
307@@ -44,101 +44,190 @@
308
309 namespace libtest {
310
311-class TestCase {
312-public:
313- TestCase(const std::string& arg):
314- _name(arg),
315- _result(TEST_FAILURE)
316- {
317- }
318-
319- const std::string& name() const
320- {
321- return _name;
322- }
323-
324- test_return_t result() const
325- {
326- return _result;
327- }
328-
329- void result(test_return_t arg)
330- {
331- _result= arg;
332- }
333-
334- void result(test_return_t arg, const libtest::Timer& timer_)
335- {
336- _result= arg;
337- _timer= timer_;
338- }
339-
340- const libtest::Timer& timer() const
341- {
342- return _timer;
343- }
344-
345- void timer(libtest::Timer& arg)
346- {
347- _timer= arg;
348- }
349-
350-private:
351- std::string _name;
352- test_return_t _result;
353- libtest::Timer _timer;
354-};
355-
356-Formatter::Formatter(const std::string& frame_name, const std::string& arg)
357-{
358- _suite_name= frame_name;
359- _suite_name+= ".";
360- _suite_name+= arg;
361-}
362-
363-Formatter::~Formatter()
364-{
365- std::for_each(_testcases.begin(), _testcases.end(), DeleteFromVector());
366- _testcases.clear();
367-}
368-
369-TestCase* Formatter::current()
370-{
371- return _testcases.back();
372-}
373-
374-void Formatter::skipped()
375-{
376- current()->result(TEST_SKIPPED);
377- Out << name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";
378-
379- reset();
380-}
381-
382-void Formatter::failed()
383-{
384- assert(current());
385- current()->result(TEST_FAILURE);
386-
387- Out << name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";
388-
389- reset();
390-}
391-
392-void Formatter::success(const libtest::Timer& timer_)
393-{
394- assert(current());
395- current()->result(TEST_SUCCESS, timer_);
396-
397- Out << name() << "."
398- << current()->name()
399- << "\t\t\t\t\t"
400- << current()->timer()
401- << " [ " << test_strerror(current()->result()) << " ]";
402-
403- reset();
404-}
405-
406+Formatter::Formatter(const Framework* frame_, std::ostream& output_):
407+ _frame(frame_),
408+ _output(output_)
409+{
410+}
411+
412+const std::string& Formatter::name() const
413+{
414+ return _frame->name();
415+}
416+
417+Legacy::Legacy(const Framework* frame_, std::ostream& output_):
418+ Formatter(frame_, output_),
419+ _collection(NULL)
420+{
421+}
422+
423+
424+Legacy::~Legacy()
425+{
426+ if (getenv("YATL_SUMMARY"))
427+ {
428+ Outn();
429+ Out << "Tests\t\t\t\t\t" << _frame->total();
430+ Out << "\tFailed\t\t\t\t\t" << _frame->failed();
431+ Out << "\tSkipped\t\t\t\t\t" << _frame->skipped();
432+ Out << "\tSucceeded\t\t\t\t" << _frame->success();
433+ }
434+}
435+
436+void Legacy::plan(const Collection* collection)
437+{
438+ _collection= collection;
439+}
440+
441+void Legacy::report(const libtest::TestCase* test, size_t) const
442+{
443+ switch (test->result())
444+ {
445+ case TEST_SUCCESS:
446+ Out << name() << "."
447+ << _collection->name() << "."
448+ << test->name()
449+ << "\t\t\t\t\t"
450+ << test->timer()
451+ << " [ " << test_strerror(test->result()) << " ]";
452+ break;
453+
454+ case TEST_FAILURE:
455+ Out << name() << "."
456+ << _collection->name() << "."
457+ << test->name()
458+ << "\t\t\t\t\t" << "[ " << test_strerror(test->result()) << " ]";
459+ break;
460+
461+ case TEST_SKIPPED:
462+ Out << name() << "."
463+ << _collection->name() << "."
464+ << test->name()
465+ << "\t\t\t\t\t" << "[ " << test_strerror(test->result()) << " ]";
466+ break;
467+ }
468+}
469+
470+Junit::Junit(const Framework* frame_, std::ostream& output_):
471+ Formatter(frame_, output_)
472+{
473+ _output << "<testsuites name=\"" << name() << "\">" << std::endl;
474+}
475+
476+Junit::~Junit()
477+{
478+ _output << "</testsuites>" << std::endl;
479+}
480+
481+void Junit::report(const libtest::TestCase* test, size_t) const
482+{
483+ _output << "\t\t<testcase name=\""
484+ << test->name()
485+ << "\" time=\""
486+ << test->timer().elapsed_milliseconds()
487+ << "\">"
488+ << std::endl;
489+
490+ switch (test->result())
491+ {
492+ case TEST_SKIPPED:
493+ _output << "\t\t <skipped/>" << std::endl;
494+ break;
495+
496+ case TEST_FAILURE:
497+ _output << "\t\t <failure message=\"\" type=\"\"/>"<< std::endl;
498+ break;
499+
500+ case TEST_SUCCESS:
501+ break;
502+ }
503+ _output << "\t\t</testcase>" << std::endl;
504+}
505+
506+void Junit::plan(const Collection* collection)
507+{
508+ _output << "\t<testsuite name=\"" << collection->name() << "\" classname=\"\" package=\"\">" << std::endl;
509+}
510+
511+void Junit::complete()
512+{
513+ _output << "\t</testsuite>" << std::endl;
514+}
515+
516+TAP::TAP(const Framework* frame_, std::ostream& output_):
517+ Formatter(frame_, output_)
518+{
519+}
520+
521+TAP::~TAP()
522+{
523+}
524+
525+void TAP::report(const libtest::TestCase* test, size_t position) const
526+{
527+ assert(test);
528+ switch (test->result())
529+ {
530+ case TEST_SUCCESS:
531+ _output << "ok " << position << " - " << test->name() << " # ";
532+ _output << test->timer().elapsed_milliseconds();
533+ break;
534+
535+ case TEST_FAILURE:
536+ _output << "not ok " << position << " - " << test->name() << " # ";
537+ break;
538+
539+ case TEST_SKIPPED:
540+ _output << "ok " << position << " - # SKIP ";
541+ break;
542+ }
543+
544+ _output << std::endl;
545+}
546+
547+void TAP::plan(const Collection* collection)
548+{
549+ _output << "0.." << collection->total() << std::endl;
550+}
551+
552+#if 0
553+void Formatter::tap(libtest::Framework& framework_, std::ofstream& output)
554+{
555+ for (Suites::iterator framework_iter= framework_.suites().begin();
556+ framework_iter != framework_.suites().end();
557+ ++framework_iter)
558+ {
559+ output << "1.." << (*framework_iter)->formatter()->testcases().size() << " # " << (*framework_iter)->name() << std::endl;
560+
561+ size_t test_count= 1;
562+ for (TestCases::iterator case_iter= (*framework_iter)->formatter()->testcases().begin();
563+ case_iter != (*framework_iter)->formatter()->testcases().end();
564+ ++case_iter)
565+ {
566+ switch ((*case_iter)->result())
567+ {
568+ case TEST_SKIPPED:
569+ output << "ok " << test_count << " - # SKIP ";
570+ break;
571+
572+ case TEST_FAILURE:
573+ output << "not ok " << test_count << " - " << (*case_iter)->name() << " # ";
574+ break;
575+
576+ case TEST_SUCCESS:
577+ output << "ok " << test_count << " - " << (*case_iter)->name() << " # ";
578+ break;
579+ }
580+
581+ output
582+ << (*case_iter)->timer().elapsed_milliseconds()
583+ << std::endl;
584+ }
585+ }
586+}
587+#endif
588+
589+#if 0
590 void Formatter::xml(libtest::Framework& framework_, std::ofstream& output)
591 {
592 output << "<testsuites name=\"" << framework_.name() << "\">" << std::endl;
593@@ -178,15 +267,6 @@
594 }
595 output << "</testsuites>" << std::endl;
596 }
597-
598-void Formatter::push_testcase(const std::string& arg)
599-{
600- assert(_suite_name.empty() == false);
601- TestCase* _current_testcase= new TestCase(arg);
602- _testcases.push_back(_current_testcase);
603-}
604-
605-void Formatter::reset()
606-{
607-}
608+#endif
609+
610 } // namespace libtest
611
612=== modified file 'libtest/formatter.hpp'
613--- libtest/formatter.hpp 2012-12-10 09:06:07 +0000
614+++ libtest/formatter.hpp 2013-07-02 18:24:29 +0000
615@@ -43,43 +43,69 @@
616
617 namespace libtest {
618
619-class TestCase;
620-typedef std::vector<libtest::TestCase*> TestCases;
621+class Collection;
622+
623+class Formatter;
624+typedef std::vector<libtest::Formatter*> Formatters;
625
626 class Formatter {
627 public:
628- Formatter(const std::string& frame_name, const std::string& arg);
629-
630- ~Formatter();
631-
632- void skipped();
633-
634- void failed();
635-
636- void success(const libtest::Timer&);
637-
638- void push_testcase(const std::string&);
639-
640- const std::string& name() const
641- {
642- return _suite_name;
643- }
644-
645- TestCases& testcases()
646- {
647- return _testcases;
648- }
649-
650+ Formatter(const Framework* frame_, std::ostream&);
651+
652+ virtual ~Formatter() {}
653+
654+ virtual void plan(const libtest::Collection*) {}
655+ virtual void report(const libtest::TestCase*, size_t) const {}
656+ virtual void complete() {}
657+
658+protected:
659+ const std::string& name() const;
660+
661+#if 0
662 static void xml(libtest::Framework&, std::ofstream&);
663-
664-private:
665- void reset();
666-
667- TestCase* current();
668-
669-private:
670- std::string _suite_name;
671- TestCases _testcases;
672+ static void tap(libtest::Framework&, std::ofstream&);
673+#endif
674+
675+protected:
676+ const Framework* _frame;
677+
678+protected:
679+ std::ostream& _output;
680+};
681+
682+class Junit : public Formatter
683+{
684+public:
685+ Junit(const Framework*, std::ostream&);
686+ ~Junit();
687+
688+ void report(const libtest::TestCase*, size_t position) const;
689+
690+ void plan(const libtest::Collection*);
691+ void complete();
692+};
693+
694+class TAP : public Formatter
695+{
696+public:
697+ TAP(const Framework*, std::ostream&);
698+ ~TAP();
699+
700+ void plan(const libtest::Collection*);
701+ void report(const libtest::TestCase*, size_t position) const;
702+};
703+
704+class Legacy : public Formatter
705+{
706+public:
707+ Legacy(const Framework*, std::ostream&);
708+ ~Legacy();
709+
710+ void plan(const libtest::Collection*);
711+ void report(const libtest::TestCase*, size_t position) const;
712+
713+private:
714+ const libtest::Collection* _collection;
715 };
716
717 } // namespace libtest
718
719=== modified file 'libtest/framework.cc'
720--- libtest/framework.cc 2013-05-03 08:41:20 +0000
721+++ libtest/framework.cc 2013-07-02 18:24:29 +0000
722@@ -125,6 +125,33 @@
723 _name(name_)
724 {
725 get_world(this);
726+
727+ {
728+ std::string file_name;
729+ if (getenv("WORKSPACE"))
730+ {
731+ file_name.append(getenv("WORKSPACE"));
732+ file_name.append("/");
733+ }
734+ file_name.append(name());
735+ file_name.append(".xml");
736+ xml_file.open(file_name.c_str(), std::ios::trunc);
737+ _formatter.push_back(new libtest::Junit(this, xml_file));
738+ }
739+
740+ {
741+ std::string file_name;
742+ if (getenv("WORKSPACE"))
743+ {
744+ file_name.append(getenv("WORKSPACE"));
745+ file_name.append("/");
746+ }
747+ file_name.append(name());
748+ file_name.append(".tap");
749+ tap_file.open(file_name.c_str(), std::ios::trunc);
750+ _formatter.push_back(new libtest::TAP(this, tap_file));
751+ }
752+ _formatter.push_back(new libtest::Legacy(this, std::cout));
753 }
754
755 void Framework::collections(collection_st collections_[])
756@@ -148,6 +175,9 @@
757
758 std::for_each(_collection.begin(), _collection.end(), DeleteFromVector());
759 _collection.clear();
760+
761+ std::for_each(_formatter.begin(), _formatter.end(), DeleteFromVector());
762+ _formatter.clear();
763 }
764
765 bool Framework::match(const char* arg)
766@@ -232,58 +262,6 @@
767 }
768 }
769
770-uint32_t Framework::sum_total()
771-{
772- uint32_t count= 0;
773- for (std::vector<Collection*>::iterator iter= _collection.begin();
774- iter != _collection.end();
775- ++iter)
776- {
777- count+= (*iter)->total();
778- }
779-
780- return count;
781-}
782-
783-uint32_t Framework::sum_success()
784-{
785- uint32_t count= 0;
786- for (std::vector<Collection*>::iterator iter= _collection.begin();
787- iter != _collection.end();
788- ++iter)
789- {
790- count+= (*iter)->success();
791- }
792-
793- return count;
794-}
795-
796-uint32_t Framework::sum_skipped()
797-{
798- uint32_t count= 0;
799- for (std::vector<Collection*>::iterator iter= _collection.begin();
800- iter != _collection.end();
801- ++iter)
802- {
803- count+= (*iter)->skipped();
804- }
805-
806- return count;
807-}
808-
809-uint32_t Framework::sum_failed()
810-{
811- uint32_t count= 0;
812- for (std::vector<Collection*>::iterator iter= _collection.begin();
813- iter != _collection.end();
814- ++iter)
815- {
816- count+= (*iter)->failed();
817- }
818-
819- return count;
820-}
821-
822 libtest::Runner *Framework::runner()
823 {
824 if (_runner == NULL)
825
826=== modified file 'libtest/framework.h'
827--- libtest/framework.h 2013-05-03 06:03:28 +0000
828+++ libtest/framework.h 2013-07-02 18:24:29 +0000
829@@ -2,7 +2,7 @@
830 *
831 * Data Differential YATL (i.e. libtest) library
832 *
833- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
834+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
835 *
836 * Redistribution and use in source and binary forms, with or without
837 * modification, are permitted provided that the following conditions are
838@@ -45,6 +45,7 @@
839 */
840
841 #include <vector>
842+#include <fstream>
843
844 namespace { class Collection; }
845 typedef std::vector<libtest::Collection*> Suites;
846@@ -126,47 +127,48 @@
847 return _signal;
848 }
849
850- uint32_t sum_total();
851- uint32_t sum_success();
852- uint32_t sum_skipped();
853- uint32_t sum_failed();
854-
855 size_t size()
856 {
857 return _collection.size();
858 }
859
860- uint32_t total() const
861+ Suites& suites()
862+ {
863+ return _collection;
864+ }
865+
866+ libtest::Formatters& formatter()
867+ {
868+ return _formatter;
869+ }
870+
871+ size_t total() const
872 {
873 return _total;
874 }
875
876- uint32_t success() const
877+ size_t success() const
878 {
879 return _success;
880 }
881
882- uint32_t skipped() const
883+ size_t skipped() const
884 {
885 return _skipped;
886 }
887
888- uint32_t failed() const
889+ size_t failed() const
890 {
891 return _failed;
892 }
893
894- Suites& suites()
895- {
896- return _collection;
897- }
898-
899 private:
900- uint32_t _total;
901- uint32_t _success;
902- uint32_t _skipped;
903- uint32_t _failed;
904-
905+ // Sums
906+ size_t _total;
907+ size_t _success;
908+ size_t _skipped;
909+ size_t _failed;
910+
911 /* These methods are called outside of any collection call. */
912 test_callback_create_fn *_create;
913 test_callback_destroy_fn *_destroy;
914@@ -195,6 +197,10 @@
915 private:
916 Framework( const Framework& );
917 const Framework& operator=( const Framework& );
918+ libtest::Formatters _formatter;
919+ std::ofstream xml_file;
920+ std::ofstream tap_file;
921+
922 };
923
924 } // namespace libtest
925
926=== modified file 'libtest/main.cc'
927--- libtest/main.cc 2013-06-28 19:13:48 +0000
928+++ libtest/main.cc 2013-07-02 18:24:29 +0000
929@@ -60,25 +60,6 @@
930
931 using namespace libtest;
932
933-static void stats_print(libtest::Framework *frame)
934-{
935- if (frame->failed() == 0 and frame->success() == 0)
936- {
937- return;
938- }
939-
940- Outn();
941- Out << "Collections\t\t\t\t\t" << frame->total();
942- Out << "\tFailed\t\t\t\t\t" << frame->failed();
943- Out << "\tSkipped\t\t\t\t\t" << frame->skipped();
944- Out << "\tSucceeded\t\t\t\t" << frame->success();
945- Outn();
946- Out << "Tests\t\t\t\t\t" << frame->sum_total();
947- Out << "\tFailed\t\t\t\t" << frame->sum_failed();
948- Out << "\tSkipped\t\t\t\t" << frame->sum_skipped();
949- Out << "\tSucceeded\t\t\t" << frame->sum_success();
950-}
951-
952 #include <getopt.h>
953 #include <unistd.h>
954
955@@ -380,19 +361,37 @@
956 Out << "All tests completed successfully.";
957 }
958
959- stats_print(frame.get());
960+#if 0
961+ {
962+ std::ofstream xml_file;
963+ std::string file_name;
964+ if (getenv("WORKSPACE"))
965+ {
966+ file_name.append(getenv("WORKSPACE"));
967+ file_name.append("/");
968+ }
969+ file_name.append(frame->name());
970+ file_name.append(".xml");
971+ xml_file.open(file_name.c_str(), std::ios::trunc);
972+ libtest::Formatter::xml(*frame, xml_file);
973+ }
974+#endif
975
976- std::ofstream xml_file;
977- std::string file_name;
978- if (getenv("WORKSPACE"))
979+#if 0
980 {
981- file_name.append(getenv("WORKSPACE"));
982- file_name.append("/");
983+ std::ofstream tap_file;
984+ std::string file_name;
985+ if (getenv("WORKSPACE"))
986+ {
987+ file_name.append(getenv("WORKSPACE"));
988+ file_name.append("/");
989+ }
990+ file_name.append(frame->name());
991+ file_name.append(".tap");
992+ tap_file.open(file_name.c_str(), std::ios::trunc);
993+ libtest::Formatter::tap(*frame, tap_file);
994 }
995- file_name.append(frame->name());
996- file_name.append(".xml");
997- xml_file.open(file_name.c_str(), std::ios::trunc);
998- libtest::Formatter::xml(*frame, xml_file);
999+#endif
1000
1001 Outn(); // Generate a blank to break up the messages if make check/test has been run
1002 } while (exit_code == EXIT_SUCCESS and --opt_repeat);
1003
1004=== modified file 'libtest/test.h'
1005--- libtest/test.h 2012-12-31 11:03:44 +0000
1006+++ libtest/test.h 2013-07-02 18:24:29 +0000
1007@@ -51,6 +51,86 @@
1008 test_callback_fn *test_fn;
1009 };
1010
1011+namespace libtest {
1012+
1013+class TestCase;
1014+typedef std::vector<libtest::TestCase*> TestCases;
1015+
1016+class TestCase {
1017+public:
1018+ TestCase(const struct test_st* test_):
1019+ _result(TEST_FAILURE)
1020+ {
1021+ _test.name= test_->name;
1022+ _test.requires_flush= test_->requires_flush;
1023+ _test.test_fn= test_->test_fn;
1024+ }
1025+
1026+ const char* name() const
1027+ {
1028+ return _test.name;
1029+ }
1030+
1031+ test_return_t result() const
1032+ {
1033+ return _result;
1034+ }
1035+
1036+ void result(test_return_t result_)
1037+ {
1038+ _result= result_;
1039+ }
1040+
1041+ void result(test_return_t result_, const libtest::Timer& timer_)
1042+ {
1043+ _result= result_;
1044+ _timer= timer_;
1045+ }
1046+
1047+ const libtest::Timer& timer() const
1048+ {
1049+ return _timer;
1050+ }
1051+
1052+ void timer(libtest::Timer& timer_)
1053+ {
1054+ _timer= timer_;
1055+ }
1056+
1057+ void skipped()
1058+ {
1059+ _result= TEST_SKIPPED;
1060+ }
1061+
1062+ void failed()
1063+ {
1064+ _result= TEST_FAILURE;
1065+ }
1066+
1067+ void success(const libtest::Timer& timer_)
1068+ {
1069+ _result= TEST_SUCCESS;
1070+ _timer= timer_;
1071+ }
1072+
1073+
1074+ const struct test_st* test() const
1075+ {
1076+ return &_test;
1077+ }
1078+
1079+ bool requires_flush() const
1080+ {
1081+ return _test.requires_flush;
1082+ }
1083+
1084+private:
1085+ struct test_st _test;
1086+ test_return_t _result;
1087+ libtest::Timer _timer;
1088+};
1089+} // namespace libtest
1090+
1091 #define test_assert_errno(A) \
1092 do \
1093 { \

Subscribers

People subscribed via source and target branches

to all changes: