Browse Source

MErge up latest yatl

Brian Aker 12 years ago
parent
commit
0d968b613d
10 changed files with 170 additions and 88 deletions
  1. 0 58
      libtest/binaries.cc
  2. 0 13
      libtest/binaries.h
  3. 4 0
      libtest/cmdline.h
  4. 1 0
      libtest/collection.cc
  5. 23 0
      libtest/comparison.hpp
  6. 9 4
      libtest/fatal.cc
  7. 18 0
      libtest/fatal.hpp
  8. 90 7
      libtest/has.cc
  9. 24 4
      libtest/has.hpp
  10. 1 2
      libtest/main.cc

+ 0 - 58
libtest/binaries.cc

@@ -35,65 +35,7 @@
  */
 
 #include <config.h>
-#include <libtest/common.h>
 
 namespace libtest {
 
-bool has_gearmand_binary()
-{
-#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
-  std::stringstream arg_buffer;
-
-  if (getenv("PWD"))
-  {
-    arg_buffer << getenv("PWD");
-    arg_buffer << "/";
-  }
-  arg_buffer << GEARMAND_BINARY;
-
-  if (access(arg_buffer.str().c_str() ,R_OK|X_OK) == 0)
-  {
-    return true;
-  }
-#endif
-
-  return false;
-}
-
-bool has_drizzled_binary()
-{
-#if defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY
-  if (access(DRIZZLED_BINARY, R_OK|X_OK) == 0)
-  {
-    return true;
-  }
-#endif
-
-  return false;
-}
-
-bool has_memcached_binary()
-{
-#if defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY
-  if (access(MEMCACHED_BINARY, R_OK|X_OK) == 0)
-  {
-    return true;
-  }
-#endif
-
-  return false;
-}
-
-bool has_memcached_sasl_binary()
-{
-#if defined(HAVE_MEMCACHED_SASL_BINARY) && HAVE_MEMCACHED_SASL_BINARY
-  if (access(MEMCACHED_SASL_BINARY, R_OK|X_OK) == 0)
-  {
-    return true;
-  }
-#endif
-
-  return false;
-}
-
 }

+ 0 - 13
libtest/binaries.h

@@ -38,17 +38,4 @@
 
 namespace libtest {
 
-LIBTEST_API
-bool has_memcached_binary();
-
-LIBTEST_API
-bool has_memcached_sasl_binary();
-
-LIBTEST_API
-bool has_gearmand_binary();
-
-LIBTEST_API
-bool has_drizzled_binary();
-
 } // namespace libtest
-

+ 4 - 0
libtest/cmdline.h

@@ -38,6 +38,10 @@
 
 #include <spawn.h>
 
+// http://www.gnu.org/software/automake/manual/automake.html#Using-the-TAP-test-protocol
+#define EXIT_SKIP 77
+#define EXIT_FATAL 77
+
 namespace libtest {
 
 class Application {

+ 1 - 0
libtest/collection.cc

@@ -121,6 +121,7 @@ test_return_t Collection::exec()
       catch (libtest::fatal &e)
       {
         Error << "Fatal exception was thrown: " << e.what();
+        stream::cerr(__FILE__, __LINE__, __func__) << e.what();
         _failed++;
         throw;
       }

+ 23 - 0
libtest/comparison.hpp

@@ -86,6 +86,29 @@ bool _compare(const char *file, int line, const char *func, const T1_comparable&
   return true;
 }
 
+template <class T1_comparable, class T2_comparable>
+bool _compare_strcmp(const char *file, int line, const char *func, const T1_comparable& __expected, const T2_comparable& __actual)
+{
+  if (__expected == NULL)
+  {
+    fatal_message("Expected value was NULL, programmer error");
+  }
+
+  if (__actual == NULL)
+  {
+    libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " but got NULL";
+    return false;
+  }
+
+  if (strncmp(__expected, __actual, strlen(__expected)))
+  {
+    libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " passed \"" << __actual << "\"";
+    return false;
+  }
+
+  return true;
+}
+
 template <class T_comparable>
 bool _compare_zero(const char *file, int line, const char *func, T_comparable __actual)
 {

+ 9 - 4
libtest/fatal.cc

@@ -54,7 +54,7 @@ fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const cha
 
     strncpy(_mesg, last_error, sizeof(_mesg));
 
-    snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, int(_line), last_error, _func);
+    snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func);
   }
 
 static bool _disabled= false;
@@ -85,9 +85,14 @@ void fatal::increment_disabled_counter()
   _counter++;
 }
 
-disconnected::disconnected(const char *file, int line, const char *func, const char *instance, const in_port_t port, const char *format, ...) :
+disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg,
+                           const char *instance, const in_port_t port,
+                           const char *format, ...) :
+  std::runtime_error(func_arg),
   _port(port),
-  std::runtime_error(func)
+  _line(line_arg),
+  _file(file_arg),
+  _func(func_arg)
 {
   strncpy(_instance, instance, sizeof(_instance));
   va_list args;
@@ -96,7 +101,7 @@ disconnected::disconnected(const char *file, int line, const char *func, const c
   (void)vsnprintf(last_error, sizeof(last_error), format, args);
   va_end(args);
 
-  snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", file, int(line), last_error, func);
+  snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func);
 }
 
 } // namespace libtest

+ 18 - 0
libtest/fatal.hpp

@@ -108,10 +108,28 @@ public:
   static uint32_t disabled_counter();
   static void increment_disabled_counter();
 
+  int line()
+  {
+    return _line;
+  }
+
+  const char* file()
+  {
+    return _file;
+  }
+
+  const char* func()
+  {
+    return _func;
+  }
+
 private:
   char _error_message[BUFSIZ];
   in_port_t _port;
   char _instance[1024];
+  int _line;
+  const char*  _file;
+  const char* _func;
 };
 
 

+ 90 - 7
libtest/has.cc

@@ -35,13 +35,16 @@
  */
 
 #include <config.h>
-#include <libtest/has.hpp>
+#include <libtest/common.h>
 
 #include <cstdlib>
+#include <unistd.h>
 
-bool has_memcached_support(void)
+namespace libtest {
+
+bool has_libmemcached(void)
 {
-  if (HAVE_LIBMEMCACHED and HAVE_MEMCACHED_BINARY)
+  if (HAVE_LIBMEMCACHED)
   {
     return true;
   }
@@ -49,9 +52,9 @@ bool has_memcached_support(void)
   return false;
 }
 
-bool has_drizzle_support(void)
+bool has_libdrizzle(void)
 {
-  if (HAVE_LIBDRIZZLE and HAVE_DRIZZLED_BINARY)
+  if (HAVE_LIBDRIZZLE)
   {
     return true;
   }
@@ -72,12 +75,92 @@ bool has_postgres_support(void)
   return false;
 }
 
-bool has_mysql_support(void)
+
+bool has_gearmand()
+{
+  if (HAVE_GEARMAND_BINARY)
+  {
+    std::stringstream arg_buffer;
+
+    if (getenv("PWD") and strcmp(MEMCACHED_BINARY, "gearmand/gearmand") == 0)
+    {
+      arg_buffer << getenv("PWD");
+      arg_buffer << "/";
+    }
+    arg_buffer << GEARMAND_BINARY;
+
+    if (access(arg_buffer.str().c_str(), X_OK) == 0)
+    {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+bool has_drizzled()
+{
+  if (HAVE_DRIZZLED_BINARY)
+  {
+    if (access(DRIZZLED_BINARY, X_OK) == 0)
+    {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+bool has_mysqld()
 {
+#if defined(HAVE_MYSQL_BUILD) && HAVE_MYSQL_BUILD
   if (HAVE_MYSQL_BUILD)
   {
-    return true;
+    if (access(HAVE_MYSQL, X_OK) == 0)
+    {
+      return true;
+    }
   }
+#endif
 
   return false;
 }
+
+bool has_memcached()
+{
+  if (HAVE_MEMCACHED_BINARY)
+  {
+    std::stringstream arg_buffer;
+
+    if (getenv("PWD") and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0)
+    {
+      arg_buffer << getenv("PWD");
+      arg_buffer << "/";
+    }
+    arg_buffer << MEMCACHED_BINARY;
+
+    if (access(arg_buffer.str().c_str(), X_OK) == 0)
+    {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+bool has_memcached_sasl()
+{
+#if defined(HAVE_MEMCACHED_SASL_BINARY) && HAVE_MEMCACHED_SASL_BINARY
+  if (HAVE_MEMCACHED_SASL_BINARY)
+  {
+    if (access(MEMCACHED_SASL_BINARY, X_OK) == 0)
+    {
+      return true;
+    }
+  }
+#endif
+
+  return false;
+}
+
+} // namespace libtest

+ 24 - 4
libtest/has.hpp

@@ -36,10 +36,30 @@
 
 #pragma once
 
-bool has_memcached_support(void);
+namespace libtest {
 
-bool has_drizzle_support(void);
+LIBTEST_API
+bool has_libmemcached();
 
-bool has_postgres_support(void);
+LIBTEST_API
+bool has_libdrizzle();
 
-bool has_mysql_support(void);
+LIBTEST_API
+bool has_postgres_support();
+
+LIBTEST_API
+bool has_memcached();
+
+LIBTEST_API
+bool has_memcached_sasl();
+
+LIBTEST_API
+bool has_gearmand();
+
+LIBTEST_API
+bool has_drizzled();
+
+LIBTEST_API
+bool has_mysqld();
+
+} // namespace libtest

+ 1 - 2
libtest/main.cc

@@ -250,8 +250,7 @@ int main(int argc, char *argv[])
           break;
 
         case TEST_SKIPPED:
-          Out << "SKIP " << argv[0];
-          return EXIT_SUCCESS;
+          return EXIT_SKIP;
 
         case TEST_FAILURE:
           return EXIT_FAILURE;

Some files were not shown because too many files changed in this diff