>From c0af39608499e96ccdb0168306b76d661c400eb2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Mar 2015 17:00:05 +0100 Subject: [PATCH 1/2] Use wxPrintf() instead of wxLogMessage() for the test suite output. This removes the need to install a custom log target for the test suite and will allow testing the default log target behaviour in the upcoming new test. --- main_wx_test.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/main_wx_test.cpp b/main_wx_test.cpp index 9497c36..f614941 100644 --- a/main_wx_test.cpp +++ b/main_wx_test.cpp @@ -40,6 +40,7 @@ #include "wx_test_case.hpp" #include "wx_test_new.hpp" +#include #include #include #include @@ -469,19 +470,16 @@ TestsResults application_test::run() try { - wxLogMessage("%s: started", name); + wxPrintf("%s: started\n", name); wxStopWatch sw; i->run_test(); - // Check that no messages were unexpectedly logged during this - // test execution. - wxLog::FlushActive(); - wxLogMessage("time=%ldms (for %s)", sw.Time(), name); - wxLogMessage("%s: ok", name); + wxPrintf("time=%ldms (for %s)\n", sw.Time(), name); + wxPrintf("%s: ok\n", name); results.passed++; } catch(test_skipped_exception const& e) { - wxLogMessage("%s: skipped (%s)", name, e.what()); + wxPrintf("%s: skipped (%s)\n", name, e.what()); results.skipped++; } catch(std::exception const& e) @@ -503,7 +501,7 @@ TestsResults application_test::run() wxString one_line_error(error); one_line_error.Replace("\n", " "); - wxLogMessage("%s: ERROR (%s)", name, one_line_error); + wxPrintf("%s: ERROR (%s)\n", name, one_line_error); } } } @@ -700,20 +698,11 @@ DocManagerEx* SkeletonTest::CreateDocManager() 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(); - if(!Skeleton::OnInit()) { return false; } - // Log everything to stdout, 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(stdout)); - // Run the tests at idle time, when the main loop is running, in order to // do it in as realistic conditions as possible. CallAfter(&SkeletonTest::RunTheTests); @@ -826,7 +815,7 @@ void SkeletonTest::RunTheTests() mainWin->SetFocus(); - wxLogMessage("NOTE: starting the test suite"); + wxPuts("NOTE: starting the test suite"); wxStopWatch sw; // Notice that it is safe to use simple variable assignment here instead of @@ -836,18 +825,18 @@ void SkeletonTest::RunTheTests() TestsResults const results = application_test::instance().run(); is_running_tests_ = false; - wxLogMessage("time=%ldms (for all tests)", sw.Time()); + wxPrintf("time=%ldms (for all tests)\n", sw.Time()); if(results.failed == 0) { if(results.passed == 0) { - wxLogMessage("WARNING: no tests have been executed."); + wxPuts("WARNING: no tests have been executed."); } else { - wxLogMessage - ("SUCCESS: %d test%s successfully completed." + wxPrintf + ("SUCCESS: %d test%s successfully completed.\n" ,results.passed ,results.passed == 1 ? "" : "s" ); @@ -855,8 +844,8 @@ void SkeletonTest::RunTheTests() } else { - wxLogMessage - ("FAILURE: %d out of %d test%s failed." + wxPrintf + ("FAILURE: %d out of %d test%s failed.\n" ,results.failed ,results.total ,results.total == 1 ? "" : "s" @@ -865,8 +854,8 @@ void SkeletonTest::RunTheTests() if(results.skipped) { - wxLogMessage - ("NOTE: %s skipped" + wxPrintf + ("NOTE: %s skipped\n" ,results.skipped == 1 ? wxString("1 test was") : wxString::Format("%d tests were", results.skipped) -- 2.1.0