libtest: fix doesnotexist spawn test
[awesomized/libmemcached] / libtest / framework.cc
index 6cca8450abcbcffbc4a7672518acb96a668c0f0f..2c9ba74b4aebc346b40856eb51b358a4263077a0 100644 (file)
  *
  */
 
-#include <config.h>
+#include "libtest/yatlcon.h"
 
 #include <libtest/common.h>
 #include <libtest/collection.h>
 #include <libtest/signal.h>
 
+#include <algorithm>
 #include <fnmatch.h>
 #include <iostream>
 
@@ -67,7 +68,7 @@ Framework::Framework(libtest::SignalThread& signal_,
   get_world(this);
 }
 
-void Framework::collections(collection_st* collections_)
+void Framework::collections(collection_st collections_[])
 {
   for (collection_st *next= collections_; next and next->name; next++)
   {
@@ -86,12 +87,8 @@ Framework::~Framework()
 
   delete _runner;
 
-  for (std::vector<Collection*>::iterator iter= _collection.begin();
-       iter != _collection.end();
-       ++iter)
-  {
-    delete *iter;
-  }
+  std::for_each(_collection.begin(), _collection.end(), DeleteFromVector());
+  _collection.clear();
 }
 
 bool Framework::match(const char* arg)
@@ -110,48 +107,50 @@ void Framework::exec()
        iter != _collection.end() and (_signal.is_shutdown() == false);
        ++iter)
   {
-    if (_only_run.empty() == false and
-        fnmatch(_only_run.c_str(), (*iter)->name(), 0))
+    if (*iter)
     {
-      continue;
-    }
-
-    _total++;
+      if (_only_run.empty() == false and
+          fnmatch(_only_run.c_str(), (*iter)->name(), 0))
+      {
+        continue;
+      }
 
-    try
-    {
-      switch ((*iter)->exec())
+      _total++;
+
+      try {
+        switch ((*iter)->exec())
+        {
+          case TEST_FAILURE:
+            _failed++;
+            break;
+
+          case TEST_SKIPPED:
+            _skipped++;
+            break;
+
+            // exec() can return SUCCESS, but that doesn't mean that some tests did
+            // not fail or get skipped.
+          case TEST_SUCCESS:
+            _success++;
+            break;
+        }
+      }
+      catch (const libtest::fatal& e)
       {
-      case TEST_FAILURE:
         _failed++;
-        break;
-
-      case TEST_SKIPPED:
-        _skipped++;
-        break;
-
-        // exec() can return SUCCESS, but that doesn't mean that some tests did
-        // not fail or get skipped.
-      case TEST_SUCCESS:
-        _success++;
-        break;
+        stream::cerr(e.file(), e.line(), e.func()) << e.what();
+      }
+      catch (const libtest::disconnected& e)
+      {
+        _failed++;
+        Error << "Unhandled disconnection occurred:" << e.what();
+        throw;
+      }
+      catch (...)
+      {
+        _failed++;
+        throw;
       }
-    }
-    catch (libtest::fatal& e)
-    {
-      _failed++;
-      stream::cerr(e.file(), e.line(), e.func()) << e.mesg();
-    }
-    catch (libtest::disconnected& e)
-    {
-      _failed++;
-      stream::cerr(e.file(), e.line(), e.func()) << "Unhandled disconnection occurred: " << e.mesg();
-      throw;
-    }
-    catch (...)
-    {
-      _failed++;
-      throw;
     }
   }