From cfe37cbfb5bdec0aa01c86a608ecc6cdc3df8a2a Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 1 Mar 2012 22:45:16 -0500
Subject: Break out std::ostream << CaptureLog routine for general use.

---
 indra/llcommon/tests/wrapllerrs.h | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

(limited to 'indra')

diff --git a/indra/llcommon/tests/wrapllerrs.h b/indra/llcommon/tests/wrapllerrs.h
index 10cf25b39e..a9c0c19c28 100644
--- a/indra/llcommon/tests/wrapllerrs.h
+++ b/indra/llcommon/tests/wrapllerrs.h
@@ -31,11 +31,11 @@
 
 #include <tut/tut.hpp>
 #include "llerrorcontrol.h"
+#include "stringize.h"
 #include <boost/bind.hpp>
 #include <list>
 #include <string>
 #include <stdexcept>
-#include <sstream>
 
 // statically reference the function in test.cpp... it's short, we could
 // replicate, but better to reuse
@@ -131,14 +131,9 @@ public:
         if (! required)
             return std::string();
 
-        std::ostringstream out;
-        out << "failed to find '" << search << "' in captured log messages:";
-        for (MessageList::const_iterator mi(mMessages.begin()), mend(mMessages.end());
-             mi != mend; ++mi)
-        {
-            out << '\n' << *mi;
-        }
-        throw tut::failure(out.str());
+        throw tut::failure(STRINGIZE("failed to find '" << search
+                                     << "' in captured log messages:\n"
+                                     << *this));
     }
 
     typedef std::list<std::string> MessageList;
@@ -146,4 +141,20 @@ public:
     LLError::Settings* mOldSettings;
 };
 
+std::ostream& operator<<(std::ostream& out, const CaptureLog& log)
+{
+    CaptureLog::MessageList::const_iterator mi(log.mMessages.begin()), mend(log.mMessages.end());
+    if (mi != mend)
+    {
+        // handle first message separately: it doesn't get a newline
+        out << *mi++;
+        for ( ; mi != mend; ++mi)
+        {
+            // every subsequent message gets a newline
+            out << '\n' << *mi;
+        }
+    }
+    return out;
+}
+
 #endif /* ! defined(LL_WRAPLLERRS_H) */
-- 
cgit v1.2.3