Fix debugger tests compilation in 193 after the big refactoring
This commit is contained in:
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.idea.debugger.test.sequence
|
||||
|
||||
import com.intellij.debugger.streams.test.StreamChainBuilderTestCase
|
||||
import com.intellij.debugger.streams.wrapper.StreamChain
|
||||
import com.intellij.debugger.streams.wrapper.StreamChainBuilder
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.idea.caches.project.LibraryModificationTracker
|
||||
import org.jetbrains.kotlin.idea.debugger.test.DEBUGGER_TESTDATA_PATH_BASE
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
|
||||
abstract class KotlinPsiChainBuilderTestCase(private val relativePath: String) : StreamChainBuilderTestCase() {
|
||||
override fun getTestDataPath(): String = "$DEBUGGER_TESTDATA_PATH_BASE/sequence/psi/$relativeTestPath"
|
||||
|
||||
override fun getFileExtension(): String = ".kt"
|
||||
abstract val kotlinChainBuilder: StreamChainBuilder
|
||||
override fun getChainBuilder(): StreamChainBuilder = kotlinChainBuilder
|
||||
private val stdLibName = "kotlin-stdlib"
|
||||
|
||||
protected abstract fun doTest()
|
||||
|
||||
final override fun getRelativeTestPath(): String = relativePath
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
@Suppress("UnstableApiUsage")
|
||||
if (ProjectLibraryTable.getInstance(project).getLibraryByName(stdLibName) == null) {
|
||||
val stdLibPath = ForTestCompileRuntime.runtimeJarForTests()
|
||||
PsiTestUtil.addLibrary(
|
||||
testRootDisposable,
|
||||
module,
|
||||
stdLibName,
|
||||
stdLibPath.parent,
|
||||
stdLibPath.name
|
||||
)
|
||||
}
|
||||
}
|
||||
LibraryModificationTracker.getInstance(project).incModificationCount()
|
||||
}
|
||||
|
||||
|
||||
override fun getProjectJDK(): Sdk {
|
||||
return PluginTestCaseBase.mockJdk9()
|
||||
}
|
||||
|
||||
abstract class Positive(relativePath: String) : KotlinPsiChainBuilderTestCase(relativePath) {
|
||||
override fun doTest() {
|
||||
val chains = buildChains()
|
||||
checkChains(chains)
|
||||
}
|
||||
|
||||
private fun checkChains(chains: MutableList<StreamChain>) {
|
||||
TestCase.assertFalse(chains.isEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Negative(relativePath: String) : KotlinPsiChainBuilderTestCase(relativePath) {
|
||||
override fun doTest() {
|
||||
val elementAtCaret = configureAndGetElementAtCaret()
|
||||
TestCase.assertFalse(chainBuilder.isChainExists(elementAtCaret))
|
||||
TestCase.assertTrue(chainBuilder.build(elementAtCaret).isEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.idea.debugger
|
||||
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
import org.jetbrains.kotlin.idea.core.util.CodeInsightUtils
|
||||
import org.jetbrains.kotlin.idea.debugger.stepping.KotlinSmartStepIntoHandler
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
|
||||
abstract class AbstractSmartStepIntoTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
private val fixture: JavaCodeInsightTestFixture
|
||||
get() = myFixture
|
||||
|
||||
protected fun doTest(path: String) {
|
||||
fixture.configureByFile(fileName())
|
||||
|
||||
val offset = fixture.caretOffset
|
||||
val line = fixture.getDocument(fixture.file!!)!!.getLineNumber(offset)
|
||||
|
||||
val lineStart = CodeInsightUtils.getStartLineOffset(file, line)!!
|
||||
val elementAtOffset = file.findElementAt(lineStart)
|
||||
|
||||
val position = MockSourcePosition(_file = fixture.file,
|
||||
_line = line,
|
||||
_offset = offset,
|
||||
_editor = fixture.editor,
|
||||
_elementAt = elementAtOffset)
|
||||
|
||||
val actual = KotlinSmartStepIntoHandler().findSmartStepTargets(position).map { it.presentation }
|
||||
|
||||
val expected = InTextDirectivesUtils.findListWithPrefixes(fixture.file?.text!!.replace("\\,", "+++"), "// EXISTS: ").map { it.replace("+++", ",") }
|
||||
|
||||
for (actualTargetName in actual) {
|
||||
assert(actualTargetName in expected) {
|
||||
"Unexpected step into target was found: $actualTargetName\n${renderTableWithResults(expected, actual)}" +
|
||||
"\n // EXISTS: ${actual.joinToString()}"
|
||||
}
|
||||
}
|
||||
|
||||
for (expectedTargetName in expected) {
|
||||
assert(expectedTargetName in actual) {
|
||||
"Missed step into target: $expectedTargetName\n${renderTableWithResults(expected, actual)}" +
|
||||
"\n // EXISTS: ${actual.joinToString()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderTableWithResults(expected: List<String>, actual: List<String>): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
val maxExtStrSize = (expected.maxBy { it.length }?.length ?: 0) + 5
|
||||
val longerList = (if (expected.size < actual.size) actual else expected).sorted()
|
||||
val shorterList = (if (expected.size < actual.size) expected else actual).sorted()
|
||||
for ((i, element) in longerList.withIndex()) {
|
||||
sb.append(element)
|
||||
sb.append(" ".repeat(maxExtStrSize - element.length))
|
||||
if (i < shorterList.size) sb.append(shorterList[i])
|
||||
sb.append("\n")
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
override fun getTestDataPath(): String {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/debugger/smartStepInto"
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
Reference in New Issue
Block a user