From f904867720291bc63ea5e140194069d29f70fb40 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 1 Mar 2012 14:33:23 -0500 Subject: 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. --- indra/llcommon/tests/llprocess_test.cpp | 6 +----- indra/llcommon/tests/wrapllerrs.h | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/indra/llcommon/tests/llprocess_test.cpp b/indra/llcommon/tests/llprocess_test.cpp index c07a9d3925..6103764f24 100644 --- a/indra/llcommon/tests/llprocess_test.cpp +++ b/indra/llcommon/tests/llprocess_test.cpp @@ -788,7 +788,6 @@ namespace tut py.mPy = LLProcess::create(py.mParams); ensure("should have rejected 'bogus'", ! py.mPy); std::string message(recorder.messageWith("bogus")); - ensure("did not log 'bogus' type", ! message.empty()); ensure_contains("did not name 'stdin'", message, "stdin"); } @@ -820,7 +819,6 @@ namespace tut py.mPy = LLProcess::create(py.mParams); ensure("should have rejected 'tpipe'", ! py.mPy); std::string message(recorder.messageWith("tpipe")); - ensure("did not log 'tpipe' type", ! message.empty()); ensure_contains("did not name 'stdout'", message, "stdout"); } @@ -839,7 +837,6 @@ namespace tut py.mPy = LLProcess::create(py.mParams); ensure("should have rejected 'npipe'", ! py.mPy); std::string message(recorder.messageWith("npipe")); - ensure("did not log 'npipe' type", ! message.empty()); ensure_contains("did not name 'stderr'", message, "stderr"); } @@ -856,7 +853,6 @@ namespace tut ensure_equals("Status.mState", py.mPy->getStatus().mState, LLProcess::EXITED); ensure_equals("Status.mData", py.mPy->getStatus().mData, 7); std::string message(recorder.messageWith("not yet supported")); - ensure("did not log pipe name warning", ! message.empty()); ensure_contains("log message did not mention internal pipe name", message, "somename"); } @@ -905,7 +901,7 @@ namespace tut { \ CaptureLog recorder; \ ensure(#CODE " succeeded", ! (CODE)); \ - ensure("wrong log message", ! recorder.messageWith(EXPECT).empty()); \ + recorder.messageWith(EXPECT); \ } while (0) template<> template<> 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 #include "llerrorcontrol.h" #include #include #include #include +#include // 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::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 MessageList; -- cgit v1.2.3