From 5b94cf43cf5708a7390c6f82213c8efd22208580 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Fri, 5 May 2017 10:40:41 +0700 Subject: [PATCH] LightQuickFixTestCase: Improved failure reporting when action is not found --- .../quickFix/LightQuickFixTestCase.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java index a974441642d7..f2de06ab7005 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java @@ -17,14 +17,17 @@ package com.intellij.codeInsight.daemon.quickFix; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiUtil; import com.intellij.testFramework.LightPlatformCodeInsightTestCase; import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; @@ -32,6 +35,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.ObjectUtils; import com.intellij.util.ui.UIUtil; import junit.framework.ComparisonFailure; +import one.util.streamex.StreamEx; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.junit.Assert; @@ -99,7 +103,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase String testName, QuickFixTestCase quickFix) throws Exception { IntentionAction action = actionHint.findAndCheck(quickFix.getAvailableActions(), - () -> "Test: "+testFullPath+"\nInfos: "+quickFix.doHighlighting()); + () -> getTestInfo(testFullPath, quickFix)); if (action != null) { String text = action.getText(); quickFix.invoke(action); @@ -121,6 +125,29 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase } } + private static String getTestInfo(String testFullPath, QuickFixTestCase quickFix) { + String infos = StreamEx.of(quickFix.doHighlighting()) + .filter(info -> info.getSeverity() != HighlightInfoType.SYMBOL_TYPE_SEVERITY) + .map(info -> { + String fixes = ""; + if (info.quickFixActionRanges != null) { + fixes = StreamEx.of(info.quickFixActionRanges) + .map(p -> p.getSecond()+" "+p.getFirst()) + .mapLastOrElse("|- "::concat, "\\- "::concat) + .map(str -> " " + str + "\n") + .joining(); + } + return info.getSeverity() + + ": (" + info.getStartOffset() + "," + info.getEndOffset() + ") '" + + info.getText() + "': " + info.getDescription() + "\n" + fixes; + }) + .joining(" "); + return "Test: " + testFullPath + "\n" + + "Language level: " + PsiUtil.getLanguageLevel(getProject()) + "\n" + + "SDK: " + ModuleRootManager.getInstance(getModule()).getSdk() + "\n" + + "Infos: " + infos; + } + protected void doAction(@NotNull ActionHint actionHint, final String testFullPath, final String testName) throws Exception { doAction(actionHint, testFullPath, testName, myWrapper);