[complement-svn] SF.net SVN: complement: [1605] trunk/complement/explore/app/exam
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-11 19:56:55
|
Revision: 1605 http://svn.sourceforge.net/complement/?rev=1605&view=rev Author: complement Date: 2007-07-11 12:56:54 -0700 (Wed, 11 Jul 2007) Log Message: ----------- test suite messages, initial Modified Paths: -------------- trunk/complement/explore/app/exam/suite.cc trunk/complement/explore/app/exam/suite.h trunk/complement/explore/app/exam/zero.cc Modified: trunk/complement/explore/app/exam/suite.cc =================================================================== --- trunk/complement/explore/app/exam/suite.cc 2007-07-11 18:52:43 UTC (rev 1604) +++ trunk/complement/explore/app/exam/suite.cc 2007-07-11 19:56:54 UTC (rev 1605) @@ -61,20 +61,39 @@ skip_recorder<Tag> record_skip(test_suite& ts, Tag) { return skip_recorder<Tag>(ts); } -int _root_func() +} // namespace detail + +int test_suite::_root_func() { - return 0; + return test_suite::init; } -} // namespace detail +test_suite::test_suite( const string& name ) : + root( add_vertex( white_color, g ) ), + _suite_name( name ) +{ + color = get( vertex_color, g ); + testcase = get( vertex_testcase, g ); + _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); + _test[root].state = 0; + _stat.total = 0; + _stat.passed = 0; + _stat.failed = 0; + _stat.skipped = 0; +} -test_suite::test_suite() : - root( add_vertex( white_color, g ) ) +test_suite::test_suite( const char *name ) : + root( add_vertex( white_color, g ) ), + _suite_name( name ) { color = get( vertex_color, g ); testcase = get( vertex_testcase, g ); _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); _test[root].state = 0; + _stat.total = 0; + _stat.passed = 0; + _stat.failed = 0; + _stat.skipped = 0; } test_suite::~test_suite() @@ -87,41 +106,66 @@ void test_suite::girdle() { stack<vertex_t> buffer; + cerr << "== Begin test suite\n"; breadth_first_visit( g, root, buffer, make_bfs_visitor( make_pair( record_vertexes(*this,on_discover_vertex()), record_skip(*this,on_examine_edge()) ) ), color ); + cerr << "== End test suite\n"; + if ( _stat.failed != 0 ) { + cerr << "*** FAIL "; + } else { + cerr << "*** PASS "; + } + cerr << _suite_name + << " (+" << _stat.passed + << "-" << _stat.failed + << "~" << _stat.skipped << "/" << _stat.total << ") ***" << endl; } void test_suite::girdle( test_suite::test_case_type start ) { stack<vertex_t> buffer; - list<vertex_t> v; + cerr << "== Begin test suite\n"; breadth_first_visit( g, start, buffer, make_bfs_visitor( make_pair( record_vertexes(*this,on_discover_vertex()), record_skip(*this,on_examine_edge()) ) ), color ); + cerr << "== End test suite\n"; + if ( _stat.failed != 0 ) { + cerr << "*** FAIL "; + } else { + cerr << "*** PASS "; + } + cerr << _suite_name + << " (+" << _stat.passed + << "-" << _stat.failed + << "~" << _stat.skipped << "/" << _stat.total << ") ***" << endl; } -test_suite::test_case_type test_suite::add( test_suite::func_type f ) +test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name ) { vertex_t v = add_vertex( white_color, g); add_edge( root, v, g ); _test[v].tc = detail::make_test_case( detail::call( f ) ); _test[v].state = 0; + _test[v].name = name; + ++_stat.total; return v; } -test_suite::test_case_type test_suite::add( test_suite::func_type f, test_suite::test_case_type depends ) +test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name, test_suite::test_case_type depends ) { vertex_t v = add_vertex( white_color, g); add_edge( depends, v, g ); _test[v].tc = detail::make_test_case( detail::call( f ) ); _test[v].state = 0; + _test[v].name = name; + ++_stat.total; return v; } @@ -164,13 +208,26 @@ { try { if ( _test[v].state == 0 ) { - if ( (*_test[v].tc)() != 0 ) { + int res = (*_test[v].tc)(); + if ( (res & init) != 0 ) { + // do nothing + } else if ( res == 0 ) { + ++_stat.passed; + cerr << " PASS " << _test[v].name << "\n"; + } else { _test[v].state = fail; + ++_stat.failed; + cerr << " FAIL " << _test[v].name << "\n"; } + } else { + ++_stat.skipped; + cerr << " SKIP " << _test[v].name << "\n"; } } catch ( ... ) { + ++_stat.failed; _test[v].state = fail; + cerr << " FAIL " << _test[v].name << "\n"; } } Modified: trunk/complement/explore/app/exam/suite.h =================================================================== --- trunk/complement/explore/app/exam/suite.h 2007-07-11 18:52:43 UTC (rev 1604) +++ trunk/complement/explore/app/exam/suite.h 2007-07-11 19:56:54 UTC (rev 1605) @@ -7,6 +7,7 @@ #include <sstream> #include <map> #include <boost/graph/adjacency_list.hpp> +#include <string> enum vertex_testcase_t { vertex_testcase }; @@ -141,18 +142,27 @@ typedef int (*func_type)(); typedef vertex_t test_case_type; - test_suite(); + test_suite( const std::string& name ); + test_suite( const char *name ); ~test_suite(); - test_case_type add( func_type ); - test_case_type add( func_type, test_case_type ); + test_case_type add( func_type, const std::string& name ); + test_case_type add( func_type, const std::string& name, test_case_type ); template <class TC> - test_case_type add( int (TC::*)(), TC& ); + test_case_type add( int (TC::*)(), TC&, const std::string& name ); template <class TC> - test_case_type add( int (TC::*)(), TC&, test_case_type ); + test_case_type add( int (TC::*)(), TC&, const std::string& name, test_case_type ); + struct stat + { + int total; + int passed; + int failed; + int skipped; + }; + void girdle(); void girdle( test_case_type start ); @@ -160,7 +170,8 @@ void check_test_case( vertex_t u, vertex_t v ); enum { - trace = 1 + trace = 1, + trace_suite = 2 }; static int flags(); @@ -170,7 +181,8 @@ private: enum { fail = 1, - skip = 2 + skip = 2, + init = 1024 }; graph_t g; @@ -182,33 +194,41 @@ { detail::test_case *tc; int state; + std::string name; }; typedef std::map<vertex_t,test_case_collect> test_case_map_type; test_case_map_type _test; + test_suite::stat _stat; + std::string _suite_name; static int _flags; static void (*_report)( const char *, int, bool, const char * ); + static int _root_func(); }; template <class TC> -test_suite::test_case_type test_suite::add( int (TC::*f)(), TC& instance ) +test_suite::test_case_type test_suite::add( int (TC::*f)(), TC& instance, const std::string& name ) { vertex_t v = boost::add_vertex( boost::white_color, g); boost::add_edge( root, v, g ); _test[v].tc = detail::make_test_case( f, instance ); _test[v].state = 0; + _test[v].name = name; + ++_stat.total; return v; } template <class TC> -test_suite::test_case_type test_suite::add( int (TC::*f)(), TC& instance, test_suite::test_case_type depends ) +test_suite::test_case_type test_suite::add( int (TC::*f)(), TC& instance, const std::string& name, test_suite::test_case_type depends ) { vertex_t v = boost::add_vertex( boost::white_color, g); boost::add_edge( depends, v, g ); _test[v].tc = detail::make_test_case( f, instance ); _test[v].state = 0; + _test[v].name = name; + ++_stat.total; return v; } Modified: trunk/complement/explore/app/exam/zero.cc =================================================================== --- trunk/complement/explore/app/exam/zero.cc 2007-07-11 18:52:43 UTC (rev 1604) +++ trunk/complement/explore/app/exam/zero.cc 2007-07-11 19:56:54 UTC (rev 1605) @@ -9,6 +9,13 @@ return 0; } +int func2() +{ + EXAM_CHECK(true); + + return 0; +} + class test_x { public: @@ -24,15 +31,19 @@ int main( int argc, char **argv ) { - exam::test_suite t; + exam::test_suite t( "exam level 0" ); test_x tx; - t.add( func ); - t.add( &test_x::f, tx ); + t.add( func, "simple function" ); + t.add( &test_x::f, tx, "member function" ); - t.girdle( 0 ); + t.add( func, "simple function, depends", + t.add( &test_x::f, tx, "member function, depends", + t.add( func2, "simple good function" ) ) ); + t.girdle(); + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |