Output test name before GTK error messages in the test suite

Try to make it possible to understand where exactly do the GTK+ errors
appearing in the buildbot slaves output originate from by installing a custom
Glib log handler and prefixing the normal log messages with the name of the
test running when they're generated.

This required a small refactoring of DetailListener which is now always
installed, in order to always have access to the current test name, but still
needs to be explicitly enabled to produce output.
This commit is contained in:
Vadim Zeitlin 2016-06-29 18:49:47 +02:00
parent 8686ca62e7
commit 68d235fed3

View File

@ -54,7 +54,11 @@
#if wxUSE_GUI
#include "testableframe.h"
#endif
#ifdef __WXGTK__
#include <glib.h>
#endif // __WXGTK__
#endif // wxUSE_GUI
#include "wx/socket.h"
#include "wx/evtloop.h"
@ -222,17 +226,34 @@ public:
class DetailListener : public CppUnit::TestListener
{
public:
DetailListener(bool doTiming = false):
DetailListener() :
CppUnit::TestListener(),
m_timing(doTiming)
m_verboseLogging(false),
m_timing(false)
{
}
void EnableVerboseLog(bool withTimings)
{
m_verboseLogging = true;
m_timing = withTimings;
}
// May return empty string if not running any tests currently.
static const char* GetCurrentTest() { return ms_currentTest.c_str(); }
virtual void startTest(CppUnit::Test *test)
{
printf(" %-60s ", test->getName().c_str());
m_result = RESULT_OK;
m_watch.Start();
ms_currentTest = test->getName();
if ( m_verboseLogging )
{
printf(" %-60s ", ms_currentTest.c_str());
m_result = RESULT_OK;
if ( m_timing )
m_watch.Start();
}
}
virtual void addFailure(const CppUnit::TestFailure& failure)
@ -242,11 +263,17 @@ public:
virtual void endTest(CppUnit::Test * WXUNUSED(test))
{
m_watch.Pause();
printf("%s", GetResultStr(m_result));
if (m_timing)
printf(" %6ld ms", m_watch.Time());
printf("\n");
if ( m_verboseLogging )
{
if ( m_timing )
m_watch.Pause();
printf("%s", GetResultStr(m_result));
if (m_timing)
printf(" %6ld ms", m_watch.Time());
printf("\n");
}
ms_currentTest.clear();
}
protected :
@ -273,11 +300,17 @@ protected :
return resultTypeNames[type];
}
bool m_verboseLogging;
bool m_timing;
wxStopWatch m_watch;
ResultType m_result;
private:
static string ms_currentTest;
};
string DetailListener::ms_currentTest;
#if wxUSE_GUI
typedef wxApp TestAppBase;
#else
@ -531,6 +564,23 @@ void DeleteTestWindow(wxWindow* win)
delete win;
}
#ifdef __WXGTK__
extern "C"
void
wxTestGLogHandler(const gchar* domain,
GLogLevelFlags level,
const gchar* message,
gpointer data)
{
fprintf(stderr, "** GTK log message while running %s(): ",
DetailListener::GetCurrentTest());
g_log_default_handler(domain, level, message, data);
}
#endif // __WXGTK__
#endif // wxUSE_GUI
// ----------------------------------------------------------------------------
@ -582,6 +632,11 @@ bool TestApp::OnInit()
new wxTestableFrame();
Connect(wxEVT_IDLE, wxIdleEventHandler(TestApp::OnIdle));
#ifdef __WXGTK__
g_log_set_default_handler(wxTestGLogHandler, NULL);
#endif // __WXGTK__
#endif // wxUSE_GUI
return true;
@ -733,9 +788,10 @@ int TestApp::RunTests()
cout.setf(ios::unitbuf);
// add detail listener if needed
DetailListener detailListener(m_timing);
DetailListener detailListener;
if ( m_detail || m_timing )
runner.eventManager().addListener(&detailListener);
detailListener.EnableVerboseLog(m_timing);
runner.eventManager().addListener(&detailListener);
// finally ensure that we report our own exceptions nicely instead of
// giving "uncaught exception of unknown type" messages