From 33f7fa342f92eb747954e60ae1003c419e0761ed Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 4 Oct 2010 10:53:37 +0000 Subject: [PATCH] Don't throw assert failure exception in the test suite if it's unsafe. Don't throw when already handling an exception as it would result in a call to terminate() and no useful information about the test failure would be given. Abort ourselves instead to at least give the message about the assert failure. This should help debug the mysterious ListCtrlTestCase failures in buildbot wxGTK builds. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/test.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/test.cpp b/tests/test.cpp index 1e59f59806..ca957f81d2 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -41,6 +41,7 @@ #include "wx/afterstd.h" #include "wx/cmdline.h" +#include #include #ifdef __WXMSW__ @@ -104,16 +105,33 @@ static void TestAssertHandler(const wxString& file, const wxString& cond, const wxString& msg) { - // can't throw from other threads, die immediately + // Determine whether we can safely throw an exception to just make the test + // fail or whether we need to abort (in this case "msg" will contain the + // explanation why did we decide to do it). + wxString abortReason; if ( !wxIsMainThread() ) { - wxPrintf("%s in a worker thread -- aborting.", - FormatAssertMessage(file, line, func, cond, msg)); - fflush(stdout); - _exit(-1); + // Exceptions thrown from worker threads are not caught currently and + // so we'd just die without any useful information -- abort instead. + abortReason = "in a worker thread"; + } + else if ( uncaught_exception() ) + { + // Throwing while already handling an exception would result in + // terminate() being called and we wouldn't get any useful information + // about why the test failed then. + abortReason = "while handling an exception"; + } + else // Can "safely" throw from here. + { + throw TestAssertFailure(file, line, func, cond, msg); } - throw TestAssertFailure(file, line, func, cond, msg); + wxFprintf(stderr, "%s %s -- aborting.", + FormatAssertMessage(file, line, func, cond, msg), + abortReason); + fflush(stderr); + _exit(-1); } #endif // wxDEBUG_LEVEL -- 2.45.2