diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/AbstractQuickFixMultiFileTest.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/AbstractQuickFixMultiFileTest.java index 06595062c54..6c20b25e980 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/AbstractQuickFixMultiFileTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/AbstractQuickFixMultiFileTest.java @@ -75,71 +75,79 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer File mainFile = new File(testDataPath + beforeFileName); final String originalFileText = FileUtil.loadFile(mainFile, true); - if (InTextDirectivesUtils.findStringWithPrefixes(originalFileText, "// WITH_RUNTIME") != null) { + boolean withRuntime = InTextDirectivesUtils.isDirectiveDefined(originalFileText, "// WITH_RUNTIME"); + if (withRuntime) { ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()); } - if (withExtraFile) { - File mainFileDir = mainFile.getParentFile(); - assert mainFileDir != null; + try { + if (withExtraFile) { + File mainFileDir = mainFile.getParentFile(); + assert mainFileDir != null; - final String mainFileName = mainFile.getName(); - final String extraFileNamePrefix = mainFileName.replace(".Main.kt", ".data.Sample."); - File[] extraFiles = mainFileDir.listFiles( - new FilenameFilter() { - @Override - public boolean accept(@NotNull File dir, @NotNull String name) { - return name.startsWith(extraFileNamePrefix); + final String mainFileName = mainFile.getName(); + final String extraFileNamePrefix = mainFileName.replace(".Main.kt", ".data.Sample."); + File[] extraFiles = mainFileDir.listFiles( + new FilenameFilter() { + @Override + public boolean accept(@NotNull File dir, @NotNull String name) { + return name.startsWith(extraFileNamePrefix); + } } - } - ); - assert extraFiles != null; + ); + assert extraFiles != null; - List testFiles = new ArrayList(); - testFiles.add(beforeFileName); - KotlinPackage.mapTo( - extraFiles, - testFiles, - new Function1() { - @Override - public String invoke(File file) { - return beforeFileName.replace(mainFileName, file.getName()); + List testFiles = new ArrayList(); + testFiles.add(beforeFileName); + KotlinPackage.mapTo( + extraFiles, + testFiles, + new Function1() { + @Override + public String invoke(File file) { + return beforeFileName.replace(mainFileName, file.getName()); + } } - } - ); + ); - configureByFiles(null, ArrayUtil.toStringArray(testFiles)); - } - else { - configureByFiles(null, beforeFileName); - } - - CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { - @Override - public void run() { - try { - PsiFile psiFile = getFile(); - - Pair pair = LightQuickFixTestCase.parseActionHint(psiFile, originalFileText); - String text = pair.getFirst(); - - boolean actionShouldBeAvailable = pair.getSecond(); - - if (psiFile instanceof JetFile) { - DirectiveBasedActionUtils.checkForUnexpectedErrors((JetFile) psiFile); - } - - doAction(text, actionShouldBeAvailable, beforeFileName); - } - catch (ComparisonFailure e) { - throw e; - } - catch (Throwable e) { - e.printStackTrace(); - fail(getTestName(true)); - } + configureByFiles(null, ArrayUtil.toStringArray(testFiles)); } - }, "", ""); + else { + configureByFiles(null, beforeFileName); + } + + CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { + @Override + public void run() { + try { + PsiFile psiFile = getFile(); + + Pair pair = LightQuickFixTestCase.parseActionHint(psiFile, originalFileText); + String text = pair.getFirst(); + + boolean actionShouldBeAvailable = pair.getSecond(); + + if (psiFile instanceof JetFile) { + DirectiveBasedActionUtils.checkForUnexpectedErrors((JetFile) psiFile); + } + + doAction(text, actionShouldBeAvailable, beforeFileName); + } + catch (ComparisonFailure e) { + throw e; + } + catch (Throwable e) { + e.printStackTrace(); + fail(getTestName(true)); + } + } + }, "", ""); + } + finally { + if (withRuntime) { + ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()); + } + } } @SuppressWarnings({"HardCodedStringLiteral"}) diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.kt b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.kt index 93025e4ca53..d801d388f2b 100644 --- a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.kt @@ -142,7 +142,8 @@ public abstract class AbstractJetExtractionTest() : JetLightCodeInsightFixtureTe val file = fixture.configureByFile(mainFile.getName()) as JetFile - if (InTextDirectivesUtils.findStringWithPrefixes(file.getText(), "// WITH_RUNTIME") != null) { + val addKotlinRuntime = InTextDirectivesUtils.findStringWithPrefixes(file.getText(), "// WITH_RUNTIME") != null + if (addKotlinRuntime) { ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()) } @@ -156,5 +157,10 @@ public abstract class AbstractJetExtractionTest() : JetLightCodeInsightFixtureTe val message = if (e is ConflictsInTestsException) e.getMessages().sort().joinToString(" ") else e.getMessage() JetTestUtils.assertEqualsToFile(conflictFile, message?.replace("\n", " ") ?: e.javaClass.getName()) } + finally { + if (addKotlinRuntime) { + ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()) + } + } } } diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt b/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt index 61803234180..72974c90453 100644 --- a/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt @@ -80,9 +80,6 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() { val config = JsonParser().parse(FileUtil.loadFile(File(path), true)) as JsonObject - if (config["withRuntime"]?.getAsBoolean() ?: false) { - ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()) - } val action = MoveAction.valueOf(config.getString("type")) @@ -90,6 +87,12 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() { val mainFilePath = config.getNullableString("mainFile")!! val conflictFile = File(testDir + "/conflicts.txt") + + val withRuntime = config["withRuntime"]?.getAsBoolean() ?: false + if (withRuntime) { + ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()) + } + doTest({ rootDir, rootAfter -> val mainFile = rootDir.findFileByRelativePath(mainFilePath)!! val mainPsiFile = PsiManager.getInstance(getProject()!!).findFile(mainFile)!! @@ -119,6 +122,10 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() { FileDocumentManager.getInstance().saveAllDocuments() EditorFactory.getInstance()!!.releaseEditor(editor) + + if (withRuntime) { + ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()) + } } }, getTestDirName(true)) diff --git a/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt b/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt index 7b706605572..e37933a4893 100644 --- a/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt @@ -100,30 +100,35 @@ class RunConfigurationTest: CodeInsightTestCase() { ConfigLibraryUtil.configureKotlinRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk()) - val expectedClasses = ArrayList() - val actualClasses = ArrayList() + try { + val expectedClasses = ArrayList() + val actualClasses = ArrayList() - val testFile = PsiManager.getInstance(getTestProject()).findFile(srcDir.findFileByRelativePath("test.kt")) - testFile.accept( - object: JetTreeVisitorVoid() { - override fun visitComment(comment: PsiComment) { - val declaration = comment.getStrictParentOfType()!! - val text = comment.getText() ?: return - if (!text.startsWith(RUN_PREFIX)) return + val testFile = PsiManager.getInstance(getTestProject()).findFile(srcDir.findFileByRelativePath("test.kt")) + testFile.accept( + object: JetTreeVisitorVoid() { + override fun visitComment(comment: PsiComment) { + val declaration = comment.getStrictParentOfType()!! + val text = comment.getText() ?: return + if (!text.startsWith(RUN_PREFIX)) return - expectedClasses.add(text.substring(RUN_PREFIX.length()).trim()) + expectedClasses.add(text.substring(RUN_PREFIX.length()).trim()) - val dataContext = MapDataContext() - dataContext.put(Location.DATA_KEY, PsiLocation(getTestProject(), declaration)) - val context = ConfigurationContext.getFromContext(dataContext) - val actualClass = (context?.getConfiguration()?.getConfiguration() as? JetRunConfiguration)?.getRunClass() - if (actualClass != null) { - actualClasses.add(actualClass) + val dataContext = MapDataContext() + dataContext.put(Location.DATA_KEY, PsiLocation(getTestProject(), declaration)) + val context = ConfigurationContext.getFromContext(dataContext) + val actualClass = (context?.getConfiguration()?.getConfiguration() as? JetRunConfiguration)?.getRunClass() + if (actualClass != null) { + actualClasses.add(actualClass) + } } } - } - ) - Assert.assertEquals(expectedClasses, actualClasses); + ) + Assert.assertEquals(expectedClasses, actualClasses) + } + finally { + ConfigLibraryUtil.unConfigureKotlinRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk()) + } } private fun createConfigurationFromMain(mainFqn: String): JetRunConfiguration { diff --git a/idea/tests/org/jetbrains/jet/psi/patternMatching/AbstractJetPsiUnifierTest.kt b/idea/tests/org/jetbrains/jet/psi/patternMatching/AbstractJetPsiUnifierTest.kt index 348070e576e..f72e1958957 100644 --- a/idea/tests/org/jetbrains/jet/psi/patternMatching/AbstractJetPsiUnifierTest.kt +++ b/idea/tests/org/jetbrains/jet/psi/patternMatching/AbstractJetPsiUnifierTest.kt @@ -52,19 +52,27 @@ public abstract class AbstractJetPsiUnifierTest: JetLightCodeInsightFixtureTestC myFixture.configureByFile(filePath) val file = myFixture.getFile() as JetFile - if (InTextDirectivesUtils.findStringWithPrefixes(file.getText(), "// WITH_RUNTIME") != null) { + val withRuntime = InTextDirectivesUtils.findStringWithPrefixes(file.getText(), "// WITH_RUNTIME") != null + if (withRuntime) { ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()) } - DirectiveBasedActionUtils.checkForUnexpectedErrors(file) + try { + DirectiveBasedActionUtils.checkForUnexpectedErrors(file) - val actualText = - findPattern(file) - .toRange() - .match(file, JetPsiUnifier.DEFAULT) - .map { it.range.getTextRange().substring(file.getText()!!) } - .joinToString("\n\n") - JetTestUtils.assertEqualsToFile(File("$filePath.match"), actualText) + val actualText = + findPattern(file) + .toRange() + .match(file, JetPsiUnifier.DEFAULT) + .map { it.range.getTextRange().substring(file.getText()!!) } + .joinToString("\n\n") + JetTestUtils.assertEqualsToFile(File("$filePath.match"), actualText) + } + finally { + if (withRuntime) { + ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk()) + } + } } override fun getProjectDescriptor(): LightProjectDescriptor = JetLightProjectDescriptor.INSTANCE