#include <chrono>
#include <cstring>
+#include <exception>
#include <iostream>
#include <list>
#include <map>
+#include <queue>
#include <set>
#include <sstream>
#include <string>
std::string m_startTestId;
bool m_runIgnored;
+ std::queue<std::string> m_failReason;
+
public:
TestRunner() :
m_currentTestCase(nullptr)
std::chrono::system_clock::duration result,
std::chrono::system_clock::duration resultMax);
+ void addFailReason(const std::string &reason);
+
typedef void (*TestCase)();
private:
void RunTests();
+ std::string getConcatedFailReason(const std::string &reason);
+
void CollectResult(const std::string& id,
const std::string& description,
const TestResultsCollectorBase::FailStatus::Type status
* body. Failing assertion indicates failing test.
*/
-#define RUNNER_ASSERT_MSG(test, message) \
- do \
- { \
- DPL::Test::TestRunnerSingleton::Instance().MarkAssertion(); \
- \
- if (!(test)) \
- { \
- std::ostringstream assertMsg; \
- assertMsg << message << gdbbacktrace(); \
- throw DPL::Test::TestRunner::TestFailed(#test, \
- __FILE__, \
- __LINE__, \
- assertMsg.str()); \
- } \
+#define RUNNER_ASSERT_MSG(test, message) \
+ do \
+ { \
+ DPL::Test::TestRunnerSingleton::Instance().MarkAssertion(); \
+ \
+ if (!(test)) \
+ { \
+ std::ostringstream assertMsg; \
+ assertMsg << message << gdbbacktrace(); \
+ DPL::Test::TestRunner::TestFailed e(#test, \
+ __FILE__, \
+ __LINE__, \
+ assertMsg.str()); \
+ if (!std::uncaught_exception()) \
+ throw e; \
+ DPL::Test::TestRunnerSingleton::Instance().addFailReason(e.GetMessage()); \
+ } \
} while (0)
-#define RUNNER_ASSERT_ERRNO_MSG(test, message) \
- do \
- { \
- DPL::Test::TestRunnerSingleton::Instance().MarkAssertion(); \
- \
- if (!(test)) \
- { \
- const char *err = strerror(errno); \
- std::ostringstream assertMsg; \
- assertMsg << message; \
- if (!assertMsg.str().empty()) \
- assertMsg << ". "; \
- assertMsg << err << gdbbacktrace(); \
- throw DPL::Test::TestRunner::TestFailed(#test, \
- __FILE__, \
- __LINE__, \
- assertMsg.str()); \
- } \
+#define RUNNER_ASSERT_ERRNO_MSG(test, message) \
+ do \
+ { \
+ DPL::Test::TestRunnerSingleton::Instance().MarkAssertion(); \
+ \
+ if (!(test)) \
+ { \
+ const char *err = strerror(errno); \
+ std::ostringstream assertMsg; \
+ assertMsg << message; \
+ if (!assertMsg.str().empty()) \
+ assertMsg << ". "; \
+ assertMsg << err << gdbbacktrace(); \
+ DPL::Test::TestRunner::TestFailed e(#test, \
+ __FILE__, \
+ __LINE__, \
+ assertMsg.str()); \
+ if (!std::uncaught_exception()) \
+ throw e; \
+ DPL::Test::TestRunnerSingleton::Instance().addFailReason(e.GetMessage()); \
+ } \
} while (0)
#define RUNNER_ASSERT_ERRNO(test) \
CollectResult(testCase.name,
"",
TestResultsCollectorBase::FailStatus::FAILED,
- e.GetMessage());
+ getConcatedFailReason(e.GetMessage()));
setCurrentTestCase(nullptr);
return FAILED;
testCase->m_performanceMaxTime = resultMax;
}
+void TestRunner::addFailReason(const std::string &reason)
+{
+ m_failReason.push(reason);
+}
+
+std::string TestRunner::getConcatedFailReason(const std::string &reason)
+{
+ std::string ret;
+ while (!m_failReason.empty())
+ {
+ ret += m_failReason.front();
+ m_failReason.pop();
+ }
+ return reason + ret;
+}
void TestRunner::CollectResult(
const std::string& id,