From c8eafbe32fc60e64e9c19a08bfd910b05516b0bc Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 10 Oct 2011 17:34:21 +0200 Subject: [PATCH] show expected FILE on the left of the diff view to be able to apply changes from actual right in the file --- .../daemon/GenericsHighlightingTest.java | 2 +- .../codeInsight/daemon/LossyEncodingTest.java | 6 ++--- .../intellij/psi/JavaSOEOnReparseTest.java | 8 +++---- .../daemon/LightDaemonAnalyzerTestCase.java | 18 +++++++++----- .../quickFix/LightQuickFixTestCase.java | 4 ++++ java/testFramework/testFramework-java.iml | 1 + .../ExpectedHighlightingData.java | 12 ++++++++-- .../LightPlatformCodeInsightTestCase.java | 24 +++++++++++++++---- platform/testFramework/testFramework.iml | 1 + 9 files changed, 56 insertions(+), 20 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 00fab84cb81c..d33381ec1e2e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -106,6 +106,6 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { collectionsClass = (PsiClass)collectionsClass.getNavigationElement(); final String text = collectionsClass.getContainingFile().getText(); configureFromFileText("Collections.java", text.replaceAll("\r","\n")); - doTestConfiguredFile(false, false); + doTestConfiguredFile(false, false, null); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java index 372377dedfdb..fec6cdb4e793 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java @@ -64,7 +64,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase { backspace(); backspace(); - doTestConfiguredFile(true, false); + doTestConfiguredFile(true, false, null); } public void testNativeConversion() throws Exception { configureFromFileText("x.properties","a=v"); @@ -99,7 +99,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase { configureByFile(BASE_PATH + "/" + "MultipleRanges.xml"); type("US-ASCII"); - doTestConfiguredFile(true, false); + doTestConfiguredFile(true, false, null); } private void doTest(@NonNls String filePath) throws Exception { @@ -110,7 +110,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase { EncodingManager.getInstance().setNative2AsciiForPropertiesFiles(null, true); configureByFile(BASE_PATH + "/" + "NativeEncoding.properties"); - doTestConfiguredFile(true, false); + doTestConfiguredFile(true, false, null); } public static final String THREE_NOTORIOUS_RUSSIAN_LETTERS = "\u0416\u041e\u041f"; diff --git a/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java b/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java index 39f8461a1eea..074f3e7108a9 100644 --- a/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java @@ -44,27 +44,27 @@ public class JavaSOEOnReparseTest extends LightDaemonAnalyzerTestCase { getEditor().getDocument().replaceString(pos, pos + 2, HUGE_EXPR); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); - doTestConfiguredFile(false, false); + doTestConfiguredFile(false, false, null); // modify huge binary expression (1) ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { getEditor().getDocument().insertString(pos, "\".\"+"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); - doTestConfiguredFile(false, false); + doTestConfiguredFile(false, false, null); // modify huge binary expression (2) ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { getEditor().getDocument().replaceString(pos, pos + 4, ""); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); - doTestConfiguredFile(false, false); + doTestConfiguredFile(false, false, null); // replace huge binary expression with small one ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { getEditor().getDocument().replaceString(pos, pos + HUGE_EXPR.length(), "\".\""); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); - doTestConfiguredFile(false, false); + doTestConfiguredFile(false, false, null); } } diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java index a0a7ea41e946..7556d7e86fe5 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java @@ -34,6 +34,7 @@ import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; @@ -75,17 +76,22 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) throws Exception { configureByFile(filePath); - doTestConfiguredFile(checkWarnings, checkInfos); + doTestConfiguredFile(checkWarnings, checkInfos, filePath); } - protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos) { + protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos, String filePath) { getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE); ExpectedHighlightingData data = new ExpectedHighlightingData(getEditor().getDocument(),checkWarnings, checkInfos); - checkHighlighting(data); + checkHighlighting(data, composeLocalPath(filePath)); } - private void checkHighlighting(ExpectedHighlightingData data) { + @Nullable + private String composeLocalPath(String filePath) { + return filePath != null ? getTestDataPath() + "/" + filePath : null; + } + + private void checkHighlighting(ExpectedHighlightingData data, String filePath) { data.init(); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); @@ -97,7 +103,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE); - data.checkResult(infos, getEditor().getDocument().getText()); + data.checkResult(infos, getEditor().getDocument().getText(), filePath); } protected HighlightTestInfo testFile(@NonNls @NotNull String filePath) { @@ -109,7 +115,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa ExpectedHighlightingData data = new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile); if (checkSymbolNames) data.checkSymbolNames(); - checkHighlighting(data); + checkHighlighting(data, composeLocalPath(path)); return this; } }; 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 7336a226228c..155c3110e9cf 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java @@ -30,6 +30,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; +import com.intellij.rt.execution.junit.FileComparisonFailure; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; import com.intellij.util.IncorrectOperationException; import com.intellij.util.ui.UIUtil; @@ -84,6 +85,9 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase quickFixTestCase.afterActionCompleted(testName, contents); } } + catch (FileComparisonFailure e){ + throw e; + } catch (Throwable e) { e.printStackTrace(); fail(testName); diff --git a/java/testFramework/testFramework-java.iml b/java/testFramework/testFramework-java.iml index edbdff617f45..e4af0e92164d 100644 --- a/java/testFramework/testFramework-java.iml +++ b/java/testFramework/testFramework-java.iml @@ -21,6 +21,7 @@ + diff --git a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java index b96c82b55a0a..4de9c541ab1d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java +++ b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java @@ -40,6 +40,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.rt.execution.junit.FileComparisonFailure; import com.intellij.util.ConstantFunction; import com.intellij.util.Function; import gnu.trove.THashMap; @@ -407,6 +408,10 @@ public class ExpectedHighlightingData { } public void checkResult(Collection infos, String text) { + checkResult(infos, text, null); + } + + public void checkResult(Collection infos, String text, String filePath) { String fileName = myFile == null ? "" : myFile.getName() + ": "; String failMessage = ""; @@ -460,11 +465,11 @@ public class ExpectedHighlightingData { } if (failMessage.length() > 0) { - compareTexts(infos, text, failMessage); + compareTexts(infos, text, failMessage, filePath); } } - private void compareTexts(Collection infos, String text, String failMessage) { + private void compareTexts(Collection infos, String text, String failMessage, String filePath) { final ArrayList list = new ArrayList(infos); Collections.sort(list, new Comparator() { // by start offset descending then by end offset ascending @Override @@ -513,6 +518,9 @@ public class ExpectedHighlightingData { } sb.insert(0, text.substring(0, end)); + if (filePath != null && !myText.equals(sb.toString())) { + throw new FileComparisonFailure(failMessage, myText, sb.toString(), filePath); + } Assert.assertEquals(failMessage + "\n", myText, sb.toString()); Assert.fail(failMessage); } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index d88cf3bc69b5..0b4920595f9b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -47,6 +47,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; +import com.intellij.rt.execution.junit.FileComparisonFailure; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -289,7 +290,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest } catch (IOException e) { LOG.error(e); } - checkResultByText(message, StringUtil.convertLineSeparators(fileText), ignoreTrailingSpaces); + checkResultByText(message, StringUtil.convertLineSeparators(fileText), ignoreTrailingSpaces, getTestDataPath() + "/" + filePath); } /** @@ -297,16 +298,26 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest * @param fileText */ protected void checkResultByText(@NonNls String fileText) { - checkResultByText(null, fileText, false); + checkResultByText(null, fileText, false, null); } + /** + * Same as checkResultByFile but text is provided directly. + * @param message - this check specific message. Added to text, caret position, selection checking. May be null + * @param fileText + * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing. + */ + protected void checkResultByText(final String message, final String fileText, final boolean ignoreTrailingSpaces) { + checkResultByText(message, fileText, ignoreTrailingSpaces, null); + } + /** * Same as checkResultByFile but text is provided directly. * @param message - this check specific message. Added to text, caret position, selection checking. May be null * @param fileText * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing. */ - protected void checkResultByText(final String message, final String fileText, final boolean ignoreTrailingSpaces) { + protected void checkResultByText(final String message, final String fileText, final boolean ignoreTrailingSpaces, final String filePath) { bringRealEditorBack(); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @@ -346,7 +357,12 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest String newFileText = document.getText(); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); - assertEquals(getMessage("Text mismatch", message), newFileText, myFile.getText()); + String fileText = myFile.getText(); + String failMessage = getMessage("Text mismatch", message); + if (filePath != null && !newFileText.equals(fileText)) { + throw new FileComparisonFailure(failMessage, newFileText, fileText, filePath); + } + assertEquals(failMessage, newFileText, fileText); checkCaretPosition(caretMarker, newFileText, message); checkSelection(selStartMarker, selEndMarker, newFileText, message); diff --git a/platform/testFramework/testFramework.iml b/platform/testFramework/testFramework.iml index bb333c9365c4..eb4b5e6ae14a 100644 --- a/platform/testFramework/testFramework.iml +++ b/platform/testFramework/testFramework.iml @@ -24,6 +24,7 @@ +