Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made todo_guard more prominent, we have no finally

  • Loading branch information...
commit 2631588c7de9d9d0966c6bbc59401448cba956a7 1 parent 05611f6
Leon Timmermans authored
9 tap++/doc/libtap++.pod
View
@@ -193,9 +193,11 @@ given I<reason>. Note that you have to do the skipping yourself.
=item B<TODO>
+ {
+ todo_guard why;
TODO="why"
my_tests_here ...
- TODO=""
+ }
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
@@ -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
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
-resetting TODO. Adding a try...finally block around such code fixes
-the problem.
+resetting TODO. To make it easier to deal with this in a thread-safe
+manner, the todo_guard class is provided. Objects of this class will
+reset TODO when they fall out of scope.
=back
13 tap++/headers/tap++.h
View
@@ -195,6 +195,13 @@ namespace TAP {
}
extern std::string TODO;
+
+ class todo_guard {
+ const std::string value;
+ public:
+ todo_guard() throw();
+ ~todo_guard() throw();
+ };
}
#ifdef WANT_TEST_EXTRAS
@@ -215,12 +222,6 @@ namespace TAP {
void start_block(unsigned) throw();
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);
12 tap++/source/tap++.C
View
@@ -158,6 +158,11 @@ namespace TAP {
}
details::error = &new_error;
}
+ todo_guard::todo_guard() throw() : value(TODO) {
+ }
+ todo_guard::~todo_guard() throw() {
+ TODO = value;
+ }
namespace details {
std::ostream* output = &std::cout;
std::ostream* error = &std::cout;
@@ -171,12 +176,7 @@ namespace TAP {
return ret;
}
- todo_guard::todo_guard() throw() : value(TODO) {
- }
- todo_guard::~todo_guard() throw() {
- TODO = value;
- }
- char const * failed_test_msg(){
+ char const * failed_test_msg() throw() {
return is_todo_test()?"Failed (TODO) test":"Failed test";
}
Please sign in to comment.
Something went wrong with that request. Please try again.