Add test for KT-21710 (gutters inside library sources)
This commit is contained in:
@@ -551,6 +551,10 @@ fun main(args: Array<String>) {
|
||||
model("codeInsight/lineMarker")
|
||||
}
|
||||
|
||||
testClass<AbstractLineMarkersTestInLibrarySources> {
|
||||
model("codeInsightInLibrary/lineMarker", testMethod = "doTestWithLibrary")
|
||||
}
|
||||
|
||||
testClass<AbstractMultiModuleLineMarkerTest> {
|
||||
model("multiModuleLineMarker", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
@@ -549,6 +549,10 @@ fun main(args: Array<String>) {
|
||||
model("codeInsight/lineMarker")
|
||||
}
|
||||
|
||||
testClass<AbstractLineMarkersTestInLibrarySources> {
|
||||
model("codeInsightInLibrary/lineMarker", testMethod = "doTestWithLibrary")
|
||||
}
|
||||
|
||||
testClass<AbstractMultiModuleLineMarkerTest> {
|
||||
model("multiModuleLineMarker", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
@@ -547,6 +547,10 @@ fun main(args: Array<String>) {
|
||||
model("codeInsight/lineMarker")
|
||||
}
|
||||
|
||||
testClass<AbstractLineMarkersTestInLibrarySources> {
|
||||
model("codeInsightInLibrary/lineMarker", testMethod = "doTestWithLibrary")
|
||||
}
|
||||
|
||||
testClass<AbstractMultiModuleLineMarkerTest> {
|
||||
model("multiModuleLineMarker", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
@@ -547,6 +547,10 @@ fun main(args: Array<String>) {
|
||||
model("codeInsight/lineMarker")
|
||||
}
|
||||
|
||||
testClass<AbstractLineMarkersTestInLibrarySources> {
|
||||
model("codeInsightInLibrary/lineMarker", testMethod = "doTestWithLibrary")
|
||||
}
|
||||
|
||||
testClass<AbstractMultiModuleLineMarkerTest> {
|
||||
model("multiModuleLineMarker", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package library
|
||||
|
||||
interface <lineMarker descr="*">My</lineMarker> {
|
||||
fun <lineMarker descr="*">foo</lineMarker>(): Int
|
||||
|
||||
val <lineMarker descr="*">s</lineMarker>: String
|
||||
}
|
||||
|
||||
class Your : My {
|
||||
override fun <lineMarker descr="*">foo</lineMarker>(): Int {
|
||||
return 42
|
||||
}
|
||||
|
||||
override val <lineMarker descr="*">s</lineMarker>: String
|
||||
get() = ""
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun <lineMarker>main</lineMarker>(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.codeInsight
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure
|
||||
@@ -40,58 +41,63 @@ abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
|
||||
fun doTest(path: String) {
|
||||
fun doTest(path: String) = doTest(path) {}
|
||||
|
||||
protected fun doAndCheckHighlighting(
|
||||
documentToAnalyze: Document, expectedHighlighting: ExpectedHighlightingData, expectedFile: File
|
||||
): List<LineMarkerInfo<*>> {
|
||||
myFixture.doHighlighting()
|
||||
|
||||
val markers = DaemonCodeAnalyzerImpl.getLineMarkers(documentToAnalyze, myFixture.project)
|
||||
|
||||
try {
|
||||
expectedHighlighting.checkLineMarkers(markers, documentToAnalyze.text)
|
||||
|
||||
// This is a workaround for sad bug in ExpectedHighlightingData:
|
||||
// the latter doesn't throw assertion error when some line markers are expected, but none are present.
|
||||
if (FileUtil.loadFile(expectedFile).contains("<lineMarker") && markers.isEmpty()) {
|
||||
throw AssertionError("Some line markers are expected, but nothing is present at all")
|
||||
}
|
||||
} catch (error: AssertionError) {
|
||||
try {
|
||||
val actualTextWithTestData = TagsTestDataUtil.insertInfoTags(markers, true, myFixture.file.text)
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actualTextWithTestData)
|
||||
} catch (failure: FileComparisonFailure) {
|
||||
throw FileComparisonFailure(
|
||||
error.message + "\n" + failure.message,
|
||||
failure.expected,
|
||||
failure.actual,
|
||||
failure.filePath
|
||||
)
|
||||
}
|
||||
}
|
||||
return markers
|
||||
}
|
||||
|
||||
fun doTest(path: String, additionalCheck: () -> Unit) {
|
||||
val fileText = FileUtil.loadFile(File(path))
|
||||
try {
|
||||
ConfigLibraryUtil.configureLibrariesByDirective(myFixture.module, PlatformTestUtil.getCommunityPath(), fileText)
|
||||
if (InTextDirectivesUtils.findStringWithPrefixes(fileText,"METHOD_SEPARATORS") != null) {
|
||||
if (InTextDirectivesUtils.findStringWithPrefixes(fileText, "METHOD_SEPARATORS") != null) {
|
||||
DaemonCodeAnalyzerSettings.getInstance().SHOW_METHOD_SEPARATORS = true
|
||||
}
|
||||
|
||||
|
||||
myFixture.configureByFile(path)
|
||||
val project = myFixture.project
|
||||
val document = myFixture.editor.document
|
||||
|
||||
val data = ExpectedHighlightingData(
|
||||
document, false, false, false, myFixture.file)
|
||||
val data = ExpectedHighlightingData(document, false, false, false, myFixture.file)
|
||||
data.init()
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
|
||||
myFixture.doHighlighting()
|
||||
|
||||
val markers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project)
|
||||
|
||||
try {
|
||||
data.checkLineMarkers(markers, document.text)
|
||||
|
||||
// This is a workaround for sad bug in ExpectedHighlightingData:
|
||||
// the latter doesn't throw assertion error when some line markers are expected, but none are present.
|
||||
if (FileUtil.loadFile(File(path)).contains("<lineMarker") && markers.isEmpty()) {
|
||||
throw AssertionError("Some line markers are expected, but nothing is present at all")
|
||||
}
|
||||
}
|
||||
catch (error: AssertionError) {
|
||||
try {
|
||||
val actualTextWithTestData = TagsTestDataUtil.insertInfoTags(markers, true, myFixture.file.text)
|
||||
KotlinTestUtils.assertEqualsToFile(File(path), actualTextWithTestData)
|
||||
}
|
||||
catch (failure: FileComparisonFailure) {
|
||||
throw FileComparisonFailure(error.message + "\n" + failure.message,
|
||||
failure.expected,
|
||||
failure.actual,
|
||||
failure.filePath)
|
||||
}
|
||||
|
||||
}
|
||||
val markers = doAndCheckHighlighting(document, data, File(path))
|
||||
|
||||
assertNavigationElements(markers)
|
||||
}
|
||||
catch (exc: Exception) {
|
||||
additionalCheck()
|
||||
} catch (exc: Exception) {
|
||||
throw RuntimeException(exc)
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText)
|
||||
DaemonCodeAnalyzerSettings.getInstance().SHOW_METHOD_SEPARATORS = false
|
||||
}
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.idea.codeInsight
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.testFramework.ExpectedHighlightingData
|
||||
import com.intellij.util.io.createFile
|
||||
import com.intellij.util.io.write
|
||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
abstract class AbstractLineMarkersTestInLibrarySources : AbstractLineMarkersTest() {
|
||||
|
||||
private var libraryCleanPath: String? = null
|
||||
|
||||
private var libraryClean: File? = null
|
||||
|
||||
private fun getLibraryCleanPath(): String = libraryCleanPath!!
|
||||
|
||||
private fun getLibraryOriginalPath(): String = PluginTestCaseBase.getTestDataPathBase() + "/codeInsightInLibrary/_library"
|
||||
|
||||
override fun getProjectDescriptor(): SdkAndMockLibraryProjectDescriptor {
|
||||
if (libraryCleanPath == null) {
|
||||
val libraryClean = Files.createTempDirectory("lineMarkers_library")
|
||||
val libraryOriginal = File(getLibraryOriginalPath())
|
||||
libraryCleanPath = libraryClean.toString()
|
||||
|
||||
for (file in libraryOriginal.walkTopDown().filter { !it.isDirectory }) {
|
||||
val text = file.readText().replace("</?lineMarker.*?>".toRegex(), "")
|
||||
val cleanFile = libraryClean.resolve(file.relativeTo(libraryOriginal).path)
|
||||
cleanFile.createFile()
|
||||
cleanFile.write(text)
|
||||
}
|
||||
this.libraryClean = File(libraryCleanPath)
|
||||
}
|
||||
return object : SdkAndMockLibraryProjectDescriptor(getLibraryCleanPath(), false) {
|
||||
override fun configureModule(module: Module, model: ModifiableRootModel) {
|
||||
super.configureModule(module, model)
|
||||
|
||||
val library = model.moduleLibraryTable.getLibraryByName(SdkAndMockLibraryProjectDescriptor.LIBRARY_NAME)!!
|
||||
val modifiableModel = library.modifiableModel
|
||||
|
||||
modifiableModel.addRoot(LocalFileSystem.getInstance().findFileByIoFile(libraryClean!!)!!, OrderRootType.SOURCES)
|
||||
modifiableModel.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun doTestWithLibrary(path: String) {
|
||||
doTest(path) {
|
||||
val fileSystem = VirtualFileManager.getInstance().getFileSystem("file")
|
||||
val libraryOriginal = File(getLibraryOriginalPath())
|
||||
val project = myFixture.project
|
||||
for (file in libraryOriginal.walkTopDown().filter { !it.isDirectory }) {
|
||||
myFixture.openFileInEditor(fileSystem.findFileByPath(file.absolutePath)!!)
|
||||
val data = ExpectedHighlightingData(
|
||||
myFixture.editor.document, false, false, false, myFixture.file
|
||||
)
|
||||
data.init()
|
||||
|
||||
val librarySourceFile = libraryClean!!.resolve(file.relativeTo(libraryOriginal).path)
|
||||
myFixture.openFileInEditor(fileSystem.findFileByPath(librarySourceFile.absolutePath)!!)
|
||||
val document = myFixture.editor.document
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
|
||||
if (!ProjectRootsUtil.isLibrarySourceFile(project, myFixture.file.virtualFile)) {
|
||||
throw AssertionError("File ${myFixture.file.virtualFile.path} should be in library sources!")
|
||||
}
|
||||
|
||||
doAndCheckHighlighting(document, data, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
libraryClean?.deleteRecursively()
|
||||
ConfigLibraryUtil.removeLibrary(module, SdkAndMockLibraryProjectDescriptor.LIBRARY_NAME)
|
||||
|
||||
super.tearDown()
|
||||
}
|
||||
}
|
||||
Generated
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.idea.codeInsight;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
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/codeInsightInLibrary/lineMarker")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class LineMarkersTestInLibrarySourcesGenerated extends AbstractLineMarkersTestInLibrarySources {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTestWithLibrary, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInLineMarker() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsightInLibrary/lineMarker"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("dummy.kt")
|
||||
public void testDummy() throws Exception {
|
||||
runTest("idea/testData/codeInsightInLibrary/lineMarker/dummy.kt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user