FIR IDE: Add separate tests for FIR reference shortening

This commit is contained in:
Roman Golyshev
2020-12-21 15:23:05 +03:00
committed by Space
parent c1130f2010
commit b9d074051f
5 changed files with 119 additions and 0 deletions
@@ -180,6 +180,7 @@ import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverTest
import org.jetbrains.kotlin.search.AbstractAnnotatedMembersSearchTest
import org.jetbrains.kotlin.search.AbstractInheritorsSearchTest
import org.jetbrains.kotlin.shortenRefs.AbstractFirShortenRefsTest
import org.jetbrains.kotlin.shortenRefs.AbstractShortenRefsTest
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.tools.projectWizard.cli.AbstractProjectTemplateBuildFileGenerationTest
@@ -1117,6 +1118,10 @@ fun main(args: Array<String>) {
val pattern = "^([\\w\\-_]+)\\.(kt|kts)$"
model("intentions/specifyTypeExplicitly", pattern = pattern)
}
testClass<AbstractFirShortenRefsTest> {
model("shortenRefsFir", pattern = KT_WITHOUT_DOTS_IN_NAME, testMethod = "doTestWithMuting")
}
}
testGroup("idea/idea-fir/tests", "idea/idea-completion/testData") {
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.shortenRefs
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.kotlin.AbstractImportsTest
import org.jetbrains.kotlin.idea.frontend.api.analyze
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.uitls.IgnoreTests
abstract class AbstractFirShortenRefsTest : AbstractImportsTest() {
override val captureExceptions: Boolean = false
override fun doTest(file: KtFile): String? {
val selectionModel = myFixture.editor.selectionModel
if (!selectionModel.hasSelection()) error("No selection in input file")
val (startOffset, endOffset) = runReadAction { selectionModel.selectionStart to selectionModel.selectionEnd }
val shortenings = executeOnPooledThread {
runReadAction {
analyze(file) {
collectPossibleReferenceShortenings(file, startOffset, endOffset)
}
}
}
project.executeWriteCommand("") {
shortenings.invokeShortening()
}
selectionModel.removeSelection()
return null
}
override val runTestInWriteCommand: Boolean = false
protected fun doTestWithMuting(unused: String) {
IgnoreTests.runTestIfEnabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON, ".after") {
doTest(unused)
}
}
override val nameCountToUseStarImportDefault: Int
get() = Integer.MAX_VALUE
}
private fun <R> executeOnPooledThread(action: () -> R): R =
ApplicationManager.getApplication().executeOnPooledThread<R> { action() }.get()
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.shortenRefs;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/shortenRefsFir")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class FirShortenRefsTestGenerated extends AbstractFirShortenRefsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTestWithMuting, this, testDataFilePath);
}
public void testAllFilesPresentInShortenRefsFir() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/shortenRefsFir"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("idea/testData/shortenRefsFir/types")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Types extends AbstractFirShortenRefsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTestWithMuting, this, testDataFilePath);
}
public void testAllFilesPresentInTypes() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/shortenRefsFir/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("ParameterType.kt")
public void testParameterType() throws Exception {
runTest("idea/testData/shortenRefsFir/types/ParameterType.kt");
}
}
}
+6
View File
@@ -0,0 +1,6 @@
// FIR_COMPARISON
package test
class T
<selection>fun foo(t: test.T) {}</selection>
@@ -0,0 +1,6 @@
// FIR_COMPARISON
package test
class T
fun foo(t: T) {}