diff --git a/platform/testFramework/src/com/intellij/testFramework/FailedTestDebugLogConsoleFolding.java b/platform/testFramework/src/com/intellij/testFramework/FailedTestDebugLogConsoleFolding.java new file mode 100644 index 000000000000..a9517fe76b57 --- /dev/null +++ b/platform/testFramework/src/com/intellij/testFramework/FailedTestDebugLogConsoleFolding.java @@ -0,0 +1,32 @@ +/* + * 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.testFramework; + +import com.intellij.execution.ConsoleFolding; + +import java.util.List; + +public class FailedTestDebugLogConsoleFolding extends ConsoleFolding { + @Override + public boolean shouldFoldLine(String line) { + return line.indexOf(TestLoggerFactory.FAILED_TEST_DEBUG_OUTPUT_MARKER) != -1; + } + + @Override + public String getPlaceholderText(List lines) { + return " "; + } +} diff --git a/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java b/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java index 7f9752c9d06a..75f22b2e4e5f 100644 --- a/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java +++ b/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.openapi.util.text.StringUtil; import org.apache.log4j.*; import org.apache.log4j.spi.LoggingEvent; @@ -145,6 +146,8 @@ public class TestLoggerFactory implements Logger.Factory { private static final StringWriter STRING_WRITER = new StringWriter(); private static final StringBuffer BUFFER = STRING_WRITER.getBuffer(); + static final char FAILED_TEST_DEBUG_OUTPUT_MARKER = '\u2003'; + // inserted unicode whitespace to be able to tell these failed tests log lines from the others and fold them private static final WriterAppender APPENDER = new WriterAppender(new PatternLayout("%d{HH:mm:ss,SSS} %p %.30c - %m%n"), STRING_WRITER); private static final int MAX_BUFFER_LENGTH = 100000; private static final String CFQN = Category.class.getName(); @@ -165,8 +168,20 @@ public class TestLoggerFactory implements Logger.Factory { } public static void onTestFinished(boolean success) { - if (!success) { - System.err.println(BUFFER); + if (!success && BUFFER.length() != 0) { + if (UsefulTestCase.IS_UNDER_TEAMCITY) { + // print in one statement to avoid exception text cutting in between causing this fold to expand + BUFFER.insert(0, "##teamcity[blockOpened name='DEBUG log']\n"); + BUFFER.append( "\n##teamcity[blockClosed name='DEBUG log']\n"); + System.err.println(BUFFER); + } + else { + // mark each line in IDEA console with this hidden mark to be able to fold it automatically + String[] lines = LineTokenizer.tokenize(BUFFER, false, false); + String text = StringUtil.join(lines, FAILED_TEST_DEBUG_OUTPUT_MARKER + "\n"); + if (!text.startsWith("\n")) text = "\n" + text; + System.err.println(text); + } } BUFFER.setLength(0); } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 2e0249035038..4de90ce9f8e3 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -1244,6 +1244,7 @@ +