>From fc1a71c8c21808a15caf2ef81a7a34ef0fe220d2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Mar 2015 17:00:05 +0100 Subject: [PATCH 1/4] 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 | 38 +++++++++++++++----------------------- wx_test_about_version.cpp | 4 ++-- wx_test_benchmark_census.cpp | 6 +++--- wx_test_default_input.cpp | 12 ++++++------ wx_test_expiry_dates.cpp | 6 +++--- 5 files changed, 29 insertions(+), 37 deletions(-) diff --git a/main_wx_test.cpp b/main_wx_test.cpp index 35d71c0..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,16 +470,16 @@ TestsResults application_test::run() try { - wxLogMessage("%s: started", name); + wxPrintf("%s: started\n", name); wxStopWatch sw; i->run_test(); - 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) @@ -500,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); } } } @@ -697,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); @@ -823,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 @@ -833,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" ); @@ -852,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" @@ -862,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) diff --git a/wx_test_about_version.cpp b/wx_test_about_version.cpp index 7b11787..ed37163 100644 --- a/wx_test_about_version.cpp +++ b/wx_test_about_version.cpp @@ -31,9 +31,9 @@ #include "wx_test_case.hpp" #include "version.hpp" +#include #include #include -#include #include #include @@ -179,7 +179,7 @@ wxHtmlWindow* find_html_window(wxWindow* parent, std::string const& dialog_name) // Extract the last word of the dialog title. wxString const last_word = d->GetTitle().AfterLast(' '); - wxLogMessage("About dialog version string is \"%s\".", last_word); + wxPrintf("About dialog version string is \"%s\".\n", last_word); LMI_ASSERT_EQUAL(last_word, LMI_VERSION); // Find the wxHtmlWindow showing the license notices. diff --git a/wx_test_benchmark_census.cpp b/wx_test_benchmark_census.cpp index 508e1c5..b74b447 100644 --- a/wx_test_benchmark_census.cpp +++ b/wx_test_benchmark_census.cpp @@ -31,9 +31,9 @@ #include "wx_test_statusbar.hpp" #include "uncopyable_lmi.hpp" +#include #include #include -#include #include #include #include @@ -82,8 +82,8 @@ class census_benchmark long time_real; LMI_ASSERT(ms_text.ToLong(&time_real)); - wxLogMessage - ("%s for %s: %ldms elapsed" + wxPrintf + ("%s for %s: %ldms elapsed\n" ,operation ,name_ ,time_real diff --git a/wx_test_default_input.cpp b/wx_test_default_input.cpp index 2c32b42..dd9285e 100644 --- a/wx_test_default_input.cpp +++ b/wx_test_default_input.cpp @@ -33,7 +33,7 @@ #include "wx_test_case.hpp" #include "wx_test_date.hpp" -#include +#include #include @@ -73,14 +73,14 @@ calendar_date const first_of_next_month = get_first_next_month(today()); - wxLogMessage - ("EffectiveDate: %s; expected: %s" + wxPrintf + ("EffectiveDate: %s; expected: %s\n" ,dump_date(effective_date) ,dump_date(first_of_next_month) ); if(effective_date != first_of_next_month) { - wxLogWarning("Effective date is different from the expected date."); + wxPuts("WARNING: Effective date is different from the expected date."); } std::string const general_account_rate = cell["GeneralAccountRate"].str(); @@ -88,8 +88,8 @@ std::string const product_name = cell["ProductName"].str(); - wxLogMessage - ("ProductName=\"%s\"; GeneralAccountRate=\"%s\"" + wxPrintf + ("ProductName=\"%s\"; GeneralAccountRate=\"%s\"\n" ,product_name ,general_account_rate ); diff --git a/wx_test_expiry_dates.cpp b/wx_test_expiry_dates.cpp index 6bf3075..ce3796e 100644 --- a/wx_test_expiry_dates.cpp +++ b/wx_test_expiry_dates.cpp @@ -33,7 +33,7 @@ #include "wx_test_date.hpp" #include "version.hpp" -#include +#include #include #include @@ -81,8 +81,8 @@ is >> begin >> end; LMI_ASSERT_WITH_MSG(is, "Failed to read dates from \"expiry\" file"); - wxLogMessage - ("Expiry dates: begin=%s, end=%s" + wxPrintf + ("Expiry dates: begin=%s, end=%s\n" ,dump_date(begin) ,dump_date(end) ); -- 2.1.0