From 159aabd8d95248bba9e508cbcdb847a3e16cec8d Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 17 Jul 2013 09:43:48 -0700 Subject: [PATCH] Run a named unit test --- .../beast_core/diagnostic/beast_UnitTest.cpp | 27 +++++++++++++++++++ .../beast_core/diagnostic/beast_UnitTest.h | 11 +++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.cpp b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.cpp index 41903dc311..6cc4ebfae5 100644 --- a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.cpp +++ b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.cpp @@ -105,6 +105,33 @@ void UnitTests::resultsUpdated() { } +void UnitTests::runTest (String const& name) +{ + results.clear(); + resultsUpdated(); + + Array& tests = UnitTest::getAllTests (); + + for (int i = 0; i < tests.size(); ++i) + { + UnitTest& test = *tests [i]; + + if (test.getName () == name) + { + try + { + test.performTest (this); + } + catch (...) + { + addFail ("An unhandled exception was thrown!"); + } + + break; + } + } +} + void UnitTests::runTests (const Array& tests) { results.clear(); diff --git a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h index 237f1ba89e..6945bf7660 100644 --- a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h +++ b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h @@ -56,9 +56,10 @@ class UnitTests; } }; - // Explicit template instantiation is required to make the unit - // test get automatically added to the set of unit tests. - template class UnitTestType ; + // This makes the unit test available in the global list + // It doesn't have to be static. + // + static MyTest myTest; @endcode @@ -187,6 +188,10 @@ public: /** Destructor. */ virtual ~UnitTests(); + /** Run a particular test. + */ + void runTest (String const& name); + /** Runs a set of tests. The tests are performed in order, and the results are logged. To run all the