Add Journal to UnitTest

This commit is contained in:
Vinnie Falco
2013-10-11 18:07:22 -07:00
parent 58da1065d6
commit d5954fffa8
2 changed files with 59 additions and 0 deletions

View File

@@ -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)
{
}

View File

@@ -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 <Results> m_results;
Random m_random;
JournalSink m_sink;
};
#endif