From 29e0c68ef562c8aa0f0dba0b99306d8d304dc1bc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 25 Mar 2009 16:28:20 +0000 Subject: [PATCH] produce a better looking report with --time option (closes #10643) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59856 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/test.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/test.cpp b/tests/test.cpp index 02d8191338..fa9ec1e6a4 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "wx/afterstd.h" #include "wx/cmdline.h" @@ -137,21 +138,45 @@ public: virtual void startTest(CppUnit::Test *test) { - std::cout << test->getName () << " "; + wxPrintf(" %-60s ", test->getName()); + m_result = RESULT_OK; m_watch.Start(); } + virtual void addFailure(const CppUnit::TestFailure& failure) { + m_result = failure.isError() ? RESULT_ERROR : RESULT_FAIL; + } + virtual void endTest(CppUnit::Test * WXUNUSED(test)) { m_watch.Pause(); - if ( m_timing ) - std::cout << " (in "<< m_watch.Time() << " ms )"; - std::cout << "\n"; + wxPrintf(GetResultStr(m_result)); + if (m_timing) + wxPrintf(" %6d ms", m_watch.Time()); + wxPrintf("\n"); } protected : + enum ResultType { + RESULT_OK = 0, + RESULT_FAIL, + RESULT_ERROR + }; + + wxString GetResultStr(ResultType type) const { + static const wxChar* ResultTypeNames[] = { + wxT("OK"), + wxT(" F"), + wxT("ER") + }; + wxCHECK_MSG(static_cast(type) < WXSIZEOF(ResultTypeNames), + ResultTypeNames[RESULT_ERROR], "invalid entry type"); + return ResultTypeNames[type]; + } + bool m_timing; wxStopWatch m_watch; + ResultType m_result; }; #if wxUSE_GUI @@ -404,7 +429,8 @@ int TestApp::OnRun() // giving "uncaught exception of unknown type" messages runner.eventManager().pushProtector(new wxUnitTestProtector); - return runner.run("", false, true, !verbose) ? EXIT_SUCCESS : EXIT_FAILURE; + bool printProgress = !(verbose || m_detail || m_timing); + return runner.run("", false, true, printProgress) ? EXIT_SUCCESS : EXIT_FAILURE; } int TestApp::OnExit() -- 2.47.2