From 6512ed104fbd445480c7371708b6aaade2a9fc0b Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 29 May 2013 20:38:01 +0400 Subject: [PATCH] filtering test suite --- .../testFramework/UsefulTestCase.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 2ffc651befb7..4ff34793f451 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -41,12 +41,12 @@ import com.intellij.rt.execution.junit.FileComparisonFailure; import com.intellij.testFramework.exceptionCases.AbstractExceptionCase; import com.intellij.util.Consumer; import com.intellij.util.Function; +import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import gnu.trove.THashSet; -import junit.framework.Assert; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import junit.framework.*; +import org.intellij.lang.annotations.RegExp; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -62,6 +62,7 @@ import java.lang.reflect.Modifier; import java.security.SecureRandom; import java.util.*; import java.util.List; +import java.util.regex.Pattern; /** * @author peter @@ -838,4 +839,25 @@ public abstract class UsefulTestCase extends TestCase { }); file.refresh(false, true); } + + public static @NotNull Test filteredSuite(@RegExp String regexp, @NotNull Test test) { + final Pattern pattern = Pattern.compile(regexp); + final TestSuite testSuite = new TestSuite(); + new Processor() { + + @Override + public boolean process(Test test) { + if (test instanceof TestSuite) { + for (int i = 0, len = ((TestSuite)test).testCount(); i < len; i++) { + process(((TestSuite)test).testAt(i)); + } + } + else if (pattern.matcher(test.toString()).find()) { + testSuite.addTest(test); + } + return false; + } + }.process(test); + return testSuite; + } }