mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
sm runner: don't use segmented output streams; provide separate runner for junit 3
This commit is contained in:
@@ -136,8 +136,9 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
|
||||
JUnitConfiguration configuration = createConfiguration(testA);
|
||||
JavaParameters parameters = checkCanRun(configuration);
|
||||
CHECK.empty(parameters.getVMParametersList().getList());
|
||||
final SegmentedOutputStream notifications = new SegmentedOutputStream(System.out);
|
||||
assertTrue(JUnitStarter.checkVersion(parameters.getProgramParametersList().getArray(),
|
||||
new SegmentedOutputStream(System.out)));
|
||||
new PrintStream(notifications)));
|
||||
assertTrue(parameters.getProgramParametersList().getList().contains(testA.getQualifiedName()));
|
||||
assertEquals(JUnitStarter.class.getName(), parameters.getMainClass());
|
||||
assertEquals(myJdk.getHomeDirectory().getPresentableUrl(), parameters.getJdkPath());
|
||||
|
||||
@@ -17,15 +17,14 @@ package com.intellij.junit3;
|
||||
|
||||
import com.intellij.rt.execution.junit.*;
|
||||
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
|
||||
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
|
||||
import com.intellij.rt.execution.junit.segments.PacketProcessor;
|
||||
import jetbrains.buildServer.messages.serviceMessages.ServiceMessage;
|
||||
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageTypes;
|
||||
import junit.framework.*;
|
||||
import junit.textui.ResultPrinter;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
|
||||
public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
|
||||
private TestListener myTestsListener;
|
||||
@@ -39,7 +38,7 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
|
||||
|
||||
public int startRunnerWithArgs(String[] args, ArrayList listeners, String name, int count, boolean sendTree) {
|
||||
myListeners = listeners;
|
||||
mySendTree = sendTree;
|
||||
mySendTree = sendTree && !(myTestsListener instanceof SMTestListener);
|
||||
if (sendTree) {
|
||||
setPrinter(new TimeSender(myRegistry));
|
||||
}
|
||||
@@ -69,9 +68,13 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
|
||||
super.runFailed(message);
|
||||
}
|
||||
|
||||
public void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr, int lastIdx) {
|
||||
myRegistry = new JUnit3OutputObjectRegistry(segmentedOut, lastIdx);
|
||||
myTestsListener = new TestResultsSender(myRegistry);
|
||||
public void setStreams(Object segmentedOut, Object segmentedErr, int lastIdx) {
|
||||
if (JUnitStarter.SM_RUNNER) {
|
||||
myTestsListener = new SMTestListener();
|
||||
} else {
|
||||
myRegistry = new JUnit3OutputObjectRegistry((PacketProcessor)segmentedOut, lastIdx);
|
||||
myTestsListener = new TestResultsSender(myRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getTestToStart(String[] args, String name) {
|
||||
@@ -138,7 +141,11 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
|
||||
System.err.println("Internal Error occured.");
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return super.doRun(suite, wait);
|
||||
final TestResult testResult = super.doRun(suite, wait);
|
||||
if (myTestsListener instanceof SMTestListener) {
|
||||
((SMTestListener)myTestsListener).finishSuite();
|
||||
}
|
||||
return testResult;
|
||||
}
|
||||
|
||||
static Vector getTestCasesOf(Test test) {
|
||||
@@ -163,4 +170,53 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
|
||||
super(DeafStream.DEAF_PRINT_STREAM);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SMTestListener implements TestListener {
|
||||
private String myClassName;
|
||||
|
||||
public void addError(Test test, Throwable e) {
|
||||
final String failureMessage = e.getMessage();
|
||||
final Map attrs = new HashMap();
|
||||
attrs.put("name", getMethodName(test));
|
||||
attrs.put("message", failureMessage != null ? failureMessage : "");
|
||||
System.out.println(ServiceMessage.asString(ServiceMessageTypes.TEST_FAILED, attrs));
|
||||
}
|
||||
|
||||
private static String getMethodName(Test test) {
|
||||
final String toString = test.toString();
|
||||
final int braceIdx = toString.indexOf("(");
|
||||
return braceIdx > 0 ? toString.substring(0, braceIdx) : toString;
|
||||
}
|
||||
|
||||
private static String getClassName(Test test) {
|
||||
final String toString = test.toString();
|
||||
final int braceIdx = toString.indexOf("(");
|
||||
return braceIdx > 0 && toString.endsWith(")") ? toString.substring(braceIdx + 1, toString.length() - 1) : null;
|
||||
}
|
||||
|
||||
public void addFailure(Test test, AssertionFailedError e) {
|
||||
addError(test, e);
|
||||
}
|
||||
|
||||
public void endTest(Test test) {
|
||||
System.out.println("\n##teamcity[testFinished name=\'" + getMethodName(test) + "\']");
|
||||
}
|
||||
|
||||
public void startTest(Test test) {
|
||||
final String className = getClassName(test);
|
||||
if (className != null && !className.equals(myClassName)) {
|
||||
finishSuite();
|
||||
myClassName = className;
|
||||
System.out.println("##teamcity[testSuiteStarted name =\'" + myClassName + "\' locationHint=\'java:suite://" + className + "\']");
|
||||
}
|
||||
final String methodName = getMethodName(test);
|
||||
System.out.println("##teamcity[testStarted name=\'" + methodName + "\' locationHint=\'java:test://" + className + "." + methodName + "\']");
|
||||
}
|
||||
|
||||
protected void finishSuite() {
|
||||
if (myClassName != null) {
|
||||
System.out.println("##teamcity[testSuiteFinished name=\'" + myClassName + "\']");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ package com.intellij.junit4;
|
||||
|
||||
import com.intellij.rt.execution.junit.*;
|
||||
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
|
||||
import com.intellij.rt.execution.junit.segments.Packet;
|
||||
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
|
||||
import com.intellij.rt.execution.junit.segments.PacketProcessor;
|
||||
import org.junit.internal.requests.ClassRequest;
|
||||
import org.junit.internal.requests.FilterRequest;
|
||||
import org.junit.runner.*;
|
||||
@@ -183,11 +182,11 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
}
|
||||
|
||||
|
||||
public void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr, int lastIdx) {
|
||||
public void setStreams(Object segmentedOut, Object segmentedErr, int lastIdx) {
|
||||
if (JUnitStarter.SM_RUNNER) {
|
||||
myTestsListener = new SMTestSender();
|
||||
} else {
|
||||
myRegistry = new JUnit4OutputObjectRegistry(segmentedOut, lastIdx);
|
||||
myRegistry = new JUnit4OutputObjectRegistry((PacketProcessor)segmentedOut, lastIdx);
|
||||
myTestsListener = new JUnit4TestResultsSender(myRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
package com.intellij.rt.execution.junit;
|
||||
|
||||
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
|
||||
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,7 +28,7 @@ import java.util.List;
|
||||
public interface IdeaTestRunner {
|
||||
|
||||
int startRunnerWithArgs(String[] args, ArrayList listeners, String name, int count, boolean sendTree);
|
||||
void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr, int lastIdx);
|
||||
void setStreams(Object segmentedOut, Object segmentedErr, int lastIdx);
|
||||
|
||||
Object getTestToStart(String[] args, String name);
|
||||
List getChildTests(Object description);
|
||||
|
||||
@@ -72,8 +72,8 @@ public class JUnitForkedStarter {
|
||||
String[] args,
|
||||
boolean isJUnit4,
|
||||
List listeners,
|
||||
String params, SegmentedOutputStream out,
|
||||
SegmentedOutputStream err,
|
||||
String params, Object out,
|
||||
Object err,
|
||||
String forkMode,
|
||||
String path) throws Exception {
|
||||
final List parameters = new ArrayList();
|
||||
@@ -178,8 +178,8 @@ public class JUnitForkedStarter {
|
||||
|
||||
private static int processChildren(boolean isJUnit4,
|
||||
List listeners,
|
||||
SegmentedOutputStream out,
|
||||
SegmentedOutputStream err,
|
||||
Object out,
|
||||
Object err,
|
||||
List parameters,
|
||||
IdeaTestRunner testRunner,
|
||||
List children,
|
||||
@@ -206,8 +206,8 @@ public class JUnitForkedStarter {
|
||||
|
||||
private static int runChild(boolean isJUnit4,
|
||||
List listeners,
|
||||
SegmentedOutputStream out,
|
||||
SegmentedOutputStream err,
|
||||
Object out,
|
||||
Object err,
|
||||
List parameters,
|
||||
String description,
|
||||
File workingDir,
|
||||
@@ -265,7 +265,9 @@ public class JUnitForkedStarter {
|
||||
|
||||
final Process exec = builder.createProcess();
|
||||
final int result = exec.waitFor();
|
||||
ForkedVMWrapper.readWrapped(testOutputPath, out.getPrintStream(), err.getPrintStream());
|
||||
ForkedVMWrapper.readWrapped(testOutputPath,
|
||||
JUnitStarter.SM_RUNNER ? ((PrintStream)out) : ((SegmentedOutputStream)out).getPrintStream(),
|
||||
JUnitStarter.SM_RUNNER ? ((PrintStream)err) : ((SegmentedOutputStream)err).getPrintStream());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,6 @@ public class JUnitStarter {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
SegmentedOutputStream out = new SegmentedOutputStream(System.out);
|
||||
SegmentedOutputStream err = new SegmentedOutputStream(System.err);
|
||||
Vector argList = new Vector();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
@@ -64,18 +62,16 @@ public class JUnitStarter {
|
||||
|
||||
boolean isJUnit4 = processParameters(argList, listeners, name);
|
||||
|
||||
if (!canWorkWithJUnitVersion(err, isJUnit4)) {
|
||||
err.flush();
|
||||
if (!canWorkWithJUnitVersion(System.err, isJUnit4)) {
|
||||
System.exit(-3);
|
||||
}
|
||||
if (!checkVersion(args, err)) {
|
||||
err.flush();
|
||||
if (!checkVersion(args, System.err)) {
|
||||
System.exit(-3);
|
||||
}
|
||||
|
||||
String[] array = new String[argList.size()];
|
||||
argList.copyInto(array);
|
||||
int exitCode = prepareStreamsAndStart(array, isJUnit4, listeners, name[0], out, err);
|
||||
int exitCode = prepareStreamsAndStart(array, isJUnit4, listeners, name[0]);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
|
||||
@@ -171,15 +167,14 @@ public class JUnitStarter {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkVersion(String[] args, SegmentedOutputStream notifications) {
|
||||
public static boolean checkVersion(String[] args, PrintStream printStream) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
if (arg.startsWith(IDE_VERSION)) {
|
||||
int ideVersion = Integer.parseInt(arg.substring(IDE_VERSION.length(), arg.length()));
|
||||
if (ideVersion != VERSION) {
|
||||
PrintStream stream = new PrintStream(notifications);
|
||||
stream.println("Wrong agent version: " + VERSION + ". IDE expects version: " + ideVersion);
|
||||
stream.flush();
|
||||
printStream.println("Wrong agent version: " + VERSION + ". IDE expects version: " + ideVersion);
|
||||
printStream.flush();
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
@@ -188,18 +183,17 @@ public class JUnitStarter {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean canWorkWithJUnitVersion(OutputStream notifications, boolean isJUnit4) {
|
||||
final PrintStream stream = new PrintStream(notifications);
|
||||
private static boolean canWorkWithJUnitVersion(PrintStream printStream, boolean isJUnit4) {
|
||||
try {
|
||||
junitVersionChecks(isJUnit4);
|
||||
} catch (Throwable e) {
|
||||
stream.println("!!! JUnit version 3.8 or later expected:");
|
||||
stream.println();
|
||||
e.printStackTrace(stream);
|
||||
stream.flush();
|
||||
printStream.println("!!! JUnit version 3.8 or later expected:");
|
||||
printStream.println();
|
||||
e.printStackTrace(printStream);
|
||||
printStream.flush();
|
||||
return false;
|
||||
} finally {
|
||||
stream.flush();
|
||||
printStream.flush();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -214,20 +208,22 @@ public class JUnitStarter {
|
||||
private static int prepareStreamsAndStart(String[] args,
|
||||
final boolean isJUnit4,
|
||||
ArrayList listeners,
|
||||
String name,
|
||||
SegmentedOutputStream out,
|
||||
SegmentedOutputStream err) {
|
||||
String name) {
|
||||
PrintStream oldOut = System.out;
|
||||
PrintStream oldErr = System.err;
|
||||
try {
|
||||
System.setOut(new PrintStream(out));
|
||||
System.setErr(new PrintStream(err));
|
||||
IdeaTestRunner testRunner = (IdeaTestRunner)getAgentClass(isJUnit4).newInstance();
|
||||
Object out = SM_RUNNER ? System.out : (Object)new SegmentedOutputStream(System.out);
|
||||
Object err = SM_RUNNER ? System.err : (Object)new SegmentedOutputStream(System.err);
|
||||
if (!SM_RUNNER) {
|
||||
System.setOut(new PrintStream((OutputStream)out));
|
||||
System.setErr(new PrintStream((OutputStream)err));
|
||||
}
|
||||
if (ourCommandFileName != null) {
|
||||
if (!"none".equals(ourForkMode) || ourWorkingDirs != null && new File(ourWorkingDirs).length() > 0) {
|
||||
return JUnitForkedStarter.startForkedVMs(ourWorkingDirs, args, isJUnit4, listeners, name, out, err, ourForkMode, ourCommandFileName);
|
||||
}
|
||||
}
|
||||
IdeaTestRunner testRunner = (IdeaTestRunner)getAgentClass(isJUnit4).newInstance();
|
||||
testRunner.setStreams(out, err, 0);
|
||||
return testRunner.startRunnerWithArgs(args, listeners, name, ourCount, !SM_RUNNER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user