>From 87d28039c941714091b46fb200b21b761077193b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 23 Nov 2014 22:29:06 +0100 Subject: [PATCH 1/3] Send GUI test suite output to stderr instead of showing it interactively. Redirect all log output to stderr. This also obviates the need to keep the log window open after the tests termination and so the test process now exits after finishing running all the tests. --- main_wx_test.cpp | 53 ++++++++++++++++++----------------------------------- 1 files changed, 18 insertions(+), 35 deletions(-) diff --git a/main_wx_test.cpp b/main_wx_test.cpp index 7658033..522af4d 100644 --- a/main_wx_test.cpp +++ b/main_wx_test.cpp @@ -41,6 +41,7 @@ #include #include #include // wxEntry() +#include #include #include #include @@ -498,10 +499,6 @@ class SkeletonTest : public Skeleton private: void RunTheTests(); - // This event handler only exists to prevent the base class from handling - // this event, see the comment near its use. - void ConsumeMenuOpen(wxMenuEvent&) {} - std::string runtime_error_; bool is_running_tests_; }; @@ -511,6 +508,15 @@ class SkeletonTest : public Skeleton bool SkeletonTest::OnInit() { + // The test output should be reproducible, so disable the time + // stamps in the logs to avoid spurious differences due to them. + wxLog::DisableTimestamp(); + + // Log everything to stderr, both to avoid interacting with the user (who + // might not even be present) and to allow redirecting the test output to a + // file which may subsequently be compared with the previous test runs. + delete wxLog::SetActiveTarget(new wxLogStderr); + if(!Skeleton::OnInit()) { return false; @@ -585,19 +591,17 @@ bool SkeletonTest::OnExceptionInMainLoop() void SkeletonTest::RunTheTests() { - // Create log window for output that should be checked by the user. - class LogWindow : public wxLogWindow - { - public: - LogWindow() : wxLogWindow(NULL, "Log Messages", true, false) {} - virtual bool OnFrameClose(wxFrame* frame) + wxWindow* const mainWin = GetTopWindow(); + if (!mainWin) { - wxTheApp->ExitMainLoop(); - return wxLogWindow::OnFrameClose(frame); + wxLogError("Failed to find the application main window."); + ExitMainLoop(); + return; } - }; - wxWindow* const mainWin = GetTopWindow(); + // Whatever happens, ensure that the main window is closed and thus the + // main loop terminated and the application exits at the end of the tests. + wxON_BLOCK_EXIT_OBJ1(*mainWin, wxWindow::Close, true /* force close */); // Close any initially opened dialogs (e.g. "About" dialog shown unless a // special command line option is specified). @@ -621,7 +625,6 @@ void SkeletonTest::RunTheTests() } } - LogWindow* const log = new LogWindow(); mainWin->SetFocus(); wxStopWatch sw; @@ -669,26 +672,6 @@ void SkeletonTest::RunTheTests() : wxString::Format("%d tests were", results.skipped) ); } - - // We want to show log output after the tests finished running and hide the - // app window, which is no longer in use. This doesn't work out of the box, - // because the main window is set application's top window and closing it - // terminates the app. LogWindow's window, on the other hand, doesn't keep - // the app running because it returns false from ShouldPreventAppExit(). - // This code (together with LogWindow::OnFrameClose above) does the right - // thing: close the main window and keep running until the user closes the - // log window. - log->GetFrame()->Maximize(); - log->GetFrame()->SetFocus(); - SetExitOnFrameDelete(false); - - // Before closing the main window, ensure that the base class event handler - // relying on it being alive is not called any more, otherwise dereferencing - // the pointer to the main frame inside it would simply crash on any attempt - // to open the log frame menu. - Bind(wxEVT_MENU_OPEN, &SkeletonTest::ConsumeMenuOpen, this); - - mainWin->Close(); } int main(int argc, char* argv[]) -- 1.7.9