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);
|
||||
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<String> testFiles = new ArrayList<String>();
|
||||
testFiles.add(beforeFileName);
|
||||
KotlinPackage.mapTo(
|
||||
extraFiles,
|
||||
testFiles,
|
||||
new Function1<File, String>() {
|
||||
@Override
|
||||
public String invoke(File file) {
|
||||
return beforeFileName.replace(mainFileName, file.getName());
|
||||
List<String> testFiles = new ArrayList<String>();
|
||||
testFiles.add(beforeFileName);
|
||||
KotlinPackage.mapTo(
|
||||
extraFiles,
|
||||
testFiles,
|
||||
new Function1<File, String>() {
|
||||
@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<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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}, "", "");
|
||||
}
|
||||
finally {
|
||||
if (withRuntime) {
|
||||
ConfigLibraryUtil.unConfigureKotlinRuntime(myModule, PluginTestCaseBase.fullJdk());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
|
||||
+7
-1
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -100,30 +100,35 @@ class RunConfigurationTest: CodeInsightTestCase() {
|
||||
|
||||
ConfigLibraryUtil.configureKotlinRuntime(createModuleResult.module, PluginTestCaseBase.fullJdk())
|
||||
|
||||
val expectedClasses = ArrayList<String>()
|
||||
val actualClasses = ArrayList<String>()
|
||||
try {
|
||||
val expectedClasses = ArrayList<String>()
|
||||
val actualClasses = ArrayList<String>()
|
||||
|
||||
val testFile = PsiManager.getInstance(getTestProject()).findFile(srcDir.findFileByRelativePath("test.kt"))
|
||||
testFile.accept(
|
||||
object: JetTreeVisitorVoid() {
|
||||
override fun visitComment(comment: PsiComment) {
|
||||
val declaration = comment.getStrictParentOfType<JetNamedDeclaration>()!!
|
||||
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<JetNamedDeclaration>()!!
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user