From: Vadim Zeitlin Date: Mon, 30 Mar 2009 22:18:24 +0000 (+0000) Subject: allow running tests whose names don't end with TestCase again X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/d73a520945a10d47184b58e3ef344a235ca84cac allow running tests whose names don't end with TestCase again git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59953 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/tests/test.cpp b/tests/test.cpp index 54f56612f6..1af46fd98e 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -379,6 +379,26 @@ extern void SetProcessEventFunc(ProcessEventFunc func) wxGetApp().SetProcessEventFunc(func); } +// helper of OnRun(): gets the test with the given name, returning NULL (and +// not an empty test suite) if there is no such test +static Test *GetTestByName(const wxString& name) +{ + Test * + test = TestFactoryRegistry::getRegistry(string(name.mb_str())).makeTest(); + if ( test ) + { + TestSuite * const suite = dynamic_cast(test); + if ( !suite || !suite->countTestCases() ) + { + // it's a bogus test, don't use it + delete test; + test = NULL; + } + } + + return test; +} + // Run // int TestApp::OnRun() @@ -395,26 +415,34 @@ int TestApp::OnRun() for (size_t i = 0; i < m_registries.size(); i++) { - wxString reg = m_registries[i]; - // allow the user to specify the name of the testcase "in short form" - // (all wx test cases end with TestCase postfix) - if (!reg.empty() && !reg.EndsWith("TestCase")) - reg += "TestCase"; - - string stdreg(reg.mb_str()); + Test *test; - auto_ptr test(reg.empty() ? - TestFactoryRegistry::getRegistry().makeTest() : - TestFactoryRegistry::getRegistry(stdreg).makeTest()); - - TestSuite *suite = dynamic_cast(test.get()); + wxString reg = m_registries[i]; + if ( reg.empty() ) + { + // no test name, run all the tests + test = TestFactoryRegistry::getRegistry().makeTest(); + } + else // test name specified, run just this test + { + test = GetTestByName(reg); + + if ( !test && !reg.EndsWith("TestCase") ) + { + test = GetTestByName(reg + "TestCase"); + } + + if ( !test ) + { + cerr << "No such test suite: " << string(reg.mb_str()) << endl; + return 2; + } + } - if (suite && suite->countTestCases() == 0) - cerr << "No such test suite: " << stdreg << endl; - else if (m_list) - List(test.get()); + if (m_list) + List(test); else - runner.addTest(test.release()); + runner.addTest(test); } if ( m_list )