From 3d5c49977350cd0f52c9705be633c3a9f0e94597 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sun, 6 Sep 2015 02:03:52 +0300 Subject: [PATCH] Wrap test failure to FileComparisonFailure --- .../kotlin/idea/WordSelectionTest.java | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java index 26f6eaea0a0..fd812a74350 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java @@ -16,15 +16,23 @@ package org.jetbrains.kotlin.idea; +import com.intellij.openapi.editor.Caret; +import com.intellij.openapi.editor.Editor; +import com.intellij.rt.execution.junit.FileComparisonFailure; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.CodeInsightTestUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; +import org.jetbrains.kotlin.test.JetTestUtils; +import org.jetbrains.kotlin.test.TagsTestDataUtil; +import org.testng.collections.Lists; import java.io.File; public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase { + private static final String TEST_RELATIVE_DIR = "wordSelection"; + public void testStatements() { doTest(); } public void testWhenEntries() { doTest(); } @@ -74,7 +82,20 @@ public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase { afterFiles[i - 1] = dirName + File.separator + i + ".kt"; } - CodeInsightTestUtil.doWordSelectionTest(myFixture, dirName + File.separator + "0.kt", afterFiles); + try { + CodeInsightTestUtil.doWordSelectionTest(myFixture, dirName + File.separator + "0.kt", afterFiles); + } + catch (FileComparisonFailure error) { + wrapToFileComparisonFailure(error.getFilePath()); + } + catch (AssertionError error) { + String message = error.getMessage(); + String path = message.substring(0, message.indexOf(":")); + + String fullPath = new File(new File(PluginTestCaseBase.getTestDataPathBase(), TEST_RELATIVE_DIR), path).getPath(); + + wrapToFileComparisonFailure(fullPath); + } } @NotNull @@ -86,9 +107,26 @@ public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase { @Override public void setUp() { super.setUp(); - String testRelativeDir = "wordSelection"; - myFixture.setTestDataPath(new File(PluginTestCaseBase.getTestDataPathBase(), testRelativeDir).getPath() + + myFixture.setTestDataPath(new File(PluginTestCaseBase.getTestDataPathBase(), TEST_RELATIVE_DIR).getPath() + File.separator); } + private void wrapToFileComparisonFailure(String failedFilePath) { + Editor editor = myFixture.getEditor(); + + Caret caret = editor.getCaretModel().getCurrentCaret(); + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + String actualText = TagsTestDataUtil.insertTagsInText( + Lists.newArrayList( + new TagsTestDataUtil.TagInfo(caret.getOffset(), true, "caret"), + new TagsTestDataUtil.TagInfo(selectionStart, true, "selection"), + new TagsTestDataUtil.TagInfo(selectionEnd, false, "selection")), + editor.getDocument().getText() + ); + + JetTestUtils.assertEqualsToFile(new File(failedFilePath), actualText); + } + }