mirror of
https://github.com/sbt/sbt.git
synced 2026-09-01 02:27:13 +02:00
Change to use test-interface-1.0-SNAP7, and use ScalaTest 2.0.M6-SNAP26 which implemented test-interface-1.0-SNAP7.
This commit is contained in:
@@ -63,68 +63,41 @@ public class ForkMain {
|
||||
public String getMessage() { return originalMessage; }
|
||||
public Exception getCause() { return cause; }
|
||||
}
|
||||
static class ForkSelector extends Selector implements Serializable {}
|
||||
static class ForkSuiteSelector extends ForkSelector {}
|
||||
static class ForkTestSelector extends ForkSelector {
|
||||
private String testName;
|
||||
ForkTestSelector(TestSelector testSelector) {
|
||||
this.testName = testSelector.getTestName();
|
||||
}
|
||||
public String getTestName() {
|
||||
return testName;
|
||||
}
|
||||
}
|
||||
static class ForkNestedSuiteSelector extends ForkSelector {
|
||||
private String suiteId;
|
||||
ForkNestedSuiteSelector(NestedSuiteSelector nestedSuiteSelector) {
|
||||
this.suiteId = nestedSuiteSelector.getSuiteId();
|
||||
}
|
||||
public String getSuiteId() {
|
||||
return suiteId;
|
||||
}
|
||||
}
|
||||
static class ForkNestedTestSelector extends ForkSelector {
|
||||
private String suiteId;
|
||||
private String testName;
|
||||
ForkNestedTestSelector(NestedTestSelector nestedTestSelector) {
|
||||
this.suiteId = nestedTestSelector.getSuiteId();
|
||||
this.testName = nestedTestSelector.getTestName();
|
||||
}
|
||||
public String getSuiteId() {
|
||||
return suiteId;
|
||||
}
|
||||
public String getTestName() {
|
||||
return testName;
|
||||
}
|
||||
}
|
||||
|
||||
static class ForkEvent implements Event, Serializable {
|
||||
private String fullyQualifiedName;
|
||||
private boolean isModule;
|
||||
private ForkSelector selector;
|
||||
private Fingerprint fingerprint;
|
||||
private Selector selector;
|
||||
private Status status;
|
||||
private Throwable throwable;
|
||||
private OptionalThrowable throwable;
|
||||
private long duration;
|
||||
ForkEvent(Event e) {
|
||||
fullyQualifiedName = e.fullyQualifiedName();
|
||||
isModule = e.isModule();
|
||||
Fingerprint rawFingerprint = e.fingerprint();
|
||||
if (rawFingerprint instanceof SubclassFingerprint)
|
||||
this.fingerprint = new SubclassFingerscan((SubclassFingerprint) rawFingerprint);
|
||||
else
|
||||
this.fingerprint = new AnnotatedFingerscan((AnnotatedFingerprint) rawFingerprint);
|
||||
selector = forkSelector(e.selector());
|
||||
status = e.status();
|
||||
if (e.throwable() != null) throwable = new ForkError(e.throwable());
|
||||
OptionalThrowable originalThrowable = e.throwable();
|
||||
if (originalThrowable.isDefined())
|
||||
this.throwable = new OptionalThrowable(new ForkError(originalThrowable.get()));
|
||||
else
|
||||
this.throwable = originalThrowable;
|
||||
this.duration = e.duration();
|
||||
}
|
||||
public String fullyQualifiedName() { return fullyQualifiedName; }
|
||||
public boolean isModule() { return isModule; }
|
||||
public Fingerprint fingerprint() { return fingerprint; }
|
||||
public Selector selector() { return selector; }
|
||||
public Status status() { return status; }
|
||||
public Throwable throwable() { return throwable; }
|
||||
protected ForkSelector forkSelector(Selector selector) {
|
||||
if (selector instanceof SuiteSelector)
|
||||
return new ForkSuiteSelector();
|
||||
else if (selector instanceof TestSelector)
|
||||
return new ForkTestSelector((TestSelector) selector);
|
||||
else if (selector instanceof NestedSuiteSelector)
|
||||
return new ForkNestedSuiteSelector((NestedSuiteSelector) selector);
|
||||
public OptionalThrowable throwable() { return throwable; }
|
||||
public long duration() { return duration; }
|
||||
protected Selector forkSelector(Selector selector) {
|
||||
if (selector instanceof Serializable)
|
||||
return selector;
|
||||
else
|
||||
return new ForkNestedTestSelector((NestedTestSelector) selector);
|
||||
throw new UnsupportedOperationException("Selector implementation must be Serializable.");
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
@@ -172,8 +145,8 @@ public class ForkMain {
|
||||
void logDebug(ObjectOutputStream os, String message) {
|
||||
write(os, new Object[]{ForkTags.Debug, message});
|
||||
}
|
||||
void writeEvents(ObjectOutputStream os, ForkTestDefinition test, ForkEvent[] events) {
|
||||
write(os, new Object[]{test.name, events});
|
||||
void writeEvents(ObjectOutputStream os, TaskDef taskDef, ForkEvent[] events) {
|
||||
write(os, new Object[]{taskDef.fullyQualifiedName(), events});
|
||||
}
|
||||
void runTests(ObjectInputStream is, final ObjectOutputStream os) throws Exception {
|
||||
final boolean ansiCodesSupported = is.readBoolean();
|
||||
@@ -212,15 +185,18 @@ public class ForkMain {
|
||||
if (framework == null)
|
||||
continue;
|
||||
|
||||
ArrayList<ForkTestDefinition> filteredTests = new ArrayList<ForkTestDefinition>();
|
||||
ArrayList<TaskDef> filteredTests = new ArrayList<TaskDef>();
|
||||
for (Fingerprint testFingerprint : framework.fingerprints()) {
|
||||
for (ForkTestDefinition test : tests) {
|
||||
if (matches(testFingerprint, test.fingerprint)) filteredTests.add(test);
|
||||
// TODO: To pass in correct explicitlySpecified and selectors
|
||||
if (matches(testFingerprint, test.fingerprint))
|
||||
filteredTests.add(new TaskDef(test.name, test.fingerprint, false, new Selector[] { new SuiteSelector() }));
|
||||
}
|
||||
}
|
||||
final Runner runner = framework.runner(frameworkArgs, remoteFrameworkArgs, getClass().getClassLoader());
|
||||
for (ForkTestDefinition test : filteredTests)
|
||||
runTestSafe(test, runner, loggers, os);
|
||||
Task[] tasks = runner.tasks(filteredTests.toArray(new TaskDef[filteredTests.size()]));
|
||||
for (Task task : tasks)
|
||||
runTestSafe(task, runner, loggers, os);
|
||||
runner.done();
|
||||
}
|
||||
write(os, ForkTags.Done);
|
||||
@@ -240,21 +216,19 @@ public class ForkMain {
|
||||
return task;
|
||||
}
|
||||
}
|
||||
void runTestSafe(ForkTestDefinition test, Runner runner, Logger[] loggers, ObjectOutputStream os) {
|
||||
void runTestSafe(Task task, Runner runner, Logger[] loggers, ObjectOutputStream os) {
|
||||
TaskDef taskDef = task.taskDef();
|
||||
try {
|
||||
// TODO: To pass in correct explicitlySpecified and selectors
|
||||
Task task = runner.task(test.name, test.fingerprint, false, new Selector[] { new SuiteSelector() });
|
||||
|
||||
List<NestedTask> nestedTasks = new ArrayList<NestedTask>();
|
||||
for (Task nt : runTest(test, task, loggers, os))
|
||||
nestedTasks.add(new NestedTask(test.name, nt));
|
||||
for (Task nt : runTest(taskDef, task, loggers, os))
|
||||
nestedTasks.add(new NestedTask(taskDef.fullyQualifiedName(), nt));
|
||||
while (true) {
|
||||
List<NestedTask> newNestedTasks = new ArrayList<NestedTask>();
|
||||
int nestedTasksLength = nestedTasks.size();
|
||||
for (int i = 0; i < nestedTasksLength; i++) {
|
||||
NestedTask nestedTask = nestedTasks.get(i);
|
||||
String nestedParentName = nestedTask.getParentName() + "-" + i;
|
||||
for (Task nt : runTest(new ForkTestDefinition(nestedParentName, test.fingerprint), nestedTask.getTask(), loggers, os)) {
|
||||
for (Task nt : runTest(nestedTask.getTask().taskDef(), nestedTask.getTask(), loggers, os)) {
|
||||
newNestedTasks.add(new NestedTask(nestedParentName, nt));
|
||||
}
|
||||
}
|
||||
@@ -265,10 +239,10 @@ public class ForkMain {
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
writeEvents(os, test, new ForkEvent[] { testError(os, test, "Uncaught exception when running " + test.name + ": " + t.toString(), t) });
|
||||
writeEvents(os, taskDef, new ForkEvent[] { testError(os, taskDef, "Uncaught exception when running " + taskDef.fullyQualifiedName() + ": " + t.toString(), t) });
|
||||
}
|
||||
}
|
||||
Task[] runTest(ForkTestDefinition test, Task task, Logger[] loggers, ObjectOutputStream os) {
|
||||
Task[] runTest(TaskDef taskDef, Task task, Logger[] loggers, ObjectOutputStream os) {
|
||||
ForkEvent[] events;
|
||||
Task[] nestedTasks;
|
||||
try {
|
||||
@@ -279,9 +253,9 @@ public class ForkMain {
|
||||
}
|
||||
catch (Throwable t) {
|
||||
nestedTasks = new Task[0];
|
||||
events = new ForkEvent[] { testError(os, test, "Uncaught exception when running " + test.name + ": " + t.toString(), t) };
|
||||
events = new ForkEvent[] { testError(os, taskDef, "Uncaught exception when running " + taskDef.fullyQualifiedName() + ": " + t.toString(), t) };
|
||||
}
|
||||
writeEvents(os, test, events);
|
||||
writeEvents(os, taskDef, events);
|
||||
return nestedTasks;
|
||||
}
|
||||
void run(ObjectInputStream is, ObjectOutputStream os) throws Exception {
|
||||
@@ -301,23 +275,33 @@ public class ForkMain {
|
||||
void internalError(Throwable t) {
|
||||
System.err.println("Internal error when running tests: " + t.toString());
|
||||
}
|
||||
ForkEvent testEvent(final String fullyQualifiedName, final Fingerprint fingerprint, final Selector selector, final Status r, final Throwable err) {
|
||||
ForkEvent testEvent(final String fullyQualifiedName, final Fingerprint fingerprint, final Selector selector, final Status r, final Throwable err, final long duration) {
|
||||
final OptionalThrowable throwable;
|
||||
if (err == null)
|
||||
throwable = new OptionalThrowable();
|
||||
else
|
||||
throwable = new OptionalThrowable(err);
|
||||
return new ForkEvent(new Event() {
|
||||
public String fullyQualifiedName() { return fullyQualifiedName; }
|
||||
public boolean isModule() { return fingerprint instanceof SubclassFingerprint ? ((SubclassFingerprint) fingerprint).isModule() : ((AnnotatedFingerprint) fingerprint).isModule(); }
|
||||
public Fingerprint fingerprint() { return fingerprint; }
|
||||
public Selector selector() { return selector; }
|
||||
public Status status() { return r; }
|
||||
public Throwable throwable() { return err; }
|
||||
public OptionalThrowable throwable() {
|
||||
return throwable;
|
||||
}
|
||||
public long duration() {
|
||||
return duration;
|
||||
}
|
||||
});
|
||||
}
|
||||
ForkEvent testError(ObjectOutputStream os, ForkTestDefinition test, String message) {
|
||||
ForkEvent testError(ObjectOutputStream os, TaskDef taskDef, String message) {
|
||||
logError(os, message);
|
||||
return testEvent(test.name, test.fingerprint, new SuiteSelector(), Status.Error, null);
|
||||
return testEvent(taskDef.fullyQualifiedName(), taskDef.fingerprint(), new SuiteSelector(), Status.Error, null, 0);
|
||||
}
|
||||
ForkEvent testError(ObjectOutputStream os, ForkTestDefinition test, String message, Throwable t) {
|
||||
ForkEvent testError(ObjectOutputStream os, TaskDef taskDef, String message, Throwable t) {
|
||||
logError(os, message);
|
||||
write(os, t);
|
||||
return testEvent(test.name, test.fingerprint, new SuiteSelector(), Status.Error, t);
|
||||
return testEvent(taskDef.fullyQualifiedName(), taskDef.fingerprint(), new SuiteSelector(), Status.Error, t, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,16 +88,16 @@ class EventHandlerWrapper implements org.scalatools.testing.EventHandler {
|
||||
|
||||
private EventHandler newEventHandler;
|
||||
private String fullyQualifiedName;
|
||||
private boolean isModule;
|
||||
private Fingerprint fingerprint;
|
||||
|
||||
public EventHandlerWrapper(EventHandler newEventHandler, String fullyQualifiedName, boolean isModule) {
|
||||
public EventHandlerWrapper(EventHandler newEventHandler, String fullyQualifiedName, Fingerprint fingerprint) {
|
||||
this.newEventHandler = newEventHandler;
|
||||
this.fullyQualifiedName = fullyQualifiedName;
|
||||
this.isModule = isModule;
|
||||
this.fingerprint = fingerprint;
|
||||
}
|
||||
|
||||
public void handle(org.scalatools.testing.Event oldEvent) {
|
||||
newEventHandler.handle(new EventWrapper(oldEvent, fullyQualifiedName, isModule));
|
||||
newEventHandler.handle(new EventWrapper(oldEvent, fullyQualifiedName, fingerprint));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,20 +105,26 @@ class EventWrapper implements Event {
|
||||
|
||||
private org.scalatools.testing.Event oldEvent;
|
||||
private String className;
|
||||
private boolean classIsModule;
|
||||
private Fingerprint fingerprint;
|
||||
private OptionalThrowable throwable;
|
||||
|
||||
public EventWrapper(org.scalatools.testing.Event oldEvent, String className, boolean classIsModule) {
|
||||
public EventWrapper(org.scalatools.testing.Event oldEvent, String className, Fingerprint fingerprint) {
|
||||
this.oldEvent = oldEvent;
|
||||
this.className = className;
|
||||
this.classIsModule = classIsModule;
|
||||
this.fingerprint = fingerprint;
|
||||
Throwable oldThrowable = oldEvent.error();
|
||||
if (oldThrowable == null)
|
||||
throwable = new OptionalThrowable();
|
||||
else
|
||||
throwable = new OptionalThrowable(oldThrowable);
|
||||
}
|
||||
|
||||
public String fullyQualifiedName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public boolean isModule() {
|
||||
return classIsModule;
|
||||
public Fingerprint fingerprint() {
|
||||
return fingerprint;
|
||||
}
|
||||
|
||||
public Selector selector() {
|
||||
@@ -140,10 +146,13 @@ class EventWrapper implements Event {
|
||||
}
|
||||
}
|
||||
|
||||
public Throwable throwable() {
|
||||
return oldEvent.error();
|
||||
public OptionalThrowable throwable() {
|
||||
return throwable;
|
||||
}
|
||||
|
||||
public long duration() {
|
||||
return 0; // Just return 0 as old event does not have duration.
|
||||
}
|
||||
}
|
||||
|
||||
class RunnerWrapper implements Runner {
|
||||
@@ -157,8 +166,19 @@ class RunnerWrapper implements Runner {
|
||||
this.testClassLoader = testClassLoader;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public Task[] tasks(TaskDef[] taskDefs) {
|
||||
int length = taskDefs.length;
|
||||
Task[] tasks = new Task[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
TaskDef taskDef = taskDefs[i];
|
||||
tasks[i] = createTask(taskDef.fullyQualifiedName(), taskDef.fingerprint(), taskDef.explicitlySpecified(), taskDef.selectors());
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
|
||||
public Task task(final String fullyQualifiedName, final Fingerprint fingerprint, boolean explicitlySpecified, Selector[] selectors) {
|
||||
public Task createTask(final String fullyQualifiedName, final Fingerprint fingerprint, boolean explicitlySpecified, Selector[] selectors) {
|
||||
final TaskDef taskDef = new TaskDef(fullyQualifiedName, fingerprint, explicitlySpecified, selectors);
|
||||
return new Task() {
|
||||
public String[] tags() {
|
||||
return new String[0]; // Old framework does not support tags
|
||||
@@ -183,19 +203,17 @@ class RunnerWrapper implements Runner {
|
||||
public boolean isModule() { return subclassFingerprint.isModule(); }
|
||||
public String superClassName() { return subclassFingerprint.superclassName(); }
|
||||
};
|
||||
runner.run(fullyQualifiedName, oldFingerprint, new EventHandlerWrapper(eventHandler, fullyQualifiedName, subclassFingerprint.isModule()), args);
|
||||
runner.run(fullyQualifiedName, oldFingerprint, new EventHandlerWrapper(eventHandler, fullyQualifiedName, subclassFingerprint), args);
|
||||
}
|
||||
|
||||
private void runRunner2(org.scalatools.testing.Runner2 runner, Fingerprint fingerprint, EventHandler eventHandler) {
|
||||
org.scalatools.testing.Fingerprint oldFingerprint = null;
|
||||
boolean isModule = false;
|
||||
if (fingerprint instanceof SubclassFingerprint) {
|
||||
final SubclassFingerprint subclassFingerprint = (SubclassFingerprint) fingerprint;
|
||||
oldFingerprint = new org.scalatools.testing.SubclassFingerprint() {
|
||||
public boolean isModule() { return subclassFingerprint.isModule(); }
|
||||
public String superClassName() { return subclassFingerprint.superclassName(); }
|
||||
};
|
||||
isModule = subclassFingerprint.isModule();
|
||||
}
|
||||
else {
|
||||
final AnnotatedFingerprint annotatedFingerprint = (AnnotatedFingerprint) fingerprint;
|
||||
@@ -203,9 +221,8 @@ class RunnerWrapper implements Runner {
|
||||
public boolean isModule() { return annotatedFingerprint.isModule(); }
|
||||
public String annotationName() { return annotatedFingerprint.annotationName(); }
|
||||
};
|
||||
isModule = annotatedFingerprint.isModule();
|
||||
}
|
||||
runner.run(fullyQualifiedName, oldFingerprint, new EventHandlerWrapper(eventHandler, fullyQualifiedName, isModule), args);
|
||||
runner.run(fullyQualifiedName, oldFingerprint, new EventHandlerWrapper(eventHandler, fullyQualifiedName, fingerprint), args);
|
||||
}
|
||||
|
||||
public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
|
||||
@@ -224,6 +241,10 @@ class RunnerWrapper implements Runner {
|
||||
}
|
||||
return new Task[0];
|
||||
}
|
||||
|
||||
public TaskDef taskDef() {
|
||||
return taskDef;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user