First pass on sync with gearman yatl.
[awesomized/libmemcached] / libtest / main.cc
index 79f177c3ca60bfe0d513282da35825bceea552ae..6231ba121f8d47a06af10f07c03f65e70ca415f5 100644 (file)
@@ -34,7 +34,7 @@
  *
  */
 
-#include <config.h>
+#include "libtest/yatlcon.h"
 #include <libtest/common.h>
 
 #include <cassert>
@@ -43,6 +43,7 @@
 #include <ctime>
 #include <fnmatch.h>
 #include <iostream>
+#include <fstream>
 #include <memory>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -58,7 +59,7 @@
 
 using namespace libtest;
 
-static void stats_print(Framework *frame)
+static void stats_print(libtest::Framework *frame)
 {
   if (frame->failed() == 0 and frame->success() == 0)
   {
@@ -87,6 +88,23 @@ int main(int argc, char *argv[])
   bool opt_quiet= false;
   std::string collection_to_run;
   std::string wildcard;
+  std::string binary_name;
+
+  const char *just_filename= rindex(argv[0], '/');
+  if (just_filename)
+  {
+    just_filename++;
+  }
+  else
+  {
+    just_filename= argv[0];
+  }
+
+  if (just_filename[0] == 'l' and just_filename[1] == 't' and  just_filename[2] == '-')
+  {
+    just_filename+= 3;
+  }
+  binary_name.append(just_filename);
 
   /*
     Valgrind does not currently work reliably, or sometimes at all, on OSX
@@ -187,27 +205,39 @@ int main(int argc, char *argv[])
     }
   }
 
+  if ((bool(getenv("YATL_RUN_MASSIVE_TESTS"))) or opt_massive)
+  {
+    opt_massive= true;
+  }
+
   if (opt_quiet)
   {
     close(STDOUT_FILENO);
   }
 
-  char buffer[1024];
+  if (opt_massive)
+  {
+    is_massive(opt_massive);
+  }
+
+  libtest::vchar_t tmp_directory;
+  tmp_directory.resize(1024);
   if (getenv("LIBTEST_TMP"))
   {
-    snprintf(buffer, sizeof(buffer), "%s", getenv("LIBTEST_TMP"));
+    snprintf(&tmp_directory[0], tmp_directory.size(), "%s", getenv("LIBTEST_TMP"));
   }
   else
   {
-    snprintf(buffer, sizeof(buffer), "%s", LIBTEST_TEMP);
+    snprintf(&tmp_directory[0], tmp_directory.size(), "%s", LIBTEST_TEMP);
   }
 
-  if (chdir(buffer) == -1)
+  if (chdir(&tmp_directory[0]) == -1)
   {
-    char getcwd_buffer[1024];
-    char *dir= getcwd(getcwd_buffer, sizeof(getcwd_buffer));
+    libtest::vchar_t getcwd_buffer;
+    getcwd_buffer.resize(1024);
+    char *dir= getcwd(&getcwd_buffer[0], getcwd_buffer.size());
 
-    Error << "Unable to chdir() from " << dir << " to " << buffer << " errno:" << strerror(errno);
+    Error << "Unable to chdir() from " << dir << " to " << &tmp_directory[0] << " errno:" << strerror(errno);
     return EXIT_FAILURE;
   }
 
@@ -251,7 +281,7 @@ int main(int argc, char *argv[])
         return EXIT_FAILURE;
       }
 
-      std::auto_ptr<Framework> frame(new Framework(signal, collection_to_run, wildcard));
+      std::auto_ptr<libtest::Framework> frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard));
 
       // Run create(), bail on error.
       {
@@ -264,7 +294,7 @@ int main(int argc, char *argv[])
           return EXIT_SKIP;
 
         case TEST_FAILURE:
-          std::cerr << "frame->create()" << std::endl;
+          std::cerr << "Could not call frame->create()" << std::endl;
           return EXIT_FAILURE;
         }
       }
@@ -293,11 +323,20 @@ int main(int argc, char *argv[])
       }
       else if (frame->success() and (frame->failed() == 0))
       {
+        Out;
         Out << "All tests completed successfully.";
       }
 
       stats_print(frame.get());
 
+      std::ofstream xml_file;
+      std::string file_name;
+      file_name.append(&tmp_directory[0]);
+      file_name.append(frame->name());
+      file_name.append(".xml");
+      xml_file.open(file_name.c_str(), std::ios::trunc);
+      libtest::Formatter::xml(*frame, xml_file);
+
       Outn(); // Generate a blank to break up the messages if make check/test has been run
     } while (exit_code == EXIT_SUCCESS and --opt_repeat);
   }