1 #ifndef TUT_RESTARTABLE_H_GUARD
2 #define TUT_RESTARTABLE_H_GUARD
26 std::string
escape(
const std::string& orig)
29 std::string::const_iterator i,e;
35 if( (*i >=
'a' && *i <=
'z') ||
36 (*i >=
'A' && *i <=
'Z') ||
37 (*i >=
'0' && *i <=
'9') )
44 rc += (
'a'+(((
unsigned int)*i)>>4));
45 rc += (
'a'+(((
unsigned int)*i)&0xF));
59 std::string::const_iterator i,e;
71 ++i;
if( i == e )
throw std::invalid_argument(
"unexpected end of string");
73 ++i;
if( i == e )
throw std::invalid_argument(
"unexpected end of string");
75 rc += (((c1-
'a')<<4) + (c2-
'a'));
97 default:
throw std::logic_error(
"operator << : bad result_type");
107 std::getline(is,tr.
group);
113 if( tr.
test < 0 )
throw std::logic_error(
"operator >> : bad test number");
123 default:
throw std::logic_error(
"operator >> : bad result_type");
129 if( !is.good() )
throw std::logic_error(
"malformed test result");
151 : runner_(
runner.get()), callback_(0), dir_(dir)
154 jrn_ = dir_+
'/'+
"journal.tut";
155 log_ = dir_+
'/'+
"log.tut";
196 std::string fail_group;
198 read_log_(fail_group,fail_test);
199 bool fail_group_reached = (fail_group ==
"");
203 tut::groupnames::const_iterator gni,gne;
209 if( !fail_group_reached )
211 if( *gni != fail_group )
216 fail_group_reached =
true;
220 int test = (*gni == fail_group && fail_test>=0)? fail_test+1:1;
224 register_execution_(*gni,test);
257 void invoke_callback_()
const
262 std::string current_group;
263 std::ifstream ijournal(jrn_.c_str());
264 while( ijournal.good() )
273 catch(
const no_more_tests& )
285 void register_test_(
const test_result& tr)
const
287 std::ofstream ojournal(jrn_.c_str(),std::ios::app);
289 ojournal << std::flush;
290 if( !ojournal.good() )
throw std::runtime_error(
"unable to register test result in file "+jrn_);
296 void register_execution_(
const std::string& grp,
int test)
const
299 std::ofstream olog(log_.c_str());
300 olog <<
util::escape(grp) << std::endl << test << std::endl << std::flush;
301 if( !olog.good() )
throw std::runtime_error(
"unable to register execution in file "+log_);
307 void truncate_()
const
309 std::ofstream olog(log_.c_str());
310 std::ofstream ojournal(jrn_.c_str());
316 void read_log_(std::string& fail_group,
int& fail_test)
const
319 std::ifstream ilog(log_.c_str());
320 std::getline(ilog,fail_group);
325 fail_group =
""; fail_test = -1;