Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 1483e78f28a4e9d1dbb19099e184fe6a9f18ce2a 1 parent fe32550
@RadixSeven RadixSeven authored
Showing with 21 additions and 8 deletions.
  1. +16 −8 tap++/headers/tap++.h
  2. +5 −0 tap++/source/tap++.C
View
24 tap++/headers/tap++.h
@@ -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,10 +87,11 @@ 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);
}
@@ -93,7 +99,7 @@ namespace TAP {
}
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);
@@ -101,7 +107,7 @@ namespace TAP {
}
catch(...) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought unknown exception");
diag(" Got: ", left);
diag(" Expected: ", right);
@@ -128,10 +134,11 @@ 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);
}
@@ -139,7 +146,7 @@ namespace TAP {
}
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);
@@ -147,7 +154,7 @@ namespace TAP {
}
catch(...) {
fail(message);
- diag("Failed test '", message, "'");
+ diag(failed_test_msg()," '", message, "'");
diag("Cought unknown exception");
diag(" Got: ", left);
diag(" Expected: ", right);
@@ -156,6 +163,7 @@ 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);
@@ -163,13 +171,13 @@ namespace TAP {
}
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;
}
View
5 tap++/source/tap++.C
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.