Unconfigure runtime to avoid affecting further tests
This commit is contained in:
@@ -75,71 +75,79 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer
|
|||||||
File mainFile = new File(testDataPath + beforeFileName);
|
File mainFile = new File(testDataPath + beforeFileName);
|
||||||
final String originalFileText = FileUtil.loadFile(mainFile, true);
|
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());
|
ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withExtraFile) {
|
try {
|
||||||
File mainFileDir = mainFile.getParentFile();
|
if (withExtraFile) {
|
||||||
assert mainFileDir != null;
|
File mainFileDir = mainFile.getParentFile();
|
||||||
|
assert mainFileDir != null;
|
||||||
|
|
||||||
final String mainFileName = mainFile.getName();
|
final String mainFileName = mainFile.getName();
|
||||||
final String extraFileNamePrefix = mainFileName.replace(".Main.kt", ".data.Sample.");
|
final String extraFileNamePrefix = mainFileName.replace(".Main.kt", ".data.Sample.");
|
||||||
File[] extraFiles = mainFileDir.listFiles(
|
File[] extraFiles = mainFileDir.listFiles(
|
||||||
new FilenameFilter() {
|
new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(@NotNull File dir, @NotNull String name) {
|
public boolean accept(@NotNull File dir, @NotNull String name) {
|
||||||
return name.startsWith(extraFileNamePrefix);
|
return name.startsWith(extraFileNamePrefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
assert extraFiles != null;
|
||||||
assert extraFiles != null;
|
|
||||||
|
|
||||||
List<String> testFiles = new ArrayList<String>();
|
List<String> testFiles = new ArrayList<String>();
|
||||||
testFiles.add(beforeFileName);
|
testFiles.add(beforeFileName);
|
||||||
KotlinPackage.mapTo(
|
KotlinPackage.mapTo(
|
||||||
extraFiles,
|
extraFiles,
|
||||||
testFiles,
|
testFiles,
|
||||||
new Function1<File, String>() {
|
new Function1<File, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String invoke(File file) {
|
public String invoke(File file) {
|
||||||
return beforeFileName.replace(mainFileName, file.getName());
|
return beforeFileName.replace(mainFileName, file.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
|
|
||||||
configureByFiles(null, ArrayUtil.toStringArray(testFiles));
|
configureByFiles(null, ArrayUtil.toStringArray(testFiles));
|
||||||
}
|
|
||||||
else {
|
|
||||||
configureByFiles(null, beforeFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
PsiFile psiFile = getFile();
|
|
||||||
|
|
||||||
Pair<String, Boolean> 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, "", "");
|
else {
|
||||||
|
configureByFiles(null, beforeFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
PsiFile psiFile = getFile();
|
||||||
|
|
||||||
|
Pair<String, Boolean> 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"})
|
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||||
|
|||||||
+7
-1
@@ -142,7 +142,8 @@ public abstract class AbstractJetExtractionTest() : JetLightCodeInsightFixtureTe
|
|||||||
|
|
||||||
val file = fixture.configureByFile(mainFile.getName()) as JetFile
|
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())
|
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()
|
val message = if (e is ConflictsInTestsException) e.getMessages().sort().joinToString(" ") else e.getMessage()
|
||||||
JetTestUtils.assertEqualsToFile(conflictFile, message?.replace("\n", " ") ?: e.javaClass.getName())
|
JetTestUtils.assertEqualsToFile(conflictFile, message?.replace("\n", " ") ?: e.javaClass.getName())
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if (addKotlinRuntime) {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,9 +80,6 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() {
|
|||||||
|
|
||||||
val config = JsonParser().parse(FileUtil.loadFile(File(path), true)) as JsonObject
|
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"))
|
val action = MoveAction.valueOf(config.getString("type"))
|
||||||
|
|
||||||
@@ -90,6 +87,12 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() {
|
|||||||
val mainFilePath = config.getNullableString("mainFile")!!
|
val mainFilePath = config.getNullableString("mainFile")!!
|
||||||
|
|
||||||
val conflictFile = File(testDir + "/conflicts.txt")
|
val conflictFile = File(testDir + "/conflicts.txt")
|
||||||
|
|
||||||
|
val withRuntime = config["withRuntime"]?.getAsBoolean() ?: false
|
||||||
|
if (withRuntime) {
|
||||||
|
ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk())
|
||||||
|
}
|
||||||
|
|
||||||
doTest({ rootDir, rootAfter ->
|
doTest({ rootDir, rootAfter ->
|
||||||
val mainFile = rootDir.findFileByRelativePath(mainFilePath)!!
|
val mainFile = rootDir.findFileByRelativePath(mainFilePath)!!
|
||||||
val mainPsiFile = PsiManager.getInstance(getProject()!!).findFile(mainFile)!!
|
val mainPsiFile = PsiManager.getInstance(getProject()!!).findFile(mainFile)!!
|
||||||
@@ -119,6 +122,10 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() {
|
|||||||
FileDocumentManager.getInstance().saveAllDocuments()
|
FileDocumentManager.getInstance().saveAllDocuments()
|
||||||
|
|
||||||
EditorFactory.getInstance()!!.releaseEditor(editor)
|
EditorFactory.getInstance()!!.releaseEditor(editor)
|
||||||
|
|
||||||
|
if (withRuntime) {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getTestDirName(true))
|
getTestDirName(true))
|
||||||
|
|||||||
@@ -100,30 +100,35 @@ class RunConfigurationTest: CodeInsightTestCase() {
|
|||||||
|
|
||||||
ConfigLibraryUtil.configureKotlinRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk())
|
ConfigLibraryUtil.configureKotlinRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk())
|
||||||
|
|
||||||
val expectedClasses = ArrayList<String>()
|
try {
|
||||||
val actualClasses = ArrayList<String>()
|
val expectedClasses = ArrayList<String>()
|
||||||
|
val actualClasses = ArrayList<String>()
|
||||||
|
|
||||||
val testFile = PsiManager.getInstance(getTestProject()).findFile(srcDir.findFileByRelativePath("test.kt"))
|
val testFile = PsiManager.getInstance(getTestProject()).findFile(srcDir.findFileByRelativePath("test.kt"))
|
||||||
testFile.accept(
|
testFile.accept(
|
||||||
object: JetTreeVisitorVoid() {
|
object: JetTreeVisitorVoid() {
|
||||||
override fun visitComment(comment: PsiComment) {
|
override fun visitComment(comment: PsiComment) {
|
||||||
val declaration = comment.getStrictParentOfType<JetNamedDeclaration>()!!
|
val declaration = comment.getStrictParentOfType<JetNamedDeclaration>()!!
|
||||||
val text = comment.getText() ?: return
|
val text = comment.getText() ?: return
|
||||||
if (!text.startsWith(RUN_PREFIX)) 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()
|
val dataContext = MapDataContext()
|
||||||
dataContext.put(Location.DATA_KEY, PsiLocation(getTestProject(), declaration))
|
dataContext.put(Location.DATA_KEY, PsiLocation(getTestProject(), declaration))
|
||||||
val context = ConfigurationContext.getFromContext(dataContext)
|
val context = ConfigurationContext.getFromContext(dataContext)
|
||||||
val actualClass = (context?.getConfiguration()?.getConfiguration() as? JetRunConfiguration)?.getRunClass()
|
val actualClass = (context?.getConfiguration()?.getConfiguration() as? JetRunConfiguration)?.getRunClass()
|
||||||
if (actualClass != null) {
|
if (actualClass != null) {
|
||||||
actualClasses.add(actualClass)
|
actualClasses.add(actualClass)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
Assert.assertEquals(expectedClasses, actualClasses)
|
||||||
Assert.assertEquals(expectedClasses, actualClasses);
|
}
|
||||||
|
finally {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createConfigurationFromMain(mainFqn: String): JetRunConfiguration {
|
private fun createConfigurationFromMain(mainFqn: String): JetRunConfiguration {
|
||||||
|
|||||||
@@ -52,19 +52,27 @@ public abstract class AbstractJetPsiUnifierTest: JetLightCodeInsightFixtureTestC
|
|||||||
myFixture.configureByFile(filePath)
|
myFixture.configureByFile(filePath)
|
||||||
val file = myFixture.getFile() as JetFile
|
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())
|
ConfigLibraryUtil.configureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk())
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file)
|
try {
|
||||||
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(file)
|
||||||
|
|
||||||
val actualText =
|
val actualText =
|
||||||
findPattern(file)
|
findPattern(file)
|
||||||
.toRange()
|
.toRange()
|
||||||
.match(file, JetPsiUnifier.DEFAULT)
|
.match(file, JetPsiUnifier.DEFAULT)
|
||||||
.map { it.range.getTextRange().substring(file.getText()!!) }
|
.map { it.range.getTextRange().substring(file.getText()!!) }
|
||||||
.joinToString("\n\n")
|
.joinToString("\n\n")
|
||||||
JetTestUtils.assertEqualsToFile(File("$filePath.match"), actualText)
|
JetTestUtils.assertEqualsToFile(File("$filePath.match"), actualText)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (withRuntime) {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getProjectDescriptor(): LightProjectDescriptor = JetLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor(): LightProjectDescriptor = JetLightProjectDescriptor.INSTANCE
|
||||||
|
|||||||
Reference in New Issue
Block a user