AbstractQuickFixTest: J2K

This commit is contained in:
Dmitry Jemerov
2017-03-23 17:07:05 +01:00
parent ad59a122ac
commit 34ad19a912
@@ -14,349 +14,315 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.idea.quickfix; package org.jetbrains.kotlin.idea.quickfix
import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.quickFix.ActionHint
import com.intellij.codeInsight.daemon.quickFix.ActionHint; import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase
import com.intellij.codeInsight.daemon.quickFix.QuickFixTestCase; import com.intellij.codeInsight.daemon.quickFix.QuickFixTestCase
import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.InspectionProfileEntry
import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.SuppressIntentionAction; import com.intellij.codeInspection.SuppressableProblemGroup
import com.intellij.codeInspection.SuppressableProblemGroup; import com.intellij.ide.startup.impl.StartupManagerImpl
import com.intellij.ide.startup.impl.StartupManagerImpl; import com.intellij.openapi.command.CommandProcessor
import com.intellij.lang.annotation.ProblemGroup; import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.CharsetToolkit
import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.stubs.StubUpdatingIndex
import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.rt.execution.junit.FileComparisonFailure
import com.intellij.psi.PsiElement; import com.intellij.testFramework.InspectionTestUtil
import com.intellij.psi.stubs.StubUpdatingIndex; import com.intellij.testFramework.LightPlatformCodeInsightTestCase
import com.intellij.rt.execution.junit.FileComparisonFailure; import com.intellij.testFramework.LightPlatformTestCase
import com.intellij.testFramework.InspectionTestUtil; import com.intellij.testFramework.UsefulTestCase
import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtil
import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.ObjectUtils.notNull
import kotlin.collections.CollectionsKt; import com.intellij.util.indexing.FileBasedIndex
import kotlin.io.FilesKt; import junit.framework.TestCase
import kotlin.jvm.functions.Function1; import org.apache.commons.lang.SystemUtils
import kotlin.text.StringsKt; import org.jetbrains.kotlin.idea.KotlinLightQuickFixTestCase
import org.apache.commons.lang.SystemUtils; import org.jetbrains.kotlin.idea.quickfix.utils.findInspectionFile
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
import org.jetbrains.kotlin.idea.KotlinLightQuickFixTestCase; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.idea.quickfix.utils.QuickfixTestUtilsKt; import org.jetbrains.kotlin.idea.test.TestFixtureExtension
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil; import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils; import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.idea.test.TestFixtureExtension; import org.junit.Assert
import org.jetbrains.kotlin.psi.KtFile; import java.io.File
import org.jetbrains.kotlin.test.InTextDirectivesUtils; import java.io.IOException
import org.jetbrains.kotlin.test.KotlinTestUtils; import java.nio.charset.Charset
import org.junit.Assert; import java.util.*
import java.io.File; abstract class AbstractQuickFixTest : KotlinLightQuickFixTestCase() {
import java.io.IOException; @Throws(Exception::class)
import java.nio.charset.Charset; override fun setUp() {
import java.util.Collections; super.setUp()
import java.util.HashSet; (StartupManager.getInstance(LightPlatformTestCase.getProject()) as StartupManagerImpl).runPostStartupActivities()
import java.util.List;
import java.util.Set;
import static com.intellij.util.ObjectUtils.notNull;
public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
((StartupManagerImpl) StartupManager.getInstance(getProject())).runPostStartupActivities();
} }
protected void doTest(@NotNull String beforeFileName) throws Exception { @Throws(Exception::class)
protected fun doTest(beforeFileName: String) {
try { try {
configureRuntimeIfNeeded(beforeFileName); configureRuntimeIfNeeded(beforeFileName)
enableInspections(beforeFileName); enableInspections(beforeFileName)
doSingleTest(getTestName(false) + ".kt"); doSingleTest(getTestName(false) + ".kt")
checkForUnexpectedErrors(); checkForUnexpectedErrors()
} }
finally { finally {
unConfigureRuntimeIfNeeded(beforeFileName); unConfigureRuntimeIfNeeded(beforeFileName)
} }
} }
//region Severe hack - lot of code copied from LightQuickFixTestCase to workaround stupid format of test data with before/after prefixes //region Severe hack - lot of code copied from LightQuickFixTestCase to workaround stupid format of test data with before/after prefixes
@Override override fun doSingleTest(fileSuffix: String) {
protected void doSingleTest(String fileSuffix) { doKotlinQuickFixTest(fileSuffix, createWrapper())
doKotlinQuickFixTest(fileSuffix, createWrapper());
} }
private static QuickFixTestCase myWrapper; override fun shouldBeAvailableAfterExecution(): Boolean {
return InTextDirectivesUtils.isDirectiveDefined(myWrapper!!.file.text, "// SHOULD_BE_AVAILABLE_AFTER_EXECUTION")
@Override
protected boolean shouldBeAvailableAfterExecution() {
return InTextDirectivesUtils.isDirectiveDefined(myWrapper.getFile().getText(), "// SHOULD_BE_AVAILABLE_AFTER_EXECUTION");
} }
@NotNull override fun configureLocalInspectionTools(): Array<LocalInspectionTool> {
@Override if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.configureLocalInspectionTools()
protected LocalInspectionTool[] configureLocalInspectionTools() {
if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.configureLocalInspectionTools();
String testRoot = KotlinTestUtils.getTestsRoot(this.getClass()); val testRoot = KotlinTestUtils.getTestsRoot(this.javaClass)
String configFileText = FilesKt.readText(new File(testRoot, getTestName(true) + ".kt"), Charset.defaultCharset()); val configFileText = File(testRoot, getTestName(true) + ".kt").readText(Charset.defaultCharset())
List<String> toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configFileText, "TOOL:"); val toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configFileText, "TOOL:")
if (toolsStrings.isEmpty()) return super.configureLocalInspectionTools(); if (toolsStrings.isEmpty()) return super.configureLocalInspectionTools()
return ArrayUtil.toObjectArray(CollectionsKt.map(toolsStrings, new Function1<String, LocalInspectionTool>() { return ArrayUtil.toObjectArray(toolsStrings.map { toolFqName ->
@Override try {
public LocalInspectionTool invoke(String toolFqName) { val aClass = Class.forName(toolFqName)
try { return@map aClass.newInstance() as LocalInspectionTool
Class<?> aClass = Class.forName(toolFqName); }
return (LocalInspectionTool) aClass.newInstance(); catch (e: Exception) {
throw IllegalArgumentException("Failed to create inspection for key '$toolFqName'", e)
}
}, LocalInspectionTool::class.java)
}
protected open fun configExtra(options: String) {
}
private fun doKotlinQuickFixTest(testName: String, quickFixTestCase: QuickFixTestCase) {
val relativePath = notNull(quickFixTestCase.basePath, "") + "/" + testName.decapitalize()
val testFullPath = quickFixTestCase.testDataPath.replace(File.separatorChar, '/') + relativePath
val testFile = File(testFullPath)
CommandProcessor.getInstance().executeCommand(quickFixTestCase.project, {
var fileText = ""
var expectedErrorMessage: String? = ""
var fixtureClasses = emptyList<String>()
try {
fileText = FileUtil.loadFile(testFile, CharsetToolkit.UTF8_CHARSET)
TestCase.assertTrue("\"<caret>\" is missing in file \"$testName\"", fileText.contains("<caret>"))
fixtureClasses = InTextDirectivesUtils.findListWithPrefixes(fileText, "// FIXTURE_CLASS: ")
for (fixtureClass in fixtureClasses) {
TestFixtureExtension.loadFixture(fixtureClass, LightPlatformTestCase.getModule())
} }
catch (Exception e) {
throw new IllegalArgumentException("Failed to create inspection for key '" + toolFqName + "'", e); expectedErrorMessage = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// SHOULD_FAIL_WITH: ")
val contents = StringUtil.convertLineSeparators(fileText)
quickFixTestCase.configureFromFileText(testFile.name, contents)
quickFixTestCase.bringRealEditorBack()
checkForUnexpectedActions()
configExtra(fileText)
applyAction(contents, quickFixTestCase, testName, testFullPath)
UsefulTestCase.assertEmpty(expectedErrorMessage)
}
catch (e: FileComparisonFailure) {
throw e
}
catch (e: AssertionError) {
throw e
}
catch (e: Throwable) {
if (expectedErrorMessage == null || expectedErrorMessage != e.message) {
e.printStackTrace()
TestCase.fail(testName)
} }
} }
}), LocalInspectionTool.class); finally {
} for (fixtureClass in fixtureClasses) {
TestFixtureExtension.unloadFixture(fixtureClass)
protected void configExtra(String options) {
}
private void doKotlinQuickFixTest(final String testName, final QuickFixTestCase quickFixTestCase) {
String relativePath = notNull(quickFixTestCase.getBasePath(), "") + "/" + StringsKt.decapitalize(testName);
final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath;
final File testFile = new File(testFullPath);
CommandProcessor.getInstance().executeCommand(quickFixTestCase.getProject(), new Runnable() {
@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod", "CallToPrintStackTrace"})
@Override
public void run() {
String fileText = "";
String expectedErrorMessage = "";
List<String> fixtureClasses = Collections.emptyList();
try {
fileText = FileUtil.loadFile(testFile, CharsetToolkit.UTF8_CHARSET);
assertTrue("\"<caret>\" is missing in file \"" + testName + "\"", fileText.contains("<caret>"));
fixtureClasses = InTextDirectivesUtils.findListWithPrefixes(fileText, "// FIXTURE_CLASS: ");
for (String fixtureClass : fixtureClasses) {
TestFixtureExtension.Companion.loadFixture(fixtureClass, getModule());
}
expectedErrorMessage = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// SHOULD_FAIL_WITH: ");
String contents = StringUtil.convertLineSeparators(fileText);
quickFixTestCase.configureFromFileText(testFile.getName(), contents);
quickFixTestCase.bringRealEditorBack();
checkForUnexpectedActions();
configExtra(fileText);
applyAction(contents, quickFixTestCase, testName, testFullPath);
assertEmpty(expectedErrorMessage);
}
catch (FileComparisonFailure e) {
throw e;
}
catch (AssertionError e) {
throw e;
}
catch (Throwable e) {
if (expectedErrorMessage == null || !expectedErrorMessage.equals(e.getMessage())) {
e.printStackTrace();
fail(testName);
}
}
finally {
for (String fixtureClass : fixtureClasses) {
TestFixtureExtension.Companion.unloadFixture(fixtureClass);
}
ConfigLibraryUtil.unconfigureLibrariesByDirective(getModule(), fileText);
} }
ConfigLibraryUtil.unconfigureLibrariesByDirective(LightPlatformTestCase.getModule(), fileText)
} }
}, "", ""); }, "", "")
} }
private static void applyAction(String contents, QuickFixTestCase quickFixTestCase, String testName, String testFullPath) @Throws(Exception::class)
throws Exception { override fun doAction(actionHint: ActionHint, testFullPath: String, testName: String) {
String fileName = StringsKt.substringAfterLast(testFullPath, "/", ""); LightQuickFixTestCase.doAction(actionHint, testFullPath, testName, myWrapper!!)
ActionHint actionHint = ActionHint.parse(quickFixTestCase.getFile(), contents.replace("${file}", fileName));
quickFixTestCase.beforeActionStarted(testName, contents);
try {
myWrapper = quickFixTestCase;
quickFixTestCase.doAction(actionHint, testFullPath, testName);
}
finally {
myWrapper = null;
quickFixTestCase.afterActionCompleted(testName, contents);
}
} }
@Override override fun checkResultByFile(message: String?, filePath: String, ignoreTrailingSpaces: Boolean) {
protected void doAction(ActionHint actionHint, String testFullPath, String testName) throws Exception { val file = File(filePath)
doAction(actionHint, testFullPath, testName, myWrapper); val afterFileName = file.name
assert(afterFileName.startsWith(LightQuickFixTestCase.AFTER_PREFIX))
val newAfterFileName = afterFileName.substring(LightQuickFixTestCase.AFTER_PREFIX.length).decapitalize() + ".after"
super.checkResultByFile(message, File(file.parent, newAfterFileName).path, ignoreTrailingSpaces)
} }
@Override @Throws(IOException::class)
protected void checkResultByFile(@Nullable String message, @NotNull String filePath, boolean ignoreTrailingSpaces) { private fun unConfigureRuntimeIfNeeded(beforeFileName: String) {
File file = new File(filePath);
String afterFileName = file.getName();
assert afterFileName.startsWith(AFTER_PREFIX);
String newAfterFileName = StringsKt.decapitalize(afterFileName.substring(AFTER_PREFIX.length())) + ".after";
super.checkResultByFile(message, new File(file.getParent(), newAfterFileName).getPath(), ignoreTrailingSpaces);
}
//endregion
private static void configureRuntimeIfNeeded(@NotNull String beforeFileName) throws IOException {
if (beforeFileName.endsWith("JsRuntime.kt")) { if (beforeFileName.endsWith("JsRuntime.kt")) {
// Without the following line of code subsequent tests with js-runtime will be prone to failure due "outdated stub in index" error. ConfigLibraryUtil.unConfigureKotlinJsRuntimeAndSdk(LightPlatformTestCase.getModule(), projectJDK)
FileBasedIndex.getInstance().requestRebuild(StubUpdatingIndex.INDEX_ID);
ConfigLibraryUtil.configureKotlinJsRuntimeAndSdk(getModule(), getFullJavaJDK());
} }
else if (isRuntimeNeeded(beforeFileName)) { else if (isRuntimeNeeded(beforeFileName)) {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(getModule(), getFullJavaJDK()); ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(LightPlatformTestCase.getModule(), projectJDK)
}
else if (beforeFileName.contains("Runtime") || beforeFileName.contains("JsRuntime")) {
Assert.fail("Runtime marker is used in test name, but not in test file end. " +
"This can lead to false-positive absent of actions");
} }
} }
private static boolean isRuntimeNeeded(@NotNull String beforeFileName) throws IOException { @Throws(IOException::class, ClassNotFoundException::class)
return beforeFileName.endsWith("Runtime.kt") || private fun enableInspections(beforeFileName: String) {
beforeFileName.toLowerCase().contains("createfromusage") || val inspectionFile = findInspectionFile(File(beforeFileName).parentFile)
InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(new File(beforeFileName)), "WITH_RUNTIME");
}
private void unConfigureRuntimeIfNeeded(@NotNull String beforeFileName) throws IOException {
if (beforeFileName.endsWith("JsRuntime.kt")) {
ConfigLibraryUtil.unConfigureKotlinJsRuntimeAndSdk(getModule(), getProjectJDK());
}
else if (isRuntimeNeeded(beforeFileName)) {
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(getModule(), getProjectJDK());
}
}
private void enableInspections(String beforeFileName) throws IOException, ClassNotFoundException {
File inspectionFile = QuickfixTestUtilsKt.findInspectionFile(new File(beforeFileName).getParentFile());
if (inspectionFile != null) { if (inspectionFile != null) {
String className = FileUtil.loadFile(inspectionFile).trim(); val className = FileUtil.loadFile(inspectionFile).trim { it <= ' ' }
Class<InspectionProfileEntry> inspectionClass = (Class<InspectionProfileEntry>) Class.forName(className); val inspectionClass = Class.forName(className) as Class<InspectionProfileEntry>
List<InspectionProfileEntry> tools = InspectionTestUtil.instantiateTools( val tools = InspectionTestUtil.instantiateTools(
Collections.<Class<? extends InspectionProfileEntry>>singletonList(inspectionClass)); listOf<Class<out InspectionProfileEntry>>(inspectionClass))
enableInspectionTools(tools.get(0)); enableInspectionTools(tools[0])
} }
} }
private void checkForUnexpectedActions() throws ClassNotFoundException { @Throws(ClassNotFoundException::class)
String text = getEditor().getDocument().getText(); private fun checkForUnexpectedActions() {
ActionHint actionHint = ActionHint.parse(getFile(), text); val text = LightPlatformCodeInsightTestCase.getEditor().getDocument().getText()
val actionHint = ActionHint.parse(LightPlatformCodeInsightTestCase.getFile(), text)
if (!actionHint.shouldPresent()) { if (!actionHint.shouldPresent()) {
List<IntentionAction> actions = getAvailableActions(); val actions = availableActions
String prefix = "class "; val prefix = "class "
if (actionHint.getExpectedText().startsWith(prefix)) { if (actionHint.expectedText.startsWith(prefix)) {
String className = actionHint.getExpectedText().substring(prefix.length()); val className = actionHint.expectedText.substring(prefix.length)
final Class<?> aClass = Class.forName(className); val aClass = Class.forName(className)
assert IntentionAction.class.isAssignableFrom(aClass) : className + " should be inheritor of IntentionAction"; assert(IntentionAction::class.java.isAssignableFrom(aClass)) { className + " should be inheritor of IntentionAction" }
final Set<String> validActions = val validActions = HashSet(InTextDirectivesUtils.findLinesWithPrefixesRemoved(text, "// ACTION:"))
new HashSet<String>(InTextDirectivesUtils.findLinesWithPrefixesRemoved(text, "// ACTION:"));
CollectionsKt.removeAll(actions, new Function1<IntentionAction, Boolean>() { actions.removeAll { action -> !aClass.isAssignableFrom(action.javaClass) || validActions.contains(action.text) }
@Override
public Boolean invoke(IntentionAction action) {
return !aClass.isAssignableFrom(action.getClass()) || validActions.contains(action.getText());
}
});
if (!actions.isEmpty()) { if (!actions.isEmpty()) {
Assert.fail("Unexpected intention actions present\n " + Assert.fail("Unexpected intention actions present\n " + actions.map { action -> action.javaClass.toString() + " " + action.toString() + "\n" }
CollectionsKt.map(actions, new Function1<IntentionAction, String>() { )
@Override
public String invoke(IntentionAction action) {
return action.getClass().toString() + " " + action.toString() + "\n";
}
})
);
} }
for (IntentionAction action : actions) { for (action in actions) {
if (aClass.isAssignableFrom(action.getClass()) && !validActions.contains(action.getText())) { if (aClass.isAssignableFrom(action.javaClass) && !validActions.contains(action.text)) {
Assert.fail("Unexpected intention action " + action.getClass() + " found"); Assert.fail("Unexpected intention action " + action.javaClass + " found")
} }
} }
} }
else { else {
// Action shouldn't be found. Check that other actions are expected and thus tested action isn't there under another name. // Action shouldn't be found. Check that other actions are expected and thus tested action isn't there under another name.
DirectiveBasedActionUtils.INSTANCE.checkAvailableActionsAreExpected(getFile(), actions); DirectiveBasedActionUtils.checkAvailableActionsAreExpected(LightPlatformCodeInsightTestCase.getFile(), actions)
} }
} }
} }
public static void checkForUnexpectedErrors() { override fun findActionWithText(text: String): IntentionAction? {
DirectiveBasedActionUtils.INSTANCE.checkForUnexpectedErrors((KtFile) getFile()); val intention = super.findActionWithText(text)
} if (intention != null) return intention
@Override
protected IntentionAction findActionWithText(String text) {
IntentionAction intention = super.findActionWithText(text);
if (intention != null) return intention;
// Support warning suppression // Support warning suppression
int caretOffset = myEditor.getCaretModel().getOffset(); val caretOffset = LightPlatformCodeInsightTestCase.myEditor.getCaretModel().getOffset()
for (HighlightInfo highlight : doHighlighting()) { for (highlight in doHighlighting()) {
if (highlight.startOffset <= caretOffset && caretOffset <= highlight.endOffset) { if (highlight.startOffset <= caretOffset && caretOffset <= highlight.endOffset) {
ProblemGroup group = highlight.getProblemGroup(); val group = highlight.problemGroup
if (group instanceof SuppressableProblemGroup) { if (group is SuppressableProblemGroup) {
SuppressableProblemGroup problemGroup = (SuppressableProblemGroup) group; val at = LightPlatformCodeInsightTestCase.getFile().findElementAt(highlight.actualStartOffset)
PsiElement at = getFile().findElementAt(highlight.getActualStartOffset()); val actions = group.getSuppressActions(at)
SuppressIntentionAction[] actions = problemGroup.getSuppressActions(at); for (action in actions) {
for (SuppressIntentionAction action : actions) { if (action.text == text) {
if (action.getText().equals(text)) { return action
return action;
} }
} }
} }
} }
} }
return null; return null
} }
@Override override fun checkResultByText(message: String?, fileText: String, ignoreTrailingSpaces: Boolean, filePath: String?) {
protected void checkResultByText(String message, @NotNull String fileText, boolean ignoreTrailingSpaces, String filePath) { super.checkResultByText(message, fileText, ignoreTrailingSpaces, File(filePath!!).absolutePath)
super.checkResultByText(message, fileText, ignoreTrailingSpaces, new File(filePath).getAbsolutePath());
} }
@Override override fun getBasePath(): String {
protected String getBasePath() { return KotlinTestUtils.getTestsRoot(javaClass)
return KotlinTestUtils.getTestsRoot(getClass());
} }
@NotNull override fun getTestDataPath(): String {
@Override return "./"
protected String getTestDataPath() {
return "./";
} }
@Override override fun getProjectJDK(): Sdk {
protected Sdk getProjectJDK() { return PluginTestCaseBase.mockJdk()
return PluginTestCaseBase.mockJdk();
} }
protected static Sdk getFullJavaJDK() { companion object {
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
private var myWrapper: QuickFixTestCase? = null
@Throws(Exception::class)
private fun applyAction(contents: String, quickFixTestCase: QuickFixTestCase, testName: String, testFullPath: String) {
val fileName = testFullPath.substringAfterLast("/", "")
val actionHint = ActionHint.parse(quickFixTestCase.file, contents.replace("\${file}", fileName))
quickFixTestCase.beforeActionStarted(testName, contents)
try {
myWrapper = quickFixTestCase
quickFixTestCase.doAction(actionHint, testFullPath, testName)
}
finally {
myWrapper = null
quickFixTestCase.afterActionCompleted(testName, contents)
}
}
//endregion
@Throws(IOException::class)
private fun configureRuntimeIfNeeded(beforeFileName: String) {
if (beforeFileName.endsWith("JsRuntime.kt")) {
// Without the following line of code subsequent tests with js-runtime will be prone to failure due "outdated stub in index" error.
FileBasedIndex.getInstance().requestRebuild(StubUpdatingIndex.INDEX_ID)
ConfigLibraryUtil.configureKotlinJsRuntimeAndSdk(LightPlatformTestCase.getModule(), fullJavaJDK)
}
else if (isRuntimeNeeded(beforeFileName)) {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(LightPlatformTestCase.getModule(), fullJavaJDK)
}
else if (beforeFileName.contains("Runtime") || beforeFileName.contains("JsRuntime")) {
Assert.fail("Runtime marker is used in test name, but not in test file end. " + "This can lead to false-positive absent of actions")
}
}
@Throws(IOException::class)
private fun isRuntimeNeeded(beforeFileName: String): Boolean {
return beforeFileName.endsWith("Runtime.kt") ||
beforeFileName.toLowerCase().contains("createfromusage") ||
InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(File(beforeFileName)), "WITH_RUNTIME")
}
fun checkForUnexpectedErrors() {
DirectiveBasedActionUtils.checkForUnexpectedErrors(LightPlatformCodeInsightTestCase.getFile() as KtFile)
}
protected val fullJavaJDK: Sdk
get() = JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().absolutePath)
} }
} }