sm protocol: allow framework to provide file with output which ought to be shown for selected test only

This commit is contained in:
Anna Kozlova
2015-11-05 10:35:15 +01:00
parent 461686e8ae
commit 50d2a34fad
6 changed files with 39 additions and 3 deletions
@@ -17,11 +17,9 @@ package com.intellij.execution.testframework.sm.runner;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil;
import com.intellij.execution.testframework.sm.runner.events.*;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.util.containers.ContainerUtil;
@@ -29,7 +27,6 @@ import gnu.trove.TIntObjectHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set;
public class GeneralIdBasedToSMTRunnerEventsConvertor extends GeneralTestEventsProcessor {
@@ -196,6 +193,7 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor extends GeneralTestEventsP
if (node != null) {
SMTestProxy testProxy = node.getProxy();
testProxy.setDuration(testFinishedEvent.getDuration());
testProxy.setInputFilePath(testFinishedEvent.getOutputFile());
testProxy.setFinished();
fireOnTestFinished(testProxy);
terminateNode(node, State.FINISHED);
@@ -312,6 +312,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
}
testProxy.setDuration(duration);
testProxy.setInputFilePath(testFinishedEvent.getOutputFile());
testProxy.setFinished();
myRunningTestsFullNameToProxy.remove(fullTestName);
myCurrentChildren.remove(testProxy);
@@ -326,6 +326,7 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer
@NonNls private static final String ATTR_KEY_TEST_ERROR = "error";
@NonNls private static final String ATTR_KEY_TEST_COUNT = "count";
@NonNls private static final String ATTR_KEY_TEST_DURATION = "duration";
@NonNls private static final String ATTR_KEY_TEST_OUTPUT_FILE = "outputFile";
@NonNls private static final String ATTR_KEY_LOCATION_URL = "locationHint";
@NonNls private static final String ATTR_KEY_LOCATION_URL_OLD = "location";
@NonNls private static final String ATTR_KEY_STACKTRACE_DETAILS = "details";
@@ -410,6 +411,7 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer
}
TestFinishedEvent testFinishedEvent = new TestFinishedEvent(testFinished, duration);
testFinishedEvent.setOutputFile(testFinished.getAttributes().get(ATTR_KEY_TEST_OUTPUT_FILE));
fireOnTestFinished(testFinishedEvent);
}
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
public class TestFinishedEvent extends TreeNodeEvent {
private final long myDuration;
private String myOutputFile;
public TestFinishedEvent(@NotNull TestFinished testFinished, long duration) {
this(testFinished.getTestName(), TreeNodeEvent.getNodeId(testFinished), duration);
@@ -50,4 +51,12 @@ public class TestFinishedEvent extends TreeNodeEvent {
protected void appendToStringInfo(@NotNull StringBuilder buf) {
append(buf, "duration", myDuration);
}
public void setOutputFile(String outputFile) {
myOutputFile = outputFile;
}
public String getOutputFile() {
return myOutputFile;
}
}
@@ -40,6 +40,7 @@ public class CompositePrintable implements Printable, Disposable {
protected int myExceptionMark;
private int myCurrentSize = 0;
private String myOutputFile = null;
private String myInputFile;
private static final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD);
public void flush() {
@@ -133,6 +134,30 @@ public class CompositePrintable implements Printable, Disposable {
public void setOutputFilePath(String outputFile) {
myOutputFile = outputFile;
}
public void setInputFilePath(String inputFilePath) {
myInputFile = inputFilePath;
}
public void printFromInputFile(final Printer console) {
if (myInputFile != null) {
final Runnable runnable = new Runnable() {
public void run() {
final File inputFile = new File(myInputFile);
if (inputFile.exists()) {
try {
final String fileText = FileUtil.loadFile(inputFile);
console.print(fileText, ConsoleViewContentType.NORMAL_OUTPUT);
}
catch (IOException e) {
LOG.error(e);
}
}
}
};
invokeInAlarm(runnable);
}
}
private static final Logger LOG = Logger.getInstance("#" + PrintablesWrapper.class.getName());
@@ -110,6 +110,7 @@ public class TestsOutputConsolePrinter implements Printer, Disposable {
final AbstractTestProxy currentProxyOrRoot = getCurrentProxyOrRoot();
CompositePrintable.invokeInAlarm(clearRunnable);
currentProxyOrRoot.printOn(this);
currentProxyOrRoot.printFromInputFile(this);
CompositePrintable.invokeInAlarm(scrollRunnable);
}