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.meow-7.2.2
parent
22fcb563ce
commit
f904867720
|
|
@ -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<>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue