Skip to content
Snippets Groups Projects
Commit cfe37cbf authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

Break out std::ostream << CaptureLog routine for general use.

parent 0ef99cd3
No related branches found
No related tags found
No related merge requests found
...@@ -31,11 +31,11 @@ ...@@ -31,11 +31,11 @@
#include <tut/tut.hpp> #include <tut/tut.hpp>
#include "llerrorcontrol.h" #include "llerrorcontrol.h"
#include "stringize.h"
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <list> #include <list>
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#include <sstream>
// statically reference the function in test.cpp... it's short, we could // statically reference the function in test.cpp... it's short, we could
// replicate, but better to reuse // replicate, but better to reuse
...@@ -131,14 +131,9 @@ class CaptureLog : public LLError::Recorder ...@@ -131,14 +131,9 @@ class CaptureLog : public LLError::Recorder
if (! required) if (! required)
return std::string(); return std::string();
std::ostringstream out; throw tut::failure(STRINGIZE("failed to find '" << search
out << "failed to find '" << search << "' in captured log messages:"; << "' in captured log messages:\n"
for (MessageList::const_iterator mi(mMessages.begin()), mend(mMessages.end()); << *this));
mi != mend; ++mi)
{
out << '\n' << *mi;
}
throw tut::failure(out.str());
} }
typedef std::list<std::string> MessageList; typedef std::list<std::string> MessageList;
...@@ -146,4 +141,20 @@ class CaptureLog : public LLError::Recorder ...@@ -146,4 +141,20 @@ class CaptureLog : public LLError::Recorder
LLError::Settings* mOldSettings; 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) */ #endif /* ! defined(LL_WRAPLLERRS_H) */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment