Browse Source

Add some additional logic for throw results.

Brian Aker 12 years ago
parent
commit
1891d64f5d
4 changed files with 82 additions and 9 deletions
  1. 6 4
      configure.ac
  2. 7 0
      libtest/result.cc
  3. 4 1
      libtest/result.hpp
  4. 65 4
      libtest/unittest.cc

+ 6 - 4
configure.ac

@@ -56,10 +56,10 @@ m4_include([libtest/yatl.m4])
 
 AX_ENABLE_LIBMEMCACHED
 m4_include([m4/memcached_sasl.m4])
-AM_CONDITIONAL([BUILDING_LIBMEMCACHED], false)
+AM_CONDITIONAL([BUILDING_LIBMEMCACHED],false)
 
-AM_CONDITIONAL([BUILDING_GEARMAN], true)
-AM_CONDITIONAL([HAVE_LIBGEARMAN], true)
+AM_CONDITIONAL([BUILDING_GEARMAN],true)
+AM_CONDITIONAL([HAVE_LIBGEARMAN],true)
 AC_SUBST([_WITH_LIBGEARMAN_SUPPORT],["_WITH_LIBGEARMAN_SUPPORT 0"])
 AC_DEFINE([GEARMAND_BINARY],["./gearmand/gearmand"],[Name of the gearmand binary used in make test])
 AC_DEFINE([HAVE_LIBGEARMAN],[1], [libgearman support])
@@ -67,7 +67,9 @@ AC_DEFINE([HAVE_GEARMAND_BINARY],[1],[libgearman support])
 
 AX_LIB_CURL([7.21.7],
             [AX_CHECK_LIBRARY([LIBCURL],[curl/curl.h],[curl])],
-            [AC_DEFINE([HAVE_LIBCURL],[0],[Have the LIBCURL library])])
+            [AC_DEFINE([HAVE_LIBCURL],[0],[Have the LIBCURL library])
+            AM_CONDITIONAL([HAVE_LIBCURL],false)
+            ])
 
 m4_include([m4/drizzled.m4])
 WITH_LIBDRIZZLE

+ 7 - 0
libtest/result.cc

@@ -57,9 +57,16 @@ __skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg):
 {
 }
 
+__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, const std::string& mesg):
+  __test_result(file_arg, line_arg, func_arg)
+{
+  snprintf(_error_message, sizeof(_error_message), "FAIL: %.*s", int(mesg.size()), mesg.c_str());
+}
+
 __failure::__failure(const char *file_arg, int line_arg, const char *func_arg):
   __test_result(file_arg, line_arg, func_arg)
 {
+  snprintf(_error_message, sizeof(_error_message), "FAIL");
 }
 
 } // namespace libtest

+ 4 - 1
libtest/result.hpp

@@ -95,14 +95,16 @@ private:
 class __failure : public __test_result
 {
 public:
+  __failure(const char *file, int line, const char *func, const std::string&);
   __failure(const char *file, int line, const char *func);
 
   const char* what() const throw()
   {
-    return "FAILURE";
+    return _error_message;
   }
 
 private:
+  char _error_message[BUFSIZ];
 };
 
 
@@ -111,3 +113,4 @@ private:
 #define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM)
 #define SKIP throw libtest::__skipped(LIBYATL_DEFAULT_PARAM)
 #define FAIL throw libtest::__failure(LIBYATL_DEFAULT_PARAM)
+#define FAILED(__mesg) throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __mesg)

+ 65 - 4
libtest/unittest.cc

@@ -108,14 +108,73 @@ static test_return_t test_success_test(void *)
 
 static test_return_t test_throw_success_TEST(void *)
 {
-  _SUCCESS;
-  return TEST_SUCCESS;
+  try {
+    _SUCCESS;
+  }
+  catch (libtest::__success)
+  {
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
 }
 
 static test_return_t test_throw_skip_TEST(void *)
 {
-  SKIP;
-  return TEST_SUCCESS;
+  try {
+    SKIP;
+  }
+  catch (libtest::__skipped)
+  {
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
+}
+
+static test_return_t test_throw_fail_TEST(void *)
+{
+  try {
+    FAIL;
+  }
+  catch (libtest::__failure)
+  {
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
+}
+
+static test_return_t test_throw_failure_TEST(void *)
+{
+  std::string error_messsage("test message!");
+  try {
+    FAILED(error_messsage);
+  }
+  catch (libtest::__failure e)
+  {
+    std::string compare_message("FAIL: test message!");
+    test_zero(compare_message.compare(e.what()));
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
 }
 
 static test_return_t test_failure_test(void *)
@@ -890,6 +949,8 @@ test_st tests_log[] ={
   {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
   {"SUCCESS", false, test_throw_success_TEST },
   {"SKIP", false, test_throw_skip_TEST },
+  {"FAIL", false, test_throw_fail_TEST },
+  {"FAILED", false, test_throw_failure_TEST },
   {0, 0, 0}
 };