unittest-cpp/UnitTest++/ThrowingTestReporter.cpp
Austin Gilbert 2e53a17d7e With code proposed in Pull Request #95, when UNITTEST_NO_EXCEPTIONS is defined, the definition for REQUIRE macro is empty.
This commit adds functionality for stopping unit tests early when UNITTEST_NO_EXCEPTIONS is defined via std::longjmp.
2016-02-08 21:38:56 -06:00

61 lines
1.5 KiB
C++

#include "ThrowingTestReporter.h"
#include "RequiredCheckException.h"
#ifdef UNITTEST_NO_EXCEPTIONS
#include "ReportAssertImpl.h"
#endif
namespace UnitTest {
ThrowingTestReporter::ThrowingTestReporter(TestReporter* decoratedReporter)
: m_decoratedReporter(decoratedReporter)
{}
//virtual
ThrowingTestReporter::~ThrowingTestReporter()
{}
//virtual
void ThrowingTestReporter::ReportTestStart(TestDetails const& test)
{
if(m_decoratedReporter)
{
m_decoratedReporter->ReportTestStart(test);
}
}
//virtual
void ThrowingTestReporter::ReportFailure(TestDetails const& test, char const* failure)
{
if(m_decoratedReporter)
{
m_decoratedReporter->ReportFailure(test, failure);
}
#ifndef UNITTEST_NO_EXCEPTIONS
throw RequiredCheckException();
#else
static const int stopTest = 1;
UNITTEST_LONGJMP(*UnitTest::Detail::GetAssertJmpBuf(), stopTest);
#endif
}
//virtual
void ThrowingTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed)
{
if(m_decoratedReporter)
{
m_decoratedReporter->ReportTestFinish(test, secondsElapsed);
}
}
//virtual
void ThrowingTestReporter::ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed)
{
if(m_decoratedReporter)
{
m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed);
}
}
}