Sync libtest.
[m6w6/libmemcached] / libtest / test.cc
index cafc48d4e45cfa9f2b41963ce73d3da0d15dab9b..fb18e0ea892772767961cd06c285c40c1dd298b9 100644 (file)
@@ -77,6 +77,7 @@ static long int timedif(struct timeval a, struct timeval b)
 int main(int argc, char *argv[])
 {
   bool opt_repeat= false;
+  bool opt_quiet= false;
   std::string collection_to_run;
 
   // Options parsing
@@ -84,14 +85,17 @@ int main(int argc, char *argv[])
     enum long_option_t {
       OPT_LIBYATL_VERSION,
       OPT_LIBYATL_MATCH_COLLECTION,
+      OPT_LIBYATL_QUIET,
       OPT_LIBYATL_REPEAT
     };
 
     static struct option long_options[]=
     {
-      {"repeat", no_argument, NULL, OPT_LIBYATL_REPEAT},
-      {"collection", required_argument, NULL, OPT_LIBYATL_MATCH_COLLECTION},
-      {0, 0, 0, 0}
+      { "version", no_argument, NULL, OPT_LIBYATL_VERSION },
+      { "quiet", no_argument, NULL, OPT_LIBYATL_QUIET },
+      { "repeat", no_argument, NULL, OPT_LIBYATL_REPEAT },
+      { "collection", required_argument, NULL, OPT_LIBYATL_MATCH_COLLECTION },
+      { 0, 0, 0, 0 }
     };
 
     int option_index= 0;
@@ -108,6 +112,10 @@ int main(int argc, char *argv[])
       case OPT_LIBYATL_VERSION:
         break;
 
+      case OPT_LIBYATL_QUIET:
+        opt_quiet= true;
+        break;
+
       case OPT_LIBYATL_REPEAT:
         opt_repeat= true;
         break;
@@ -129,11 +137,27 @@ int main(int argc, char *argv[])
 
   srandom((unsigned int)time(NULL));
 
-  if (getenv("LIBTEST_QUIET") and strcmp(getenv("LIBTEST_QUIET"), "0") == 0)
+  int repeat;
+  if (bool(getenv("YATL_REPEAT")) and (repeat= atoi(getenv("YATL_REPEAT"))))
   {
-    close(STDOUT_FILENO);
+    opt_repeat= true;
+  }
+
+  if ((getenv("YATL_QUIET") and strcmp(getenv("YATL_QUIET"), "0") == 0) or opt_quiet)
+  {
+    opt_quiet= true;
   }
   else if (getenv("JENKINS_URL"))
+  {
+    if (getenv("YATL_QUIET") and strcmp(getenv("YATL_QUIET"), "1") == 0)
+    { }
+    else
+    {
+      opt_quiet= true;
+    }
+  }
+
+  if (opt_quiet)
   {
     close(STDOUT_FILENO);
   }
@@ -173,7 +197,7 @@ int main(int argc, char *argv[])
       fatal_assert(sigignore(SIGPIPE) == 0);
 
       libtest::SignalThread signal;
-      if (not signal.setup())
+      if (signal.setup() == false)
       {
         Error << "Failed to setup signals";
         return EXIT_FAILURE;
@@ -326,6 +350,11 @@ int main(int argc, char *argv[])
             }
           }
 
+          catch (libtest::fatal &e)
+          {
+            Error << "Fatal exception was thrown: " << e.what();
+            return_code= TEST_FAILURE;
+          }
           catch (std::exception &e)
           {
             Error << "Exception was thrown: " << e.what();