diff --git a/src/beast/modules/beast_core/diagnostic/UnitTest.cpp b/src/beast/modules/beast_core/diagnostic/UnitTest.cpp index 0585ec0ab2..edcd7a903a 100644 --- a/src/beast/modules/beast_core/diagnostic/UnitTest.cpp +++ b/src/beast/modules/beast_core/diagnostic/UnitTest.cpp @@ -54,6 +54,11 @@ String const& UnitTest::getPackageName() const noexcept return m_packageName; } +Journal UnitTest::journal () const +{ + return m_runner->journal(); +} + UnitTest::TestList& UnitTest::getAllTests() { static TestList s_tests; @@ -224,8 +229,39 @@ void UnitTest::finishCase () //============================================================================== +UnitTests::JournalSink::JournalSink (UnitTests& tests) + : m_tests (tests) +{ +} + +void UnitTests::JournalSink::write (Journal::Severity, std::string const& text) +{ + m_tests.logMessage (text); +} + +bool UnitTests::JournalSink::active (Journal::Severity) +{ + return true; +} + +bool UnitTests::JournalSink::console () +{ + return false; +} + +void UnitTests::JournalSink::set_severity (Journal::Severity) +{ +} + +void UnitTests::JournalSink::set_console (bool) +{ +} + +//============================================================================== + UnitTests::UnitTests() : m_assertOnFailure (false) + , m_sink (*this) { } diff --git a/src/beast/modules/beast_core/diagnostic/UnitTest.h b/src/beast/modules/beast_core/diagnostic/UnitTest.h index 72b9140f8f..59e5ce7697 100644 --- a/src/beast/modules/beast_core/diagnostic/UnitTest.h +++ b/src/beast/modules/beast_core/diagnostic/UnitTest.h @@ -210,6 +210,9 @@ public: /** Returns the run option of the test. */ When getWhen () const noexcept { return m_when; } + /** Returns a Journal that logs to the UnitTests. */ + Journal journal () const; + /** Runs the test, using the specified UnitTests. You shouldn't need to call this method directly - use UnitTests::runTests() instead. @@ -479,6 +482,11 @@ public: */ void runTests (TestList const& tests, int64 randomSeed = 0); + Journal journal () + { + return Journal (m_sink); + } + protected: friend class UnitTest; @@ -505,9 +513,24 @@ private: void runTest (UnitTest& test); private: + class JournalSink : public Journal::Sink, public Uncopyable + { + public: + explicit JournalSink (UnitTests& tests); + void write (Journal::Severity severity, std::string const& text); + bool active (Journal::Severity severity); + bool console (); + void set_severity (Journal::Severity severity); + void set_console (bool); + + private: + UnitTests& m_tests; + }; + bool m_assertOnFailure; ScopedPointer m_results; Random m_random; + JournalSink m_sink; }; #endif