mirror of https://github.com/sbt/sbt.git
Cleanup testAgentProj
This commit is contained in:
parent
222a970080
commit
d77e769635
|
|
@ -3,10 +3,10 @@ package sbt;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public final class ForkConfiguration implements Serializable {
|
public final class ForkConfiguration implements Serializable {
|
||||||
private boolean ansiCodesSupported;
|
private final boolean ansiCodesSupported;
|
||||||
private boolean parallel;
|
private final boolean parallel;
|
||||||
|
|
||||||
public ForkConfiguration(boolean ansiCodesSupported, boolean parallel) {
|
public ForkConfiguration(final boolean ansiCodesSupported, final boolean parallel) {
|
||||||
this.ansiCodesSupported = ansiCodesSupported;
|
this.ansiCodesSupported = ansiCodesSupported;
|
||||||
this.parallel = parallel;
|
this.parallel = parallel;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,16 +16,16 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
public class ForkMain {
|
final public class ForkMain {
|
||||||
|
|
||||||
// serializables
|
// serializables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static class SubclassFingerscan implements SubclassFingerprint, Serializable {
|
final static class SubclassFingerscan implements SubclassFingerprint, Serializable {
|
||||||
private boolean isModule;
|
private final boolean isModule;
|
||||||
private String superclassName;
|
private final String superclassName;
|
||||||
private boolean requireNoArgConstructor;
|
private final boolean requireNoArgConstructor;
|
||||||
SubclassFingerscan(SubclassFingerprint print) {
|
SubclassFingerscan(final SubclassFingerprint print) {
|
||||||
isModule = print.isModule();
|
isModule = print.isModule();
|
||||||
superclassName = print.superclassName();
|
superclassName = print.superclassName();
|
||||||
requireNoArgConstructor = print.requireNoArgConstructor();
|
requireNoArgConstructor = print.requireNoArgConstructor();
|
||||||
|
|
@ -35,10 +35,10 @@ public class ForkMain {
|
||||||
public boolean requireNoArgConstructor() { return requireNoArgConstructor; }
|
public boolean requireNoArgConstructor() { return requireNoArgConstructor; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static class AnnotatedFingerscan implements AnnotatedFingerprint, Serializable {
|
final static class AnnotatedFingerscan implements AnnotatedFingerprint, Serializable {
|
||||||
private boolean isModule;
|
private final boolean isModule;
|
||||||
private String annotationName;
|
private final String annotationName;
|
||||||
AnnotatedFingerscan(AnnotatedFingerprint print) {
|
AnnotatedFingerscan(final AnnotatedFingerprint print) {
|
||||||
isModule = print.isModule();
|
isModule = print.isModule();
|
||||||
annotationName = print.annotationName();
|
annotationName = print.annotationName();
|
||||||
}
|
}
|
||||||
|
|
@ -46,34 +46,34 @@ public class ForkMain {
|
||||||
public String annotationName() { return annotationName; }
|
public String annotationName() { return annotationName; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ForkEvent implements Event, Serializable {
|
final static class ForkEvent implements Event, Serializable {
|
||||||
private String fullyQualifiedName;
|
private final String fullyQualifiedName;
|
||||||
private Fingerprint fingerprint;
|
private final Fingerprint fingerprint;
|
||||||
private Selector selector;
|
private final Selector selector;
|
||||||
private Status status;
|
private final Status status;
|
||||||
private OptionalThrowable throwable;
|
private final OptionalThrowable throwable;
|
||||||
private long duration;
|
private final long duration;
|
||||||
|
|
||||||
ForkEvent(Event e) {
|
ForkEvent(final Event e) {
|
||||||
fullyQualifiedName = e.fullyQualifiedName();
|
fullyQualifiedName = e.fullyQualifiedName();
|
||||||
Fingerprint rawFingerprint = e.fingerprint();
|
final Fingerprint rawFingerprint = e.fingerprint();
|
||||||
|
|
||||||
if (rawFingerprint instanceof SubclassFingerprint)
|
if (rawFingerprint instanceof SubclassFingerprint)
|
||||||
this.fingerprint = new SubclassFingerscan((SubclassFingerprint) rawFingerprint);
|
fingerprint = new SubclassFingerscan((SubclassFingerprint) rawFingerprint);
|
||||||
else
|
else
|
||||||
this.fingerprint = new AnnotatedFingerscan((AnnotatedFingerprint) rawFingerprint);
|
fingerprint = new AnnotatedFingerscan((AnnotatedFingerprint) rawFingerprint);
|
||||||
|
|
||||||
selector = e.selector();
|
selector = e.selector();
|
||||||
checkSerializableSelector(selector);
|
checkSerializableSelector(selector);
|
||||||
status = e.status();
|
status = e.status();
|
||||||
OptionalThrowable originalThrowable = e.throwable();
|
final OptionalThrowable originalThrowable = e.throwable();
|
||||||
|
|
||||||
if (originalThrowable.isDefined())
|
if (originalThrowable.isDefined())
|
||||||
this.throwable = new OptionalThrowable(new ForkError(originalThrowable.get()));
|
throwable = new OptionalThrowable(new ForkError(originalThrowable.get()));
|
||||||
else
|
else
|
||||||
this.throwable = originalThrowable;
|
throwable = originalThrowable;
|
||||||
|
|
||||||
this.duration = e.duration();
|
duration = e.duration();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fullyQualifiedName() { return fullyQualifiedName; }
|
public String fullyQualifiedName() { return fullyQualifiedName; }
|
||||||
|
|
@ -83,7 +83,7 @@ public class ForkMain {
|
||||||
public OptionalThrowable throwable() { return throwable; }
|
public OptionalThrowable throwable() { return throwable; }
|
||||||
public long duration() { return duration; }
|
public long duration() { return duration; }
|
||||||
|
|
||||||
static void checkSerializableSelector(Selector selector) {
|
private static void checkSerializableSelector(final Selector selector) {
|
||||||
if (! (selector instanceof Serializable)) {
|
if (! (selector instanceof Serializable)) {
|
||||||
throw new UnsupportedOperationException("Selector implementation must be Serializable, but " + selector.getClass().getName() + " is not.");
|
throw new UnsupportedOperationException("Selector implementation must be Serializable, but " + selector.getClass().getName() + " is not.");
|
||||||
}
|
}
|
||||||
|
|
@ -93,11 +93,11 @@ public class ForkMain {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static class ForkError extends Exception {
|
final static class ForkError extends Exception {
|
||||||
private String originalMessage;
|
private final String originalMessage;
|
||||||
private String originalName;
|
private final String originalName;
|
||||||
private ForkError cause;
|
private ForkError cause;
|
||||||
ForkError(Throwable t) {
|
ForkError(final Throwable t) {
|
||||||
originalMessage = t.getMessage();
|
originalMessage = t.getMessage();
|
||||||
originalName = t.getClass().getName();
|
originalName = t.getClass().getName();
|
||||||
setStackTrace(t.getStackTrace());
|
setStackTrace(t.getStackTrace());
|
||||||
|
|
@ -111,8 +111,8 @@ public class ForkMain {
|
||||||
// main
|
// main
|
||||||
// ----------------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(final String[] args) throws Exception {
|
||||||
Socket socket = new Socket(InetAddress.getByName(null), Integer.valueOf(args[0]));
|
final Socket socket = new Socket(InetAddress.getByName(null), Integer.valueOf(args[0]));
|
||||||
final ObjectInputStream is = new ObjectInputStream(socket.getInputStream());
|
final ObjectInputStream is = new ObjectInputStream(socket.getInputStream());
|
||||||
final ObjectOutputStream os = new ObjectOutputStream(socket.getOutputStream());
|
final ObjectOutputStream os = new ObjectOutputStream(socket.getOutputStream());
|
||||||
// Must flush the header that the constructor writes, otherwise the ObjectInputStream on the other end may block indefinitely
|
// Must flush the header that the constructor writes, otherwise the ObjectInputStream on the other end may block indefinitely
|
||||||
|
|
@ -132,76 +132,76 @@ public class ForkMain {
|
||||||
// ----------------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
private static class Run {
|
final private static class Run {
|
||||||
|
|
||||||
void run(ObjectInputStream is, ObjectOutputStream os) {
|
private void run(final ObjectInputStream is, final ObjectOutputStream os) {
|
||||||
try {
|
try {
|
||||||
runTests(is, os);
|
runTests(is, os);
|
||||||
} catch (RunAborted e) {
|
} catch (final RunAborted e) {
|
||||||
internalError(e);
|
internalError(e);
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
try {
|
try {
|
||||||
logError(os, "Uncaught exception when running tests: " + t.toString());
|
logError(os, "Uncaught exception when running tests: " + t.toString());
|
||||||
write(os, new ForkError(t));
|
write(os, new ForkError(t));
|
||||||
} catch (Throwable t2) {
|
} catch (final Throwable t2) {
|
||||||
internalError(t2);
|
internalError(t2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean matches(Fingerprint f1, Fingerprint f2) {
|
private boolean matches(final Fingerprint f1, final Fingerprint f2) {
|
||||||
if (f1 instanceof SubclassFingerprint && f2 instanceof SubclassFingerprint) {
|
if (f1 instanceof SubclassFingerprint && f2 instanceof SubclassFingerprint) {
|
||||||
final SubclassFingerprint sf1 = (SubclassFingerprint) f1;
|
final SubclassFingerprint sf1 = (SubclassFingerprint) f1;
|
||||||
final SubclassFingerprint sf2 = (SubclassFingerprint) f2;
|
final SubclassFingerprint sf2 = (SubclassFingerprint) f2;
|
||||||
return sf1.isModule() == sf2.isModule() && sf1.superclassName().equals(sf2.superclassName());
|
return sf1.isModule() == sf2.isModule() && sf1.superclassName().equals(sf2.superclassName());
|
||||||
} else if (f1 instanceof AnnotatedFingerprint && f2 instanceof AnnotatedFingerprint) {
|
} else if (f1 instanceof AnnotatedFingerprint && f2 instanceof AnnotatedFingerprint) {
|
||||||
AnnotatedFingerprint af1 = (AnnotatedFingerprint) f1;
|
final AnnotatedFingerprint af1 = (AnnotatedFingerprint) f1;
|
||||||
AnnotatedFingerprint af2 = (AnnotatedFingerprint) f2;
|
final AnnotatedFingerprint af2 = (AnnotatedFingerprint) f2;
|
||||||
return af1.isModule() == af2.isModule() && af1.annotationName().equals(af2.annotationName());
|
return af1.isModule() == af2.isModule() && af1.annotationName().equals(af2.annotationName());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
class RunAborted extends RuntimeException {
|
class RunAborted extends RuntimeException {
|
||||||
RunAborted(Exception e) { super(e); }
|
RunAborted(final Exception e) { super(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void write(ObjectOutputStream os, Object obj) {
|
private synchronized void write(final ObjectOutputStream os, final Object obj) {
|
||||||
try {
|
try {
|
||||||
os.writeObject(obj);
|
os.writeObject(obj);
|
||||||
os.flush();
|
os.flush();
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new RunAborted(e);
|
throw new RunAborted(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void log(ObjectOutputStream os, String message, ForkTags level) {
|
private void log(final ObjectOutputStream os, final String message, final ForkTags level) {
|
||||||
write(os, new Object[]{level, message});
|
write(os, new Object[]{level, message});
|
||||||
}
|
}
|
||||||
|
|
||||||
void logDebug(ObjectOutputStream os, String message) { log(os, message, ForkTags.Debug); }
|
private void logDebug(final ObjectOutputStream os, final String message) { log(os, message, ForkTags.Debug); }
|
||||||
void logInfo(ObjectOutputStream os, String message) { log(os, message, ForkTags.Info); }
|
private void logInfo(final ObjectOutputStream os, final String message) { log(os, message, ForkTags.Info); }
|
||||||
void logWarn(ObjectOutputStream os, String message) { log(os, message, ForkTags.Warn); }
|
private void logWarn(final ObjectOutputStream os, final String message) { log(os, message, ForkTags.Warn); }
|
||||||
void logError(ObjectOutputStream os, String message) { log(os, message, ForkTags.Error); }
|
private void logError(final ObjectOutputStream os, final String message) { log(os, message, ForkTags.Error); }
|
||||||
|
|
||||||
Logger remoteLogger(final boolean ansiCodesSupported, final ObjectOutputStream os) {
|
private Logger remoteLogger(final boolean ansiCodesSupported, final ObjectOutputStream os) {
|
||||||
return new Logger() {
|
return new Logger() {
|
||||||
public boolean ansiCodesSupported() { return ansiCodesSupported; }
|
public boolean ansiCodesSupported() { return ansiCodesSupported; }
|
||||||
public void error(String s) { logError(os, s); }
|
public void error(final String s) { logError(os, s); }
|
||||||
public void warn(String s) { logWarn(os, s); }
|
public void warn(final String s) { logWarn(os, s); }
|
||||||
public void info(String s) { logInfo(os, s); }
|
public void info(final String s) { logInfo(os, s); }
|
||||||
public void debug(String s) { logDebug(os, s); }
|
public void debug(final String s) { logDebug(os, s); }
|
||||||
public void trace(Throwable t) { write(os, new ForkError(t)); }
|
public void trace(final Throwable t) { write(os, new ForkError(t)); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeEvents(ObjectOutputStream os, TaskDef taskDef, ForkEvent[] events) {
|
private void writeEvents(final ObjectOutputStream os, final TaskDef taskDef, final ForkEvent[] events) {
|
||||||
write(os, new Object[]{taskDef.fullyQualifiedName(), events});
|
write(os, new Object[]{taskDef.fullyQualifiedName(), events});
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutorService executorService(ForkConfiguration config, ObjectOutputStream os) {
|
private ExecutorService executorService(final ForkConfiguration config, final ObjectOutputStream os) {
|
||||||
if(config.isParallel()) {
|
if(config.isParallel()) {
|
||||||
int nbThreads = Runtime.getRuntime().availableProcessors();
|
final int nbThreads = Runtime.getRuntime().availableProcessors();
|
||||||
logDebug(os, "Create a test executor with a thread pool of " + nbThreads + " threads.");
|
logDebug(os, "Create a test executor with a thread pool of " + nbThreads + " threads.");
|
||||||
// more options later...
|
// more options later...
|
||||||
// TODO we might want to configure the blocking queue with size #proc
|
// TODO we might want to configure the blocking queue with size #proc
|
||||||
|
|
@ -212,12 +212,12 @@ public class ForkMain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void runTests(ObjectInputStream is, final ObjectOutputStream os) throws Exception {
|
private void runTests(final ObjectInputStream is, final ObjectOutputStream os) throws Exception {
|
||||||
final ForkConfiguration config = (ForkConfiguration) is.readObject();
|
final ForkConfiguration config = (ForkConfiguration) is.readObject();
|
||||||
ExecutorService executor = executorService(config, os);
|
final ExecutorService executor = executorService(config, os);
|
||||||
final TaskDef[] tests = (TaskDef[]) is.readObject();
|
final TaskDef[] tests = (TaskDef[]) is.readObject();
|
||||||
int nFrameworks = is.readInt();
|
final int nFrameworks = is.readInt();
|
||||||
Logger[] loggers = { remoteLogger(config.isAnsiCodesSupported(), os) };
|
final Logger[] loggers = { remoteLogger(config.isAnsiCodesSupported(), os) };
|
||||||
|
|
||||||
for (int i = 0; i < nFrameworks; i++) {
|
for (int i = 0; i < nFrameworks; i++) {
|
||||||
final String[] implClassNames = (String[]) is.readObject();
|
final String[] implClassNames = (String[]) is.readObject();
|
||||||
|
|
@ -225,15 +225,15 @@ public class ForkMain {
|
||||||
final String[] remoteFrameworkArgs = (String[]) is.readObject();
|
final String[] remoteFrameworkArgs = (String[]) is.readObject();
|
||||||
|
|
||||||
Framework framework = null;
|
Framework framework = null;
|
||||||
for (String implClassName : implClassNames) {
|
for (final String implClassName : implClassNames) {
|
||||||
try {
|
try {
|
||||||
Object rawFramework = Class.forName(implClassName).newInstance();
|
final Object rawFramework = Class.forName(implClassName).newInstance();
|
||||||
if (rawFramework instanceof Framework)
|
if (rawFramework instanceof Framework)
|
||||||
framework = (Framework) rawFramework;
|
framework = (Framework) rawFramework;
|
||||||
else
|
else
|
||||||
framework = new FrameworkWrapper((org.scalatools.testing.Framework) rawFramework);
|
framework = new FrameworkWrapper((org.scalatools.testing.Framework) rawFramework);
|
||||||
break;
|
break;
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (final ClassNotFoundException e) {
|
||||||
logDebug(os, "Framework implementation '" + implClassName + "' not present.");
|
logDebug(os, "Framework implementation '" + implClassName + "' not present.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -241,16 +241,16 @@ public class ForkMain {
|
||||||
if (framework == null)
|
if (framework == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ArrayList<TaskDef> filteredTests = new ArrayList<TaskDef>();
|
final ArrayList<TaskDef> filteredTests = new ArrayList<TaskDef>();
|
||||||
for (Fingerprint testFingerprint : framework.fingerprints()) {
|
for (final Fingerprint testFingerprint : framework.fingerprints()) {
|
||||||
for (TaskDef test : tests) {
|
for (final TaskDef test : tests) {
|
||||||
// TODO: To pass in correct explicitlySpecified and selectors
|
// TODO: To pass in correct explicitlySpecified and selectors
|
||||||
if (matches(testFingerprint, test.fingerprint()))
|
if (matches(testFingerprint, test.fingerprint()))
|
||||||
filteredTests.add(new TaskDef(test.fullyQualifiedName(), test.fingerprint(), test.explicitlySpecified(), test.selectors()));
|
filteredTests.add(new TaskDef(test.fullyQualifiedName(), test.fingerprint(), test.explicitlySpecified(), test.selectors()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Runner runner = framework.runner(frameworkArgs, remoteFrameworkArgs, getClass().getClassLoader());
|
final Runner runner = framework.runner(frameworkArgs, remoteFrameworkArgs, getClass().getClassLoader());
|
||||||
Task[] tasks = runner.tasks(filteredTests.toArray(new TaskDef[filteredTests.size()]));
|
final Task[] tasks = runner.tasks(filteredTests.toArray(new TaskDef[filteredTests.size()]));
|
||||||
logDebug(os, "Runner for " + framework.getClass().getName() + " produced " + tasks.length + " initial tasks for " + filteredTests.size() + " tests.");
|
logDebug(os, "Runner for " + framework.getClass().getName() + " produced " + tasks.length + " initial tasks for " + filteredTests.size() + " tests.");
|
||||||
|
|
||||||
runTestTasks(executor, tasks, loggers, os);
|
runTestTasks(executor, tasks, loggers, os);
|
||||||
|
|
@ -261,20 +261,20 @@ public class ForkMain {
|
||||||
is.readObject();
|
is.readObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void runTestTasks(ExecutorService executor, Task[] tasks, Logger[] loggers, ObjectOutputStream os) {
|
private void runTestTasks(final ExecutorService executor, final Task[] tasks, final Logger[] loggers, final ObjectOutputStream os) {
|
||||||
if( tasks.length > 0 ) {
|
if( tasks.length > 0 ) {
|
||||||
List<Future<Task[]>> futureNestedTasks = new ArrayList<Future<Task[]>>();
|
final List<Future<Task[]>> futureNestedTasks = new ArrayList<Future<Task[]>>();
|
||||||
for( Task task : tasks ) {
|
for( final Task task : tasks ) {
|
||||||
futureNestedTasks.add(runTest(executor, task, loggers, os));
|
futureNestedTasks.add(runTest(executor, task, loggers, os));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: this could be optimized further, we could have a callback once a test finishes that executes immediately the nested tasks
|
// Note: this could be optimized further, we could have a callback once a test finishes that executes immediately the nested tasks
|
||||||
// At the moment, I'm especially interested in JUnit, which doesn't have nested tasks.
|
// At the moment, I'm especially interested in JUnit, which doesn't have nested tasks.
|
||||||
List<Task> nestedTasks = new ArrayList<Task>();
|
final List<Task> nestedTasks = new ArrayList<Task>();
|
||||||
for( Future<Task[]> futureNestedTask : futureNestedTasks ) {
|
for( final Future<Task[]> futureNestedTask : futureNestedTasks ) {
|
||||||
try {
|
try {
|
||||||
nestedTasks.addAll( Arrays.asList(futureNestedTask.get()));
|
nestedTasks.addAll( Arrays.asList(futureNestedTask.get()));
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
logError(os, "Failed to execute task " + futureNestedTask);
|
logError(os, "Failed to execute task " + futureNestedTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -282,23 +282,23 @@ public class ForkMain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Task[]> runTest(ExecutorService executor, final Task task, final Logger[] loggers, final ObjectOutputStream os) {
|
private Future<Task[]> runTest(final ExecutorService executor, final Task task, final Logger[] loggers, final ObjectOutputStream os) {
|
||||||
return executor.submit(new Callable<Task[]>() {
|
return executor.submit(new Callable<Task[]>() {
|
||||||
@Override
|
@Override
|
||||||
public Task[] call() {
|
public Task[] call() {
|
||||||
ForkEvent[] events;
|
ForkEvent[] events;
|
||||||
Task[] nestedTasks;
|
Task[] nestedTasks;
|
||||||
TaskDef taskDef = task.taskDef();
|
final TaskDef taskDef = task.taskDef();
|
||||||
try {
|
try {
|
||||||
final List<ForkEvent> eventList = new ArrayList<ForkEvent>();
|
final List<ForkEvent> eventList = new ArrayList<ForkEvent>();
|
||||||
EventHandler handler = new EventHandler() { public void handle(Event e){ eventList.add(new ForkEvent(e)); } };
|
final EventHandler handler = new EventHandler() { public void handle(final Event e){ eventList.add(new ForkEvent(e)); } };
|
||||||
logDebug(os, " Running " + taskDef);
|
logDebug(os, " Running " + taskDef);
|
||||||
nestedTasks = task.execute(handler, loggers);
|
nestedTasks = task.execute(handler, loggers);
|
||||||
if(nestedTasks.length > 0 || eventList.size() > 0)
|
if(nestedTasks.length > 0 || eventList.size() > 0)
|
||||||
logDebug(os, " Produced " + nestedTasks.length + " nested tasks and " + eventList.size() + " events.");
|
logDebug(os, " Produced " + nestedTasks.length + " nested tasks and " + eventList.size() + " events.");
|
||||||
events = eventList.toArray(new ForkEvent[eventList.size()]);
|
events = eventList.toArray(new ForkEvent[eventList.size()]);
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (final Throwable t) {
|
||||||
nestedTasks = new Task[0];
|
nestedTasks = new Task[0];
|
||||||
events = new ForkEvent[] { testError(os, taskDef, "Uncaught exception when running " + taskDef.fullyQualifiedName() + ": " + t.toString(), t) };
|
events = new ForkEvent[] { testError(os, taskDef, "Uncaught exception when running " + taskDef.fullyQualifiedName() + ": " + t.toString(), t) };
|
||||||
}
|
}
|
||||||
|
|
@ -308,11 +308,11 @@ public class ForkMain {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void internalError(Throwable t) {
|
private void internalError(final Throwable t) {
|
||||||
System.err.println("Internal error when running tests: " + t.toString());
|
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 ForkError err, final long duration) {
|
private ForkEvent testEvent(final String fullyQualifiedName, final Fingerprint fingerprint, final Selector selector, final Status r, final ForkError err, final long duration) {
|
||||||
final OptionalThrowable throwable;
|
final OptionalThrowable throwable;
|
||||||
if (err == null)
|
if (err == null)
|
||||||
throwable = new OptionalThrowable();
|
throwable = new OptionalThrowable();
|
||||||
|
|
@ -332,9 +332,9 @@ public class ForkMain {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ForkEvent testError(ObjectOutputStream os, TaskDef taskDef, String message, Throwable t) {
|
private ForkEvent testError(final ObjectOutputStream os, final TaskDef taskDef, final String message, final Throwable t) {
|
||||||
logError(os, message);
|
logError(os, message);
|
||||||
ForkError fe = new ForkError(t);
|
final ForkError fe = new ForkError(t);
|
||||||
write(os, fe);
|
write(os, fe);
|
||||||
return testEvent(taskDef.fullyQualifiedName(), taskDef.fingerprint(), new SuiteSelector(), Status.Error, fe, 0);
|
return testEvent(taskDef.fullyQualifiedName(), taskDef.fingerprint(), new SuiteSelector(), Status.Error, fe, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,3 @@ package sbt;
|
||||||
public enum ForkTags {
|
public enum ForkTags {
|
||||||
Error, Warn, Info, Debug, Done
|
Error, Warn, Info, Debug, Done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ import sbt.testing.*;
|
||||||
*/
|
*/
|
||||||
final class FrameworkWrapper implements Framework {
|
final class FrameworkWrapper implements Framework {
|
||||||
|
|
||||||
private org.scalatools.testing.Framework oldFramework;
|
private final org.scalatools.testing.Framework oldFramework;
|
||||||
|
|
||||||
public FrameworkWrapper(org.scalatools.testing.Framework oldFramework) {
|
FrameworkWrapper(final org.scalatools.testing.Framework oldFramework) {
|
||||||
this.oldFramework = oldFramework;
|
this.oldFramework = oldFramework;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,11 +19,11 @@ final class FrameworkWrapper implements Framework {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Fingerprint[] fingerprints() {
|
public Fingerprint[] fingerprints() {
|
||||||
org.scalatools.testing.Fingerprint[] oldFingerprints = oldFramework.tests();
|
final org.scalatools.testing.Fingerprint[] oldFingerprints = oldFramework.tests();
|
||||||
int length = oldFingerprints.length;
|
final int length = oldFingerprints.length;
|
||||||
Fingerprint[] fingerprints = new Fingerprint[length];
|
final Fingerprint[] fingerprints = new Fingerprint[length];
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
org.scalatools.testing.Fingerprint oldFingerprint = oldFingerprints[i];
|
final org.scalatools.testing.Fingerprint oldFingerprint = oldFingerprints[i];
|
||||||
if (oldFingerprint instanceof org.scalatools.testing.TestFingerprint)
|
if (oldFingerprint instanceof org.scalatools.testing.TestFingerprint)
|
||||||
fingerprints[i] = new SubclassFingerprintWrapper((org.scalatools.testing.TestFingerprint) oldFingerprint);
|
fingerprints[i] = new SubclassFingerprintWrapper((org.scalatools.testing.TestFingerprint) oldFingerprint);
|
||||||
else if (oldFingerprint instanceof org.scalatools.testing.SubclassFingerprint)
|
else if (oldFingerprint instanceof org.scalatools.testing.SubclassFingerprint)
|
||||||
|
|
@ -34,20 +34,20 @@ final class FrameworkWrapper implements Framework {
|
||||||
return fingerprints;
|
return fingerprints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Runner runner(String[] args, String[] remoteArgs, ClassLoader testClassLoader) {
|
public Runner runner(final String[] args, final String[] remoteArgs, final ClassLoader testClassLoader) {
|
||||||
return new RunnerWrapper(oldFramework, testClassLoader, args);
|
return new RunnerWrapper(oldFramework, testClassLoader, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class SubclassFingerprintWrapper implements SubclassFingerprint {
|
final class SubclassFingerprintWrapper implements SubclassFingerprint {
|
||||||
private String superclassName;
|
private final String superclassName;
|
||||||
private boolean isModule;
|
private final boolean isModule;
|
||||||
private boolean requireNoArgConstructor;
|
private final boolean requireNoArgConstructor;
|
||||||
|
|
||||||
public SubclassFingerprintWrapper(org.scalatools.testing.SubclassFingerprint oldFingerprint) {
|
SubclassFingerprintWrapper(final org.scalatools.testing.SubclassFingerprint oldFingerprint) {
|
||||||
this.superclassName = oldFingerprint.superClassName();
|
superclassName = oldFingerprint.superClassName();
|
||||||
this.isModule = oldFingerprint.isModule();
|
isModule = oldFingerprint.isModule();
|
||||||
this.requireNoArgConstructor = false; // Old framework SubclassFingerprint does not require no arg constructor
|
requireNoArgConstructor = false; // Old framework SubclassFingerprint does not require no arg constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isModule() {
|
public boolean isModule() {
|
||||||
|
|
@ -64,12 +64,12 @@ final class SubclassFingerprintWrapper implements SubclassFingerprint {
|
||||||
}
|
}
|
||||||
|
|
||||||
final class AnnotatedFingerprintWrapper implements AnnotatedFingerprint {
|
final class AnnotatedFingerprintWrapper implements AnnotatedFingerprint {
|
||||||
private String annotationName;
|
private final String annotationName;
|
||||||
private boolean isModule;
|
private final boolean isModule;
|
||||||
|
|
||||||
public AnnotatedFingerprintWrapper(org.scalatools.testing.AnnotatedFingerprint oldFingerprint) {
|
AnnotatedFingerprintWrapper(final org.scalatools.testing.AnnotatedFingerprint oldFingerprint) {
|
||||||
this.annotationName = oldFingerprint.annotationName();
|
annotationName = oldFingerprint.annotationName();
|
||||||
this.isModule = oldFingerprint.isModule();
|
isModule = oldFingerprint.isModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isModule() {
|
public boolean isModule() {
|
||||||
|
|
@ -83,33 +83,33 @@ final class AnnotatedFingerprintWrapper implements AnnotatedFingerprint {
|
||||||
|
|
||||||
final class EventHandlerWrapper implements org.scalatools.testing.EventHandler {
|
final class EventHandlerWrapper implements org.scalatools.testing.EventHandler {
|
||||||
|
|
||||||
private EventHandler newEventHandler;
|
private final EventHandler newEventHandler;
|
||||||
private String fullyQualifiedName;
|
private final String fullyQualifiedName;
|
||||||
private Fingerprint fingerprint;
|
private final Fingerprint fingerprint;
|
||||||
|
|
||||||
public EventHandlerWrapper(EventHandler newEventHandler, String fullyQualifiedName, Fingerprint fingerprint) {
|
EventHandlerWrapper(final EventHandler newEventHandler, final String fullyQualifiedName, final Fingerprint fingerprint) {
|
||||||
this.newEventHandler = newEventHandler;
|
this.newEventHandler = newEventHandler;
|
||||||
this.fullyQualifiedName = fullyQualifiedName;
|
this.fullyQualifiedName = fullyQualifiedName;
|
||||||
this.fingerprint = fingerprint;
|
this.fingerprint = fingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle(org.scalatools.testing.Event oldEvent) {
|
public void handle(final org.scalatools.testing.Event oldEvent) {
|
||||||
newEventHandler.handle(new EventWrapper(oldEvent, fullyQualifiedName, fingerprint));
|
newEventHandler.handle(new EventWrapper(oldEvent, fullyQualifiedName, fingerprint));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class EventWrapper implements Event {
|
final class EventWrapper implements Event {
|
||||||
|
|
||||||
private org.scalatools.testing.Event oldEvent;
|
private final org.scalatools.testing.Event oldEvent;
|
||||||
private String className;
|
private final String className;
|
||||||
private Fingerprint fingerprint;
|
private final Fingerprint fingerprint;
|
||||||
private OptionalThrowable throwable;
|
private final OptionalThrowable throwable;
|
||||||
|
|
||||||
public EventWrapper(org.scalatools.testing.Event oldEvent, String className, Fingerprint fingerprint) {
|
EventWrapper(final org.scalatools.testing.Event oldEvent, final String className, final Fingerprint fingerprint) {
|
||||||
this.oldEvent = oldEvent;
|
this.oldEvent = oldEvent;
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.fingerprint = fingerprint;
|
this.fingerprint = fingerprint;
|
||||||
Throwable oldThrowable = oldEvent.error();
|
final Throwable oldThrowable = oldEvent.error();
|
||||||
if (oldThrowable == null)
|
if (oldThrowable == null)
|
||||||
throwable = new OptionalThrowable();
|
throwable = new OptionalThrowable();
|
||||||
else
|
else
|
||||||
|
|
@ -154,27 +154,27 @@ final class EventWrapper implements Event {
|
||||||
|
|
||||||
final class RunnerWrapper implements Runner {
|
final class RunnerWrapper implements Runner {
|
||||||
|
|
||||||
private org.scalatools.testing.Framework oldFramework;
|
private final org.scalatools.testing.Framework oldFramework;
|
||||||
private ClassLoader testClassLoader;
|
private final ClassLoader testClassLoader;
|
||||||
private String[] args;
|
private final String[] args;
|
||||||
|
|
||||||
public RunnerWrapper(org.scalatools.testing.Framework oldFramework, ClassLoader testClassLoader, String[] args) {
|
RunnerWrapper(final org.scalatools.testing.Framework oldFramework, final ClassLoader testClassLoader, final String[] args) {
|
||||||
this.oldFramework = oldFramework;
|
this.oldFramework = oldFramework;
|
||||||
this.testClassLoader = testClassLoader;
|
this.testClassLoader = testClassLoader;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task[] tasks(TaskDef[] taskDefs) {
|
public Task[] tasks(final TaskDef[] taskDefs) {
|
||||||
int length = taskDefs.length;
|
final int length = taskDefs.length;
|
||||||
Task[] tasks = new Task[length];
|
final Task[] tasks = new Task[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
TaskDef taskDef = taskDefs[i];
|
final TaskDef taskDef = taskDefs[i];
|
||||||
tasks[i] = createTask(taskDef);
|
tasks[i] = createTask(taskDef);
|
||||||
}
|
}
|
||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task createTask(final TaskDef taskDef) {
|
private Task createTask(final TaskDef taskDef) {
|
||||||
return new Task() {
|
return new Task() {
|
||||||
public String[] tags() {
|
public String[] tags() {
|
||||||
return new String[0]; // Old framework does not support tags
|
return new String[0]; // Old framework does not support tags
|
||||||
|
|
@ -183,18 +183,18 @@ final class RunnerWrapper implements Runner {
|
||||||
private org.scalatools.testing.Logger createOldLogger(final Logger logger) {
|
private org.scalatools.testing.Logger createOldLogger(final Logger logger) {
|
||||||
return new org.scalatools.testing.Logger() {
|
return new org.scalatools.testing.Logger() {
|
||||||
public boolean ansiCodesSupported() { return logger.ansiCodesSupported(); }
|
public boolean ansiCodesSupported() { return logger.ansiCodesSupported(); }
|
||||||
public void error(String msg) { logger.error(msg); }
|
public void error(final String msg) { logger.error(msg); }
|
||||||
public void warn(String msg) { logger.warn(msg); }
|
public void warn(final String msg) { logger.warn(msg); }
|
||||||
public void info(String msg) { logger.info(msg); }
|
public void info(final String msg) { logger.info(msg); }
|
||||||
public void debug(String msg) { logger.debug(msg); }
|
public void debug(final String msg) { logger.debug(msg); }
|
||||||
public void trace(Throwable t) { logger.trace(t); }
|
public void trace(final Throwable t) { logger.trace(t); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runRunner(org.scalatools.testing.Runner runner, Fingerprint fingerprint, EventHandler eventHandler) {
|
private void runRunner(final org.scalatools.testing.Runner runner, final Fingerprint fingerprint, final EventHandler eventHandler) {
|
||||||
// Old runner only support subclass fingerprint.
|
// Old runner only support subclass fingerprint.
|
||||||
final SubclassFingerprint subclassFingerprint = (SubclassFingerprint) fingerprint;
|
final SubclassFingerprint subclassFingerprint = (SubclassFingerprint) fingerprint;
|
||||||
org.scalatools.testing.TestFingerprint oldFingerprint =
|
final org.scalatools.testing.TestFingerprint oldFingerprint =
|
||||||
new org.scalatools.testing.TestFingerprint() {
|
new org.scalatools.testing.TestFingerprint() {
|
||||||
public boolean isModule() { return subclassFingerprint.isModule(); }
|
public boolean isModule() { return subclassFingerprint.isModule(); }
|
||||||
public String superClassName() { return subclassFingerprint.superclassName(); }
|
public String superClassName() { return subclassFingerprint.superclassName(); }
|
||||||
|
|
@ -203,8 +203,8 @@ final class RunnerWrapper implements Runner {
|
||||||
runner.run(name, oldFingerprint, new EventHandlerWrapper(eventHandler, name, subclassFingerprint), args);
|
runner.run(name, oldFingerprint, new EventHandlerWrapper(eventHandler, name, subclassFingerprint), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runRunner2(org.scalatools.testing.Runner2 runner, Fingerprint fingerprint, EventHandler eventHandler) {
|
private void runRunner2(final org.scalatools.testing.Runner2 runner, final Fingerprint fingerprint, final EventHandler eventHandler) {
|
||||||
org.scalatools.testing.Fingerprint oldFingerprint = null;
|
final org.scalatools.testing.Fingerprint oldFingerprint;
|
||||||
if (fingerprint instanceof SubclassFingerprint) {
|
if (fingerprint instanceof SubclassFingerprint) {
|
||||||
final SubclassFingerprint subclassFingerprint = (SubclassFingerprint) fingerprint;
|
final SubclassFingerprint subclassFingerprint = (SubclassFingerprint) fingerprint;
|
||||||
oldFingerprint = new org.scalatools.testing.SubclassFingerprint() {
|
oldFingerprint = new org.scalatools.testing.SubclassFingerprint() {
|
||||||
|
|
@ -223,9 +223,9 @@ final class RunnerWrapper implements Runner {
|
||||||
runner.run(name, oldFingerprint, new EventHandlerWrapper(eventHandler, name, fingerprint), args);
|
runner.run(name, oldFingerprint, new EventHandlerWrapper(eventHandler, name, fingerprint), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
|
public Task[] execute(final EventHandler eventHandler, final Logger[] loggers) {
|
||||||
int length = loggers.length;
|
final int length = loggers.length;
|
||||||
org.scalatools.testing.Logger[] oldLoggers = new org.scalatools.testing.Logger[length];
|
final org.scalatools.testing.Logger[] oldLoggers = new org.scalatools.testing.Logger[length];
|
||||||
for (int i=0; i<length; i++) {
|
for (int i=0; i<length; i++) {
|
||||||
oldLoggers[i] = createOldLogger(loggers[i]);
|
oldLoggers[i] = createOldLogger(loggers[i]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue