diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2012-03-01 14:33:23 -0500 |
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2012-03-01 14:33:23 -0500 |
| commit | f904867720291bc63ea5e140194069d29f70fb40 (patch) | |
| tree | de651fbc78a75a885acbab3214f60a7ae1942f15 /indra/llcommon/tests/wrapllerrs.h | |
| parent | 22fcb563ce45e64f23c9911bdcd07b0086bc892a (diff) | |
Make CaptureLog::withMessage() raise tut::failure if not found.
All known callers were using ensure(! withMessage(...).empty()). Centralize
that logic. Make failure message report the string being sought and the log
messages in which it wasn't found.
In case someone does want to permit the search to fail, add an optional
'required' parameter, default true.
Leverage new functionality in llprocess_test.cpp.
Diffstat (limited to 'indra/llcommon/tests/wrapllerrs.h')
| -rw-r--r-- | indra/llcommon/tests/wrapllerrs.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/indra/llcommon/tests/wrapllerrs.h b/indra/llcommon/tests/wrapllerrs.h index a61f8451b3..28ffbf517f 100644 --- a/indra/llcommon/tests/wrapllerrs.h +++ b/indra/llcommon/tests/wrapllerrs.h @@ -29,11 +29,13 @@ #if ! defined(LL_WRAPLLERRS_H) #define LL_WRAPLLERRS_H +#include <tut/tut.hpp> #include "llerrorcontrol.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 @@ -117,17 +119,26 @@ public: /// Don't assume the message we want is necessarily the LAST log message /// emitted by the underlying code; search backwards through all messages /// for the sought string. - std::string messageWith(const std::string& search) + std::string messageWith(const std::string& search, bool required=true) { - for (std::list<std::string>::const_reverse_iterator rmi(mMessages.rbegin()), - rmend(mMessages.rend()); + for (MessageList::const_reverse_iterator rmi(mMessages.rbegin()), rmend(mMessages.rend()); rmi != rmend; ++rmi) { if (rmi->find(search) != std::string::npos) return *rmi; } // failed to find any such message - return std::string(); + 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()); } typedef std::list<std::string> MessageList; |
