Permalink
Browse files

Made diagnostic messages from is and isnt mention whether this is a t…

…odo test

The Perl diagnostics have language like "Failed (TODO) test" when
failing a todo test.  I added this to libtap++.

To add it, I had to make the TODO status visible to the is and isnt
methods, which are defined in the header file.  I thought that
TAP::details was the best place to put the interface function -- out
of the way of most users, but still where is and isnt can see it.
  • Loading branch information...
1 parent fe32550 commit 1483e78f28a4e9d1dbb19099e184fe6a9f18ce2a @RadixSeven RadixSeven committed May 4, 2011
Showing with 21 additions and 8 deletions.
  1. +16 −8 tap++/headers/tap++.h
  2. +5 −0 tap++/source/tap++.C
View
@@ -11,6 +11,11 @@ namespace TAP {
struct no_plan_type {};
extern std::ostream* output;
extern std::ostream* error;
+
+ //Return the variant of "Failed test" or "Failed
+ //(TODO) test" required by whether the current test is
+ //a todo test
+ char const * failed_test_msg();
}
class fatal_exception : public std::exception {
std::string message;
@@ -82,26 +87,27 @@ namespace TAP {
}
template<typename T, typename U> typename boost::disable_if<typename boost::is_floating_point<U>::type, bool>::type is(const T& left, const U& right, const std::string& message = "") {
+ using namespace TAP::details;
try {
bool ret = ok(left == right, message);
if (!ret) {
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag(" Got: ", left);
diag(" Expected: ", right);
}
return ret;
}
catch(const std::exception& e) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought exception '", e.what(), "'");
diag(" Got: ", left);
diag(" Expected: ", right);
return false;
}
catch(...) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought unknown exception");
diag(" Got: ", left);
diag(" Expected: ", right);
@@ -128,26 +134,27 @@ namespace TAP {
}
template<typename T, typename U> typename boost::enable_if<typename boost::is_floating_point<U>::type, bool>::type is(const T& left, const U& right, const std::string& message = "", double epsilon = 0.01) {
+ using namespace TAP::details;
try {
bool ret = ok(2 * fabs(left - right) / (fabs(left) + fabs(right)) < epsilon);
if (!ret) {
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag(" Got: ", left);
diag(" Expected: ", right);
}
return ret;
}
catch(const std::exception& e) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought exception '", e.what(), "'");
diag(" Got: ", left);
diag(" Expected: ", right);
return false;
}
catch(...) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought unknown exception");
diag(" Got: ", left);
diag(" Expected: ", right);
@@ -156,20 +163,21 @@ namespace TAP {
}
template<typename T, typename U> typename boost::enable_if<typename boost::is_floating_point<U>::type, bool>::type isnt(const T& left, const U& right, const std::string& message = "", double epsilon = 0.01) {
+ using namespace TAP::details;
try {
bool ret = 2 * fabs(left - right) / (fabs(left) + fabs(right)) > epsilon;
ok(ret, message);
return ret;
}
catch(const std::exception& e) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought exception '", e.what(), "'");
return false;
}
catch(...) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought unknown exception");
return false;
}
@@ -62,6 +62,7 @@ namespace TAP {
}
}
+
void plan(unsigned tests) throw(fatal_exception) {
if (is_planned) {
bail_out("Can't plan again!");
@@ -175,6 +176,10 @@ namespace TAP {
todo_guard::~todo_guard() throw() {
TODO = value;
}
+ char const * failed_test_msg(){
+ return is_todo_test()?"Failed (TODO) test":"Failed test";
+ }
+
}
void skip(const std::string& reason) throw(details::Skip_exception) {

0 comments on commit 1483e78

Please sign in to comment.