1 #ifndef TUT_RESTARTABLE_H_GUARD
2 #define TUT_RESTARTABLE_H_GUARD
29 std::string escape(
const std::string& orig)
32 std::string::const_iterator i,e;
38 if ((*i >=
'a' && *i <=
'z') ||
39 (*i >=
'A' && *i <=
'Z') ||
40 (*i >=
'0' && *i <=
'9') )
47 rc += (
'a'+(((
unsigned int)*i) >> 4));
48 rc += (
'a'+(((
unsigned int)*i) & 0xF));
59 std::string unescape(
const std::string& orig)
62 std::string::const_iterator i,e;
77 throw std::invalid_argument(
"unexpected end of string");
83 throw std::invalid_argument(
"unexpected end of string");
86 rc += (((c1 -
'a') << 4) + (c2 -
'a'));
99 os << escape(tr.
group) << std::endl;
100 os << tr.
test <<
' ';
118 case test_result::rethrown:
121 case test_result::ex_ctor:
124 case test_result::dummy:
125 assert(!
"Should never be called");
127 throw std::logic_error(
"operator << : bad result_type");
129 os <<
' ' << escape(tr.
message) << std::endl;
137 std::getline(is,tr.
group);
148 throw std::logic_error(
"operator >> : bad test number");
171 tr.result = test_result::rethrown;
174 tr.result = test_result::ex_ctor;
177 throw std::logic_error(
"operator >> : bad result_type");
185 throw std::logic_error(
"malformed test result");
197 callbacks callbacks_;
209 : runner_(runner.get()),
212 log_( dir +
'/' +
"log.tut" ),
213 jrn_( dir +
'/' +
"journal.tut" )
232 callbacks_.insert(cb);
237 callbacks_.insert(cb);
240 void erase_callback(callback* cb)
242 callbacks_.erase(cb);
245 void set_callbacks(
const callbacks& cb)
250 const callbacks& get_callbacks()
const
269 std::string fail_group;
271 read_log_(fail_group,fail_test);
272 bool fail_group_reached = (fail_group ==
"");
276 tut::groupnames::const_iterator gni,gne;
282 if (!fail_group_reached)
284 if (*gni != fail_group)
289 fail_group_reached =
true;
293 int test = (*gni == fail_group && fail_test >= 0) ? fail_test + 1 : 1;
297 register_execution_(*gni,test);
300 if( !runner_.
run_test(*gni,test, tr) || tr.result == test_result::dummy )
323 void invoke_callback_()
const
326 runner_.cb_run_started_();
328 std::string current_group;
329 std::ifstream ijournal(jrn_.c_str());
330 while (ijournal.good())
333 if( !util::deserialize(ijournal,tr) )
337 runner_.cb_test_completed_(tr);
340 runner_.cb_run_completed_();
346 void register_test_(
const test_result& tr)
const
348 std::ofstream ojournal(jrn_.c_str(), std::ios::app);
349 util::serialize(ojournal, tr);
350 ojournal << std::flush;
351 if (!ojournal.good())
353 throw std::runtime_error(
"unable to register test result in file "
361 void register_execution_(
const std::string& grp,
int test)
const
364 std::ofstream olog(log_.c_str());
365 olog << util::escape(grp) << std::endl << test << std::endl << std::flush;
368 throw std::runtime_error(
"unable to register execution in file "
376 void truncate_()
const
378 std::ofstream olog(log_.c_str());
379 std::ofstream ojournal(jrn_.c_str());
385 void read_log_(std::string& fail_group,
int& fail_test)
const
388 std::ifstream ilog(log_.c_str());
389 std::getline(ilog,fail_group);
390 fail_group = util::unescape(fail_group);
Definition: tut_runner.hpp:113
std::string group
Definition: tut_result.hpp:74
groupnames list_groups() const
Definition: tut_restartable.hpp:258
bool run_test(const std::string &group_name, int n, test_result &tr) const
Definition: tut_runner.hpp:268
test finished successfully
Definition: tut_result.hpp:91
void set_callbacks(const callbacks &cb)
Definition: tut_runner.hpp:200
int test
Definition: tut_result.hpp:79
void register_group(const std::string &name, group_base *gr)
Definition: tut_restartable.hpp:221
test finished successfully, but test destructor throwed
Definition: tut_result.hpp:94
std::vector< std::string > groupnames
Definition: tut_runner.hpp:107
void register_group(const std::string &name, group_base *gr)
Definition: tut_runner.hpp:132
Definition: tut_runner.hpp:16
Definition: tut_restartable.hpp:194
void run_tests() const
Definition: tut_restartable.hpp:266
test failed with ensure() or fail() methods
Definition: tut_result.hpp:92
const groupnames list_groups() const
Definition: tut_runner.hpp:209
std::string message
Definition: tut_result.hpp:107
Definition: tut_result.hpp:69
test forced test application to terminate abnormally
Definition: tut_result.hpp:95
test throwed an exceptions
Definition: tut_result.hpp:93
const callbacks & get_callbacks() const
Definition: tut_runner.hpp:191
restartable_wrapper(const std::string &dir=".")
Definition: tut_restartable.hpp:208
void set_callback(callback *cb)
Definition: tut_restartable.hpp:229
Definition: tut_runner.hpp:38