diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2014-08-07 16:26:51 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2014-08-07 18:36:05 -0400 |
commit | a88395dff3cc8bc3beec8356b8b25869d9c6cfe4 (patch) | |
tree | eedbfd99b844ac1a167719fe8b24d3d467ae48e0 /src/mongo/unittest/unittest.h | |
parent | d261864e9156af7ecc3d0491111dffa0161e9d0d (diff) | |
download | mongo-a88395dff3cc8bc3beec8356b8b25869d9c6cfe4.tar.gz |
SERVER-14825 Add utility methods to C++ unit tests for capturing and examining log messages.
Diffstat (limited to 'src/mongo/unittest/unittest.h')
-rw-r--r-- | src/mongo/unittest/unittest.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h index 8e27707b391..ccef6dc9925 100644 --- a/src/mongo/unittest/unittest.h +++ b/src/mongo/unittest/unittest.h @@ -45,6 +45,7 @@ #include "mongo/base/status_with.h" #include "mongo/logger/logstream_builder.h" +#include "mongo/logger/message_log_domain.h" #include "mongo/stdx/functional.h" #include "mongo/util/assert_util.h" #include "mongo/util/mongoutils/str.h" @@ -263,6 +264,29 @@ namespace mongo { class FixtureExceptionForTesting : public std::exception { }; + /** + * Starts capturing messages logged by code under test. + * + * Log messages will still also go to their default destination; this + * code simply adds an additional sink for log messages. + * + * Clears any previously captured log lines. + */ + void startCapturingLogMessages(); + + /** + * Stops capturing log messages logged by code under test. + */ + void stopCapturingLogMessages(); + + /** + * Gets a vector of strings, one log line per string, captured since + * the last call to startCapturingLogMessages() in this test. + */ + const std::vector<std::string>& getCapturedLogMessages() const { + return _capturedLogMessages; + } + private: /** * Called on the test object before running the test. @@ -278,6 +302,10 @@ namespace mongo { * The test itself. */ virtual void _doTest() = 0; + + bool _isCapturingLogMessages; + std::vector<std::string> _capturedLogMessages; + logger::MessageLogDomain::AppenderHandle _captureAppenderHandle; }; /** |