diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index bb566a29b1d6..ec85b930c96a 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -581,7 +581,7 @@ public class SMTestProxy extends AbstractTestProxy { } public void addStdOutput(final String output, final Key outputType) { - addLast(new Printable() { + addAfterLastPassed(new Printable() { public void printOn(final Printer printer) { printer.print(output, ConsoleViewContentType.getConsoleViewType(outputType)); } @@ -589,7 +589,7 @@ public class SMTestProxy extends AbstractTestProxy { } public void addStdErr(final String output) { - addLast(new Printable() { + addAfterLastPassed(new Printable() { public void printOn(final Printer printer) { printer.print(output, ConsoleViewContentType.ERROR_OUTPUT); } @@ -615,7 +615,7 @@ public class SMTestProxy extends AbstractTestProxy { } setStacktraceIfNotSet(stackTrace); - addLast(new Printable() { + addAfterLastPassed(new Printable() { public void printOn(final Printer printer) { String errorText = TestFailedState.buildErrorPresentationText(output, stackTrace); LOG.assertTrue(errorText != null); @@ -634,7 +634,7 @@ public class SMTestProxy extends AbstractTestProxy { } public void addSystemOutput(final String output) { - addLast(new Printable() { + addAfterLastPassed(new Printable() { public void printOn(final Printer printer) { printer.print(output, ConsoleViewContentType.SYSTEM_OUTPUT); } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/OutputTest.kt b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/OutputTest.kt new file mode 100644 index 000000000000..dc66631ff6d9 --- /dev/null +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/OutputTest.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.testframework.sm.runner + +import com.intellij.execution.process.ProcessOutputTypes +import com.intellij.execution.testframework.sm.runner.ui.MockPrinter +import com.intellij.openapi.util.Disposer + +class OutputTest : BaseSMTRunnerTestCase() { + fun testBeforeAfterOrder() { + val suite = createTestProxy("parent") + val child = createTestProxy("child", suite) + + suite.addStdOutput("before test started\n", ProcessOutputTypes.STDOUT) + child.setStarted() + child.addStdOutput("inside test\n", ProcessOutputTypes.STDOUT) + child.setFinished() + suite.addStdOutput("after test finished\n", ProcessOutputTypes.STDOUT) + + val printer = MockPrinter(true) + suite.printOn(printer) + + assertEquals("before test started\ninside test\nafter test finished\n", printer.stdOut) + printer.resetIfNecessary() + + child.printOn(printer) + assertEquals("inside test\n", printer.stdOut) + } + + fun testBeforeAfterOrderWhenFlushed() { + val suite = createTestProxy("parent") + val child = createTestProxy("child", suite) + + try { + suite.addStdOutput("before test started\n", ProcessOutputTypes.STDOUT) + child.setStarted() + child.addStdOutput("inside test\n", ProcessOutputTypes.STDOUT) + child.setFinished() + suite.flush() + suite.addStdOutput("after test finished\n", ProcessOutputTypes.STDOUT) + + val printer = MockPrinter(true) + suite.printOn(printer) + + assertEquals("before test started\ninside test\nafter test finished\n", printer.stdOut) + printer.resetIfNecessary() + + child.printOn(printer) + assertEquals("inside test\n", printer.stdOut) + } + finally { + Disposer.dispose(child) + Disposer.dispose(suite) + } + } +} \ No newline at end of file diff --git a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java index c60de5c69027..10a283bd3292 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java @@ -148,7 +148,20 @@ public abstract class AbstractTestProxy extends CompositePrintable { final DiffHyperlink provider = getDiffViewerProvider(); return provider == null ? Collections.emptyList() : Collections.singletonList(provider); } - + + protected void addAfterLastPassed(Printable printable) { + int idx = 0; + synchronized (myNestedPrintables) { + for (Printable proxy : myNestedPrintables) { + if (proxy instanceof AbstractTestProxy && !((AbstractTestProxy)proxy).isPassed()) { + break; + } + idx++; + } + } + insert(printable, idx); + } + @Nullable public DiffHyperlink getDiffViewerProvider() { return null;