mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 08:24:10 -08:00
Add JUnit test filtering
This commit is contained in:
parent
0b4f8b9898
commit
c25dd1a99d
|
@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -42,6 +43,9 @@ import java.util.stream.Stream;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
import org.junit.runner.Runner;
|
import org.junit.runner.Runner;
|
||||||
|
import org.junit.runner.manipulation.Filter;
|
||||||
|
import org.junit.runner.manipulation.Filterable;
|
||||||
|
import org.junit.runner.manipulation.NoTestsRemainException;
|
||||||
import org.junit.runner.notification.Failure;
|
import org.junit.runner.notification.Failure;
|
||||||
import org.junit.runner.notification.RunNotifier;
|
import org.junit.runner.notification.RunNotifier;
|
||||||
import org.junit.runners.model.InitializationError;
|
import org.junit.runners.model.InitializationError;
|
||||||
|
@ -64,7 +68,7 @@ import org.teavm.vm.DirectoryBuildTarget;
|
||||||
import org.teavm.vm.TeaVM;
|
import org.teavm.vm.TeaVM;
|
||||||
import org.teavm.vm.TeaVMBuilder;
|
import org.teavm.vm.TeaVMBuilder;
|
||||||
|
|
||||||
public class TeaVMTestRunner extends Runner {
|
public class TeaVMTestRunner extends Runner implements Filterable {
|
||||||
private static final String PATH_PARAM = "teavm.junit.target";
|
private static final String PATH_PARAM = "teavm.junit.target";
|
||||||
private static final String RUNNER = "teavm.junit.js.runner";
|
private static final String RUNNER = "teavm.junit.js.runner";
|
||||||
private static final String THREAD_COUNT = "teavm.junit.js.threads";
|
private static final String THREAD_COUNT = "teavm.junit.js.threads";
|
||||||
|
@ -83,6 +87,7 @@ public class TeaVMTestRunner extends Runner {
|
||||||
private static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
|
private static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
|
||||||
private static volatile ScheduledFuture<?> cleanupFuture;
|
private static volatile ScheduledFuture<?> cleanupFuture;
|
||||||
private CountDownLatch latch;
|
private CountDownLatch latch;
|
||||||
|
private List<Method> filteredChildren;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
@ -129,7 +134,7 @@ public class TeaVMTestRunner extends Runner {
|
||||||
public Description getDescription() {
|
public Description getDescription() {
|
||||||
if (suiteDescription == null) {
|
if (suiteDescription == null) {
|
||||||
suiteDescription = Description.createSuiteDescription(testClass);
|
suiteDescription = Description.createSuiteDescription(testClass);
|
||||||
for (Method child : getChildren()) {
|
for (Method child : getFilteredChildren()) {
|
||||||
suiteDescription.getChildren().add(describeChild(child));
|
suiteDescription.getChildren().add(describeChild(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +143,7 @@ public class TeaVMTestRunner extends Runner {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(RunNotifier notifier) {
|
public void run(RunNotifier notifier) {
|
||||||
List<Method> children = getChildren();
|
List<Method> children = getFilteredChildren();
|
||||||
latch = new CountDownLatch(children.size());
|
latch = new CountDownLatch(children.size());
|
||||||
|
|
||||||
notifier.fireTestStarted(getDescription());
|
notifier.fireTestStarted(getDescription());
|
||||||
|
@ -169,6 +174,13 @@ public class TeaVMTestRunner extends Runner {
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Method> getFilteredChildren() {
|
||||||
|
if (filteredChildren == null) {
|
||||||
|
filteredChildren = getChildren();
|
||||||
|
}
|
||||||
|
return filteredChildren;
|
||||||
|
}
|
||||||
|
|
||||||
private Description describeChild(Method child) {
|
private Description describeChild(Method child) {
|
||||||
return descriptions.computeIfAbsent(child, method -> Description.createTestDescription(testClass,
|
return descriptions.computeIfAbsent(child, method -> Description.createTestDescription(testClass,
|
||||||
method.getName()));
|
method.getName()));
|
||||||
|
@ -461,6 +473,18 @@ public class TeaVMTestRunner extends Runner {
|
||||||
new ClasspathClassHolderSource(classLoader)));
|
new ClasspathClassHolderSource(classLoader)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(Filter filter) throws NoTestsRemainException {
|
||||||
|
for (Iterator<Method> iterator = getFilteredChildren().iterator(); iterator.hasNext();) {
|
||||||
|
Method method = iterator.next();
|
||||||
|
if (filter.shouldRun(describeChild(method))) {
|
||||||
|
filter.apply(method);
|
||||||
|
} else {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class CompileResult {
|
static class CompileResult {
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
String errorMessage;
|
String errorMessage;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user