Update errors to make sure we return the real error.
[awesomized/libmemcached] / libtest / unittest.cc
index f8432476ab10d2f7ea557c1a67fd1abe4b6d2f12..b81ef5e760360f494965ee869c993f77cc31a9e8 100644 (file)
  *
  */
 
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
 
 #include <libtest/test.hpp>
 
-#if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT
-#include <libmemcached-1.0/memcached.h>
+#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
+# include <libmemcached-1.0/types/return.h>
 #endif
 
-#if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT
-#include <libgearman/gearman.h>
+#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H
+# include <libgearman-1.0/return.h>
 #endif
 
 #include <cstdlib>
@@ -56,6 +56,18 @@ static std::string testing_service;
 // Used to track setups where we see if failure is happening
 static uint32_t fatal_calls= 0;
 
+static test_return_t getenv_TEST(void *)
+{
+#if 0
+  for (char **ptr= environ; *ptr; ptr++)
+  {
+    Error << *ptr;
+  }
+#endif
+
+  return TEST_SUCCESS;
+}
+
 static test_return_t LIBTOOL_COMMAND_test(void *)
 {
   test_true(getenv("LIBTOOL_COMMAND"));
@@ -83,7 +95,7 @@ static test_return_t GDB_COMMAND_test(void *)
 static test_return_t test_success_equals_one_test(void *)
 {
   test_skip(HAVE_LIBMEMCACHED, 1);
-#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED 
+#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
   test_zero(MEMCACHED_SUCCESS);
 #endif
   return TEST_SUCCESS;
@@ -94,6 +106,60 @@ static test_return_t test_success_test(void *)
   return TEST_SUCCESS;
 }
 
+static test_return_t test_throw_success_TEST(void *)
+{
+  try {
+    _SUCCESS;
+  }
+  catch (libtest::__success)
+  {
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
+}
+
+static test_return_t test_throw_skip_TEST(void *)
+{
+  try {
+    SKIP;
+  }
+  catch (libtest::__skipped)
+  {
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
+}
+
+static test_return_t test_throw_fail_TEST(void *)
+{
+  std::string error_messsage("test message!");
+  try {
+    FAIL(error_messsage);
+  }
+  catch (libtest::__failure e)
+  {
+    std::string compare_message("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 *)
 {
   return TEST_SKIPPED; // Only run this when debugging
@@ -245,7 +311,7 @@ static test_return_t _compare_test_return_t_test(void *)
 static test_return_t _compare_memcached_return_t_test(void *)
 {
   test_skip(HAVE_LIBMEMCACHED, true);
-#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED 
+#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
   test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
 #endif
 
@@ -255,7 +321,7 @@ static test_return_t _compare_memcached_return_t_test(void *)
 static test_return_t _compare_gearman_return_t_test(void *)
 {
   test_skip(HAVE_LIBGEARMAN, true);
-#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H
   test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
 #endif
 
@@ -395,6 +461,8 @@ static test_return_t application_true_BINARY(void *)
 static test_return_t application_gdb_true_BINARY2(void *)
 {
   test_skip(0, access("/usr/bin/gdb", X_OK ));
+  test_skip(0, access("/usr/bin/true", X_OK ));
+
   Application true_app("/usr/bin/true");
   true_app.use_gdb();
 
@@ -407,6 +475,8 @@ static test_return_t application_gdb_true_BINARY2(void *)
 static test_return_t application_gdb_true_BINARY(void *)
 {
   test_skip(0, access("/usr/bin/gdb", X_OK ));
+  test_skip(0, access("/usr/bin/true", X_OK ));
+
   Application true_app("/usr/bin/true");
   true_app.use_gdb();
 
@@ -440,6 +510,8 @@ static test_return_t application_doesnotexist_BINARY(void *)
   const char *args[]= { "--fubar", 0 };
 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
   test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
+#elif defined(TARGET_OS_FREEBSD) && TARGET_OS_FREEBSD
+  test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
 #else
   test_compare(Application::SUCCESS, true_app.run(args));
   test_compare(Application::INVALID_POSIX_SPAWN, true_app.join());
@@ -608,8 +680,9 @@ static test_return_t wait_services_BINARY2(void *)
 
 static test_return_t wait_services_appliction_TEST(void *)
 {
-  test_skip(0, access("/usr/bin/gdb", X_OK ));
   test_skip(0, access("/etc/services", R_OK ));
+  test_skip(0, access("/usr/bin/gdb", X_OK ));
+  test_skip(0, access("libtest/wait", X_OK ));
 
   libtest::Application wait_app("libtest/wait", true);
   wait_app.use_gdb();
@@ -628,8 +701,9 @@ static test_return_t gdb_wait_services_appliction_TEST(void *)
   test_skip(0, TARGET_OS_OSX);
 #endif
 
-  test_skip(0, access("/usr/bin/gdb", X_OK ));
   test_skip(0, access("/etc/services", R_OK ));
+  test_skip(0, access("/usr/bin/gdb", X_OK ));
+  test_skip(0, access("libtest/wait", X_OK ));
 
   libtest::Application wait_app("libtest/wait", true);
   wait_app.use_gdb();
@@ -643,8 +717,9 @@ static test_return_t gdb_wait_services_appliction_TEST(void *)
 
 static test_return_t gdb_abort_services_appliction_TEST(void *)
 {
-  test_skip(true, false);
   test_skip(0, access("/usr/bin/gdb", X_OK ));
+  test_skip(0, access("libtest/abort", X_OK ));
+  test_skip(true, false);
 
 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
   test_skip(0, TARGET_OS_OSX);
@@ -734,6 +809,7 @@ static test_return_t lookup_false_TEST(void *)
 
 static test_return_t create_tmpfile_TEST(void *)
 {
+  test_skip(0, access("/usr/bin/touch", X_OK ));
   std::string tmp= create_tmpfile(__func__);
   test_compare(-1, access(tmp.c_str(), R_OK));
   test_compare(-1, access(tmp.c_str(), F_OK));
@@ -770,6 +846,16 @@ static test_return_t check_for_gearman(void *)
 {
   test_skip(true, HAVE_LIBGEARMAN);
   test_skip(true, has_gearmand());
+#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
+  if (GEARMAND_BINARY)
+  {
+    test_zero(access(GEARMAND_BINARY, X_OK ));
+  }
+  else
+  {
+    return TEST_SKIPPED;
+  }
+#endif
 
   testing_service= "gearmand";
 
@@ -842,6 +928,7 @@ test_st test_skip_TESTS[] ={
 };
 
 test_st environment_tests[] ={
+  {"getenv()", 0, getenv_TEST },
   {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
   {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
   {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
@@ -853,6 +940,9 @@ test_st tests_log[] ={
   {"TEST_SUCCESS", false, test_success_test },
   {"TEST_FAILURE", false, test_failure_test },
   {"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 },
   {0, 0, 0}
 };