Merge in docs.
[awesomized/libmemcached] / libtest / test.c
index 009c4be5c7e9289c550b36b3c4cdb0a9bc726250..0905e13b6fc94562c4303749af6b0c786910212d 100644 (file)
@@ -10,7 +10,7 @@
   Sample test application.
 */
 
-#include "config.h"
+#include <config.h>
 
 #include <unistd.h>
 
@@ -24,9 +24,8 @@
 #include <time.h>
 #include <stdint.h>
 
-#include <libmemcached/memcached.h>
-
 #include <libtest/test.h>
+#include <libtest/failed.h>
 
 static void world_stats_print(world_stats_st *stats)
 {
@@ -60,10 +59,12 @@ const char *test_strerror(test_return_t code)
     return "ok";
   case TEST_FAILURE:
     return "failed";
-  case TEST_MEMORY_ALLOCATION_FAILURE:
-    return "memory allocation";
+  case TEST_FATAL:
+    return "failed";
   case TEST_SKIPPED:
     return "skipped";
+  case TEST_MEMORY_ALLOCATION_FAILURE:
+    return "memory allocation";
   case TEST_MAXIMUM_RETURN:
   default:
     fprintf(stderr, "Unknown return value\n");
@@ -147,7 +148,6 @@ int main(int argc, char *argv[])
   char *wildcard= NULL;
   world_st world;
   collection_st *collection;
-  collection_st *next;
   void *world_ptr;
 
   world_stats_st stats;
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])
   if (sasl_client_init(NULL) != SASL_OK)
   {
      fprintf(stderr, "Failed to initialize sasl library!\n");
-     return 1;
+     return EXIT_FAILURE;
   }
 #endif
 
@@ -179,12 +179,23 @@ int main(int argc, char *argv[])
   }
 
   if (argc > 1)
+  {
     collection_to_run= argv[1];
+  }
+  else if (getenv("TEST_COLLECTION"))
+  {
+    collection_to_run= getenv("TEST_COLLECTION");
+  }
+
+  if (collection_to_run)
+    printf("Only testing %s\n", collection_to_run);
 
   if (argc == 3)
+  {
     wildcard= argv[2];
+  }
 
-  for (next= collection; next->name; next++)
+  for (collection_st *next= collection; next->name; next++)
   {
     test_return_t collection_rc= TEST_SUCCESS;
     test_st *run;
@@ -213,6 +224,10 @@ skip_pre:
       case TEST_SUCCESS:
         fprintf(stderr, "\n%s\n\n", next->name);
         break;
+      case TEST_FATAL:
+        fprintf(stderr, "\n%s [ failed ]\n\n", next->name);
+        stats.collection_failed++;
+        goto cleanup;
       case TEST_FAILURE:
         fprintf(stderr, "\n%s [ failed ]\n\n", next->name);
         stats.collection_failed++;
@@ -297,17 +312,25 @@ skip_pre:
         fprintf(stderr, "%ld.%03ld ", load_time / 1000, load_time % 1000);
         stats.success++;
         break;
+
+      case TEST_FATAL:
       case TEST_FAILURE:
+#if 0
+        push_failed_test(next->name, run->name);
+#endif
         stats.failed++;
         failed= true;
         break;
+
       case TEST_SKIPPED:
         stats.skipped++;
         skipped= true;
         break;
+
       case TEST_MEMORY_ALLOCATION_FAILURE:
         fprintf(stderr, "Exhausted memory, quitting\n");
         abort();
+
       case TEST_MAXIMUM_RETURN:
       default:
         assert(0); // Coding error.
@@ -324,6 +347,12 @@ skip_pre:
         if (rc != TEST_SUCCESS)
           break;
       }
+
+      // If we get a TEST_FATAL we move onto the next collection
+      if (return_code == TEST_FATAL)
+      {
+        break;
+      }
     }
 
     if (next->post && world.runner->post)
@@ -343,6 +372,9 @@ cleanup:
   if (stats.collection_failed || stats.collection_skipped)
   {
     fprintf(stderr, "Some test failures and/or skipped test occurred.\n\n");
+#if 0
+    print_failed_test();
+#endif
   }
   else
   {
@@ -357,15 +389,11 @@ cleanup:
     if (error != TEST_SUCCESS)
     {
       fprintf(stderr, "Failure during shutdown.\n");
-      stats.failed++; // We do this to make our exit code return 1
+      stats.failed++; // We do this to make our exit code return EXIT_FAILURE
     }
   }
 
   world_stats_print(&stats);
 
-#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
-  sasl_done();
-#endif
-
   return stats.failed == 0 ? 0 : 1;
 }