diff --git a/modules/juce_core/unit_tests/juce_UnitTest.cpp b/modules/juce_core/unit_tests/juce_UnitTest.cpp index 23e7c06e5b..0e5658011a 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.cpp +++ b/modules/juce_core/unit_tests/juce_UnitTest.cpp @@ -66,6 +66,20 @@ Array UnitTest::getTestsInCategory (const String& category) return unitTests; } +Array UnitTest::getTestsWithName (const String& name) +{ + if (name.isEmpty()) + return getAllTests(); + + Array unitTests; + + for (auto* test : getAllTests()) + if (test->getName() == name) + unitTests.add (test); + + return unitTests; +} + StringArray UnitTest::getAllCategories() { StringArray categories; @@ -196,6 +210,11 @@ void UnitTestRunner::runTestsInCategory (const String& category, int64 randomSee runTests (UnitTest::getTestsInCategory (category), randomSeed); } +void UnitTestRunner::runTestsWithName (const String& name, int64 randomSeed) +{ + runTests (UnitTest::getTestsWithName (name), randomSeed); +} + void UnitTestRunner::logMessage (const String& message) { Logger::writeToLog (message); diff --git a/modules/juce_core/unit_tests/juce_UnitTest.h b/modules/juce_core/unit_tests/juce_UnitTest.h index aef0b6e739..4a4186becc 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.h +++ b/modules/juce_core/unit_tests/juce_UnitTest.h @@ -106,6 +106,9 @@ public: /** Returns the set of UnitTests in a specified category. */ static Array getTestsInCategory (const String& category); + /** Returns the set of UnitTests with a specified name. */ + static Array getTestsWithName (const String& name); + /** Returns a StringArray containing all of the categories of UnitTests that have been registered. */ static StringArray getAllCategories(); @@ -369,6 +372,14 @@ public: */ void runTestsInCategory (const String& category, int64 randomSeed = 0); + /** Runs all the UnitTest objects with a specified name. + This calls runTests() for all the objects listed in UnitTest::getTestsWithName(). + + If you want to run the tests with a predetermined seed, you can pass that into + the randomSeed argument, or pass 0 to have a randomly-generated seed chosen. + */ + void runTestsWithName (const String& name, int64 randomSeed = 0); + /** Sets a flag to indicate whether an assertion should be triggered if a test fails. This is true by default. */