test runner: append output after last passed child (IDEA-160397)

This commit is contained in:
Anna Kozlova
2016-09-12 14:40:07 +03:00
parent 58ad02077e
commit f5262aa97c
3 changed files with 87 additions and 5 deletions
@@ -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);
}
@@ -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)
}
}
}
@@ -148,7 +148,20 @@ public abstract class AbstractTestProxy extends CompositePrintable {
final DiffHyperlink provider = getDiffViewerProvider();
return provider == null ? Collections.<DiffHyperlink>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;