Second pass on update of yatl.
[awesomized/libmemcached] / libtest / unittest.cc
index 0d50447783ce0c1278d6c07e1b072336ea7e4223..e35911bf537ffc23598cc190f52045c124424584 100644 (file)
  *
  */
 
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
 
-#include <libtest/test.hpp>
+#include <libtest/yatl.h>
 
-#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(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
-#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,96 @@ 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 *)
+{
+  try {
+    FAIL("test message!");
+  }
+  catch (const 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;
+}
+#pragma GCC diagnostic ignored "-Wstack-protector"
+
+static test_return_t ASSERT_FALSE__TEST(void *)
+{
+  try {
+    ASSERT_FALSE_(true, __func__);
+  }
+  catch (const libtest::__failure& e)
+  {
+    ASSERT_STREQ(e.what(), "Assertion '!true' [ ASSERT_FALSE__TEST ]");
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
+}
+
+static test_return_t ASSERT_FALSE_TEST(void *)
+{
+  try {
+    FAIL(__func__);
+  }
+  catch (const libtest::__failure& e)
+  {
+    ASSERT_STREQ(e.what(), __func__);
+    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 +347,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 +357,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,8 +497,10 @@ 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();
+  true_app.use_gdb(true);
 
   test_compare(Application::SUCCESS, true_app.run());
   test_compare(Application::SUCCESS, true_app.join());
@@ -407,8 +511,10 @@ 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();
+  true_app.use_gdb(true);
 
   const char *args[]= { "--fubar", 0 };
   test_compare(Application::SUCCESS, true_app.run(args));
@@ -440,6 +546,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,11 +716,12 @@ 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();
+  wait_app.use_gdb(true);
 
   const char *args[]= { "/etc/services", 0 };
   test_compare(Application::SUCCESS, wait_app.run(args));
@@ -628,11 +737,12 @@ 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();
+  wait_app.use_gdb(true);
 
   const char *args[]= { "/etc/services", 0 };
   test_compare(Application::SUCCESS, wait_app.run(args));
@@ -643,15 +753,16 @@ 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);
 #endif
 
   libtest::Application abort_app("libtest/abort", true);
-  abort_app.use_gdb();
+  abort_app.use_gdb(true);
 
   test_compare(Application::SUCCESS, abort_app.run());
   test_compare(Application::SUCCESS, abort_app.join());
@@ -774,7 +885,10 @@ static test_return_t check_for_gearman(void *)
 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
   if (GEARMAND_BINARY)
   {
-    test_zero(access(GEARMAND_BINARY, X_OK ));
+    if (strcmp(GEARMAND_BINARY, "./gearmand/gearmand"))
+    {
+      test_zero(access(GEARMAND_BINARY, X_OK ));
+    }
   }
   else
   {
@@ -824,9 +938,8 @@ static test_return_t clear_servers(void* object)
   return TEST_SUCCESS;
 }
 
-static test_return_t check_for_libmemcached(void* object)
+static test_return_t check_for_memcached(void* object)
 {
-  test_skip(true, HAVE_LIBMEMCACHED);
   test_skip(true, has_memcached());
 
   server_startup_st *servers= (server_startup_st*)object;
@@ -853,6 +966,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 },
@@ -864,6 +978,11 @@ 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 },
+  {"ASSERT_FALSE_", false, ASSERT_FALSE__TEST },
+  {"ASSERT_FALSE", false, ASSERT_FALSE_TEST },
   {0, 0, 0}
 };
 
@@ -990,7 +1109,7 @@ collection_st collection[] ={
   {"directories", 0, 0, directories_tests},
   {"comparison", 0, 0, comparison_tests},
   {"gearmand", check_for_gearman, clear_servers, gearmand_tests},
-  {"memcached", check_for_libmemcached, clear_servers, memcached_TESTS },
+  {"memcached", check_for_memcached, clear_servers, memcached_TESTS },
   {"drizzled", check_for_drizzle, clear_servers, drizzled_tests},
   {"cmdline", 0, 0, cmdline_tests},
   {"application", 0, 0, application_tests},