From 50d2a34fad5f746d8b5bf4757108867c16642ea6 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 5 Nov 2015 10:32:13 +0100 Subject: [PATCH] sm protocol: allow framework to provide file with output which ought to be shown for selected test only --- ...eralIdBasedToSMTRunnerEventsConvertor.java | 4 +-- .../GeneralToSMTRunnerEventsConvertor.java | 1 + .../OutputToGeneralTestEventsConverter.java | 2 ++ .../sm/runner/events/TestFinishedEvent.java | 9 +++++++ .../testframework/CompositePrintable.java | 25 +++++++++++++++++++ .../ui/TestsOutputConsolePrinter.java | 1 + 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java index fee2f6f75e5b..be740b238b62 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java @@ -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); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java index e299d40eaf60..6ea423374474 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -312,6 +312,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso } testProxy.setDuration(duration); + testProxy.setInputFilePath(testFinishedEvent.getOutputFile()); testProxy.setFinished(); myRunningTestsFullNameToProxy.remove(fullTestName); myCurrentChildren.remove(testProxy); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java index c947d6feb3a4..2a7adbebb7f1 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java @@ -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); } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java index b63bccf1a379..e82b8d074061 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java @@ -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; + } } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java b/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java index fbb0602b7c32..a03f89d03c75 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java @@ -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()); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java index 535f2d454999..2134c6d20918 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java @@ -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); }