New stats output for collection information.
authorBrian Aker <brian@gaz>
Mon, 11 Jan 2010 20:50:35 +0000 (12:50 -0800)
committerBrian Aker <brian@gaz>
Mon, 11 Jan 2010 20:50:35 +0000 (12:50 -0800)
tests/test.c
tests/test.h

index ee6f94dcd3e5f0d1d6928513f4ecdc0e5764e1ed..ff6bca680966e1125041e57a6efa737ba415a1b8 100644 (file)
 #include <unistd.h>
 #include <time.h>
 #include <fnmatch.h>
+#include <stdint.h>
 
 #include "test.h"
 
 static void world_stats_print(world_stats_st *stats)
 {
+  fputc('\n', stderr);
+  fprintf(stderr, "Total Collections\t\t\t\t%u\n", stats->collection_total);
+  fprintf(stderr, "\tFailed Collections\t\t\t%u\n", stats->collection_failed);
+  fprintf(stderr, "\tSkipped Collections\t\t\t%u\n", stats->collection_skipped);
+  fprintf(stderr, "\tSucceeded Collections\t\t%u\n", stats->collection_success);
+  fputc('\n', stderr);
   fprintf(stderr, "Total\t\t\t\t%u\n", stats->total);
   fprintf(stderr, "\tFailed\t\t\t%u\n", stats->failed);
   fprintf(stderr, "\tSkipped\t\t\t%u\n", stats->skipped);
@@ -143,13 +150,41 @@ int main(int argc, char *argv[])
 
   for (next= collection; next->name; next++)
   {
+    test_return_t collection_rc= TEST_SUCCESS;
     test_st *run;
+    bool failed= false;
+    bool skipped= false;
 
     run= next->tests;
     if (collection_to_run && fnmatch(collection_to_run, next->name, 0))
       continue;
 
-    fprintf(stderr, "\n%s\n\n", next->name);
+    stats.collection_total++;
+
+    if (world.collection_startup)
+    {
+      collection_rc= world.test_startup(world_ptr);
+    }
+
+    switch (collection_rc)
+    {
+      case TEST_SUCCESS:
+        fprintf(stderr, "\n%s\n\n", next->name);
+        break;
+      case TEST_FAILURE:
+        fprintf(stderr, "\n%s [ failed ]\n\n", next->name);
+        stats.failed++;
+        continue;
+      case TEST_SKIPPED:
+        fprintf(stderr, "\n%s [ skipping ]\n\n", next->name);
+        stats.skipped++;
+        continue;
+      case TEST_MEMORY_ALLOCATION_FAILURE:
+      case TEST_MAXIMUM_RETURN:
+      default:
+        assert(0);
+        break;
+    }
 
     for (x= 0; run->name; run++)
     {
@@ -215,13 +250,18 @@ error:
         break;
       case TEST_FAILURE:
         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.
         break;
       }
 
@@ -236,9 +276,36 @@ error:
           break;
       }
     }
+
+    if (failed)
+    {
+      stats.collection_failed++;
+    }
+
+    if (skipped)
+    {
+      stats.collection_skipped++;
+    }
+
+    if (! failed && ! skipped)
+    {
+      stats.collection_success++;
+    }
+
+    if (world.collection_shutdown)
+    {
+      world.collection_shutdown(world_ptr);
+    }
   }
 
-  fprintf(stderr, "All tests completed successfully\n\n");
+  if (stats.collection_failed || stats.collection_skipped)
+  {
+    fprintf(stderr, "Some test failures and/or skipped test occurred.\n\n");
+  }
+  else
+  {
+    fprintf(stderr, "All tests completed successfully\n\n");
+  }
 
   if (world.destroy)
   {
index 7385763ddb9ef8d370852e87a9444fdd4c9d5831..d5be8c3024cd5cc12f787013926904d91308a4e3 100644 (file)
@@ -82,9 +82,15 @@ struct world_st {
   test_callback_create_fn create;
   test_callback_fn destroy;
 
-  /* This is called a the beginning of any collection run. */
+  /* This is called a the beginning of any test run. */
   test_callback_fn test_startup;
 
+  /* This is called a the beginning of any collection run. */
+  test_callback_fn collection_startup;
+
+  /* This is called a the beginning of any collection run. */
+  test_callback_fn collection_shutdown;
+
   /* This called on a test if the test requires a flush call (the bool is from test_st) */
   test_callback_fn flush;
 
@@ -113,6 +119,10 @@ struct world_st {
   @note world_stats_st is a simple structure for tracking test successes.
 */
 typedef struct {
+  uint32_t collection_success;
+  uint32_t collection_skipped;
+  uint32_t collection_failed;
+  uint32_t collection_total;
   uint32_t success;
   uint32_t skipped;
   uint32_t failed;