proxygen
|
#include <TestUtil.h>
Classes | |
struct | NoOpChunkCob |
Public Types | |
using | ChunkCob = std::function< void(folly::StringPiece)> |
Public Member Functions | |
CaptureFD (int fd, ChunkCob chunk_cob=NoOpChunkCob()) | |
~CaptureFD () | |
void | release () |
std::string | read () const |
std::string | readIncremental () |
Private Attributes | |
ChunkCob | chunkCob_ |
TemporaryFile | file_ |
int | fd_ |
int | oldFDCopy_ |
off_t | readOffset_ |
Temporarily capture a file descriptor by redirecting it into a file. You can consume its entire output thus far via read(), incrementally via readIncremental(), or via callback using chunk_cob. Great for testing logging (see also glog*Pattern()).
Definition at line 222 of file TestUtil.h.
using folly::test::CaptureFD::ChunkCob = std::function<void(folly::StringPiece)> |
Definition at line 229 of file TestUtil.h.
|
explicit |
chunk_cob is is guaranteed to consume all the captured output. It is invoked on each readIncremental(), and also on FD release to capture as-yet unread lines. Chunks can be empty.
Definition at line 185 of file TestUtil.cpp.
References folly::netops::close(), fd_, file_, oldFDCopy_, and folly::test::TemporaryFile::path().
folly::test::CaptureFD::~CaptureFD | ( | ) |
Definition at line 206 of file TestUtil.cpp.
References release().
std::string folly::test::CaptureFD::read | ( | ) | const |
Reads the whole file into a string, but does not remove the redirect.
Definition at line 210 of file TestUtil.cpp.
References file_, folly::test::TemporaryFile::path(), folly::readFile(), and string.
std::string folly::test::CaptureFD::readIncremental | ( | ) |
Read any bytes that were appended to the file since the last readIncremental. Great for testing line-by-line output.
Definition at line 217 of file TestUtil.cpp.
References chunkCob_, f, folly::File::fd(), file_, folly::openNoInt(), folly::test::TemporaryFile::path(), folly::preadFull(), readOffset_, folly::size(), and string.
Referenced by release(), and TEST().
void folly::test::CaptureFD::release | ( | ) |
Restore the captured FD to its original state. It can be useful to do this before the destructor so that you can read() the captured data and log about it to the formerly captured stderr or stdout.
Definition at line 196 of file TestUtil.cpp.
References folly::netops::close(), fd_, oldFDCopy_, and readIncremental().
Referenced by ~CaptureFD().
|
private |
Definition at line 258 of file TestUtil.h.
Referenced by readIncremental().
|
private |
Definition at line 261 of file TestUtil.h.
Referenced by CaptureFD(), and release().
|
private |
Definition at line 259 of file TestUtil.h.
Referenced by CaptureFD(), read(), and readIncremental().
|
private |
Definition at line 262 of file TestUtil.h.
Referenced by CaptureFD(), and release().
|
private |
Definition at line 264 of file TestUtil.h.
Referenced by readIncremental().