Skip to content

Commit

Permalink
Made todo_guard more prominent, we have no finally
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed May 5, 2011
1 parent 05611f6 commit 2631588
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
9 changes: 6 additions & 3 deletions tap++/doc/libtap++.pod
Expand Up @@ -193,9 +193,11 @@ given I<reason>. Note that you have to do the skipping yourself.


=item B<TODO> =item B<TODO>


{
todo_guard why;
TODO="why" TODO="why"
my_tests_here ... my_tests_here ...
TODO="" }


C<TODO> is a global string variable that tells TAP harness the reason C<TODO> is a global string variable that tells TAP harness the reason
the current test is expected to fail. You set TODO before a block of the current test is expected to fail. You set TODO before a block of
Expand All @@ -214,8 +216,9 @@ Note that TODO manipulates a global variable. Thus, you should be
careful to set it to "" before going to another section of the careful to set it to "" before going to another section of the
program. An easy mistake to make is to have a failing section of code program. An easy mistake to make is to have a failing section of code
that throws an exception, taking you out of the current scope without that throws an exception, taking you out of the current scope without
resetting TODO. Adding a try...finally block around such code fixes resetting TODO. To make it easier to deal with this in a thread-safe
the problem. manner, the todo_guard class is provided. Objects of this class will
reset TODO when they fall out of scope.


=back =back


Expand Down
13 changes: 7 additions & 6 deletions tap++/headers/tap++.h
Expand Up @@ -195,6 +195,13 @@ namespace TAP {
} }


extern std::string TODO; extern std::string TODO;

class todo_guard {
const std::string value;
public:
todo_guard() throw();
~todo_guard() throw();
};
} }


#ifdef WANT_TEST_EXTRAS #ifdef WANT_TEST_EXTRAS
Expand All @@ -215,12 +222,6 @@ namespace TAP {
void start_block(unsigned) throw(); void start_block(unsigned) throw();
unsigned stop_block() throw(fatal_exception); unsigned stop_block() throw(fatal_exception);


class todo_guard {
const std::string value;
public:
todo_guard() throw();
~todo_guard() throw();
};
} }


void skip(const std::string& reason) throw(details::Skip_exception); void skip(const std::string& reason) throw(details::Skip_exception);
Expand Down
12 changes: 6 additions & 6 deletions tap++/source/tap++.C
Expand Up @@ -158,6 +158,11 @@ namespace TAP {
} }
details::error = &new_error; details::error = &new_error;
} }
todo_guard::todo_guard() throw() : value(TODO) {
}
todo_guard::~todo_guard() throw() {
TODO = value;
}
namespace details { namespace details {
std::ostream* output = &std::cout; std::ostream* output = &std::cout;
std::ostream* error = &std::cout; std::ostream* error = &std::cout;
Expand All @@ -171,12 +176,7 @@ namespace TAP {
return ret; return ret;
} }


todo_guard::todo_guard() throw() : value(TODO) { char const * failed_test_msg() throw() {
}
todo_guard::~todo_guard() throw() {
TODO = value;
}
char const * failed_test_msg(){
return is_todo_test()?"Failed (TODO) test":"Failed test"; return is_todo_test()?"Failed (TODO) test":"Failed test";
} }


Expand Down

0 comments on commit 2631588

Please sign in to comment.