Always use stderr for wxMessageOutputBest in the tests
Avoid showing message boxes even if we don't have the associated console as this prevents the test from completing on its own if an unknown exception happens.
This commit is contained in:
parent
d55d5b1dd7
commit
277937b0c4
@ -46,6 +46,7 @@ std::string wxTheCurrentTestClass, wxTheCurrentTestMethod;
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#include "wx/apptrait.h"
|
||||
#include "wx/cmdline.h"
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@ -171,8 +172,10 @@ CATCH_TRANSLATE_EXCEPTION(TestAssertFailure& e)
|
||||
|
||||
#if wxUSE_GUI
|
||||
typedef wxApp TestAppBase;
|
||||
typedef wxGUIAppTraits TestAppTraitsBase;
|
||||
#else
|
||||
typedef wxAppConsole TestAppBase;
|
||||
typedef wxConsoleAppTraits TestAppTraitsBase;
|
||||
#endif
|
||||
|
||||
// The application class
|
||||
@ -186,6 +189,36 @@ public:
|
||||
virtual bool OnInit();
|
||||
virtual int OnExit();
|
||||
|
||||
#ifdef __WIN32__
|
||||
virtual wxAppTraits *CreateTraits()
|
||||
{
|
||||
// Define a new class just to customize CanUseStderr() behaviour.
|
||||
class TestAppTraits : public TestAppTraitsBase
|
||||
{
|
||||
public:
|
||||
// We want to always use stderr, tests are also run unattended and
|
||||
// in this case we really don't want to show any message boxes, as
|
||||
// wxMessageOutputBest, used e.g. from the default implementation
|
||||
// of wxApp::OnUnhandledException(), would do by default.
|
||||
virtual bool CanUseStderr() { return true; }
|
||||
|
||||
// Overriding CanUseStderr() is not enough, we also need to
|
||||
// override this one to avoid returning false from it.
|
||||
virtual bool WriteToStderr(const wxString& text)
|
||||
{
|
||||
wxFputs(text, stderr);
|
||||
fflush(stderr);
|
||||
|
||||
// Intentionally ignore any errors, we really don't want to
|
||||
// show any message boxes in any case.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
return new TestAppTraits;
|
||||
}
|
||||
#endif // __WIN32__
|
||||
|
||||
// used by events propagation test
|
||||
virtual int FilterEvent(wxEvent& event);
|
||||
virtual bool ProcessEvent(wxEvent& event);
|
||||
|
Loading…
Reference in New Issue
Block a user