Debugger: Tests refactor

This commit is contained in:
Aleksandr Prokopyev
2019-10-15 11:39:27 +03:00
committed by Vladimir Ilmov
parent 12313fa5aa
commit 1dc44b4000
22 changed files with 472 additions and 1 deletions
@@ -56,7 +56,6 @@ import org.jetbrains.kotlin.idea.conversion.copy.AbstractLiteralTextToKotlinCopy
import org.jetbrains.kotlin.idea.conversion.copy.AbstractTextJavaToKotlinCopyPasteConversionTest
import org.jetbrains.kotlin.idea.coverage.AbstractKotlinCoverageOutputFilesTest
import org.jetbrains.kotlin.idea.debugger.*
import org.jetbrains.kotlin.idea.debugger.coroutines.AbstractCoroutineDumpTest
import org.jetbrains.kotlin.idea.debugger.evaluate.*
import org.jetbrains.kotlin.idea.debugger.test.sequence.exec.AbstractSequenceTraceTestCase
import org.jetbrains.kotlin.idea.debugger.test.*
@@ -227,6 +226,10 @@ fun main(args: Array<String>) {
model("asyncStackTrace")
}
testClass<AbstractCoroutineDumpTest> {
model("coroutines")
}
testClass<AbstractSequenceTraceTestCase> {
// TODO: implement mapping logic for terminal operations
model("sequence/streams/sequence", excludeDirs = listOf("terminal"))
@@ -0,0 +1,82 @@
/*
* 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
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl
import com.intellij.execution.configurations.JavaParameters
import com.intellij.execution.process.ProcessOutputTypes
import com.intellij.jarRepository.JarRepositoryManager
import com.intellij.jarRepository.RemoteRepositoryDescription
import org.jetbrains.idea.maven.aether.ArtifactKind
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor
import org.jetbrains.kotlin.idea.debugger.coroutines.CoroutineState
import org.jetbrains.kotlin.idea.debugger.coroutines.CoroutinesDebugProbesProxy
import org.jetbrains.kotlin.idea.debugger.evaluate.ExecutionContext
import org.jetbrains.kotlin.idea.debugger.test.preference.DebuggerPreferences
abstract class AbstractCoroutineDumpTest : KotlinDescriptorTestCaseWithStepping() {
override fun doMultiFileTest(files: TestFiles, preferences: DebuggerPreferences) {
doOnBreakpoint {
val evalContext = EvaluationContextImpl(this, frameProxy)
val execContext = ExecutionContext(evalContext, frameProxy ?: return@doOnBreakpoint)
val either = CoroutinesDebugProbesProxy.dumpCoroutines(execContext)
try {
if (either.isRight)
try {
val states = either.get()
print(stringDump(states), ProcessOutputTypes.SYSTEM)
} catch (ignored: Throwable) {
}
else
throw AssertionError("Dump failed", either.left)
} finally {
resume(this)
}
}
doOnBreakpoint {
val evalContext = EvaluationContextImpl(this, frameProxy)
val execContext = ExecutionContext(evalContext, frameProxy ?: return@doOnBreakpoint)
val either = CoroutinesDebugProbesProxy.dumpCoroutines(execContext)
try {
if (either.isRight)
try {
val states = either.get()
print(stringDump(states), ProcessOutputTypes.SYSTEM)
} catch (ignored: Throwable) {
}
else
throw AssertionError("Dump failed", either.left)
} finally {
resume(this)
}
}
}
private fun stringDump(states: List<CoroutineState>) = buildString {
states.forEach {
appendln("\"${it.name}\", state: ${it.state}")
}
}
override fun createJavaParameters(mainClass: String?): JavaParameters {
val description = JpsMavenRepositoryLibraryDescriptor("org.jetbrains.kotlinx", "kotlinx-coroutines-debug", "1.3.0")
val debugJar = JarRepositoryManager.loadDependenciesSync(
project, description, setOf(ArtifactKind.ARTIFACT),
RemoteRepositoryDescription.DEFAULT_REPOSITORIES, null
) ?: throw AssertionError("Debug Dependency is not found")
val params = super.createJavaParameters(mainClass)
for (jar in debugJar) {
params.classPath.add(jar.file.presentableUrl)
if (jar.file.name.contains("kotlinx-coroutines-debug"))
params.vmParametersList.add("-javaagent:${jar.file.presentableUrl}")
}
return params
}
}
@@ -0,0 +1,46 @@
/*
* 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;
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/jvm-debugger/jvm-debugger-test/testData/coroutines")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class CoroutineDumpTestGenerated extends AbstractCoroutineDumpTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInCoroutines() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/jvm-debugger/jvm-debugger-test/testData/coroutines"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("noCoroutines.kt")
public void testNoCoroutines() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/coroutines/noCoroutines.kt");
}
@TestMetadata("threeCoroutines.kt")
public void testThreeCoroutines() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/coroutines/threeCoroutines.kt");
}
@TestMetadata("twoDumps.kt")
public void testTwoDumps() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/coroutines/twoDumps.kt");
}
}
@@ -305,6 +305,21 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/kt31709.kt");
}
@TestMetadata("kt32691.kt")
public void testKt32691() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/kt32691.kt");
}
@TestMetadata("kt33093.kt")
public void testKt33093() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/kt33093.kt");
}
@TestMetadata("kt33181.kt")
public void testKt33181() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/kt33181.kt");
}
@TestMetadata("kt5554OnlyIntsShouldBeCoerced.kt")
public void testKt5554OnlyIntsShouldBeCoerced() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/kt5554OnlyIntsShouldBeCoerced.kt");
@@ -834,11 +849,21 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/frameLambda.kt");
}
@TestMetadata("frameLambdaNotAccessible.kt")
public void testFrameLambdaNotAccessible() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/frameLambdaNotAccessible.kt");
}
@TestMetadata("frameLambdaNotUsed.kt")
public void testFrameLambdaNotUsed() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/frameLambdaNotUsed.kt");
}
@TestMetadata("frameLambdaVariableFromCorrectFrame.kt")
public void testFrameLambdaVariableFromCorrectFrame() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/frameLambdaVariableFromCorrectFrame.kt");
}
@TestMetadata("frameLocalVariable.kt")
public void testFrameLocalVariable() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/frameLocalVariable.kt");
@@ -939,6 +964,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/nestedInlineFun2.kt");
}
@TestMetadata("nonCapturedThisInLambda.kt")
public void testNonCapturedThisInLambda() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/nonCapturedThisInLambda.kt");
}
@TestMetadata("remapThis.kt")
public void testRemapThis() throws Exception {
runTest("idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/frame/remapThis.kt");
@@ -0,0 +1,6 @@
package noCoroutines
fun main() {
//Breakpoint!
val s = "nothing to see here, folks"
}
@@ -0,0 +1,7 @@
LineBreakpoint created at noCoroutines.kt:5
Run Java
Connected to the target VM
noCoroutines.kt:5
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,13 @@
package threeCoroutines
import kotlin.random.Random
suspend fun main() {
sequence {
yield(239)
sequence {
//Breakpoint!
yield(666)
}.toList()
}.toList()
}
@@ -0,0 +1,10 @@
LineBreakpoint created at threeCoroutines.kt:10
Run Java
Connected to the target VM
threeCoroutines.kt:10
"coroutine#1", state: RUNNING
"coroutine#2", state: RUNNING
"coroutine#3", state: RUNNING
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,31 @@
package twoDumps
suspend fun main() {
foo()
sequence<Int> {
foo()
yield(666)
}.toList()
}
suspend fun foo() {
val f = 239
bar()
}
suspend fun bar() {
var r = 1337
//Breakpoint!
r += 42
}
suspend fun SequenceScope<Int>.foo() {
val k = 228
bar()
}
suspend fun SequenceScope<Int>.bar() {
var r = 1337
//Breakpoint!
r += 42
}
@@ -0,0 +1,12 @@
LineBreakpoint created at twoDumps.kt:19
LineBreakpoint created at twoDumps.kt:30
Run Java
Connected to the target VM
twoDumps.kt:19
"coroutine#1", state: RUNNING
twoDumps.kt:30
"coroutine#1", state: RUNNING
"coroutine#2", state: RUNNING
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,20 @@
package frameLambdaNotAccessible
fun main() {
val k = "lorem"
bar()()
}
fun bar(): () -> Unit {
val k = "ipsum"
return {
val l = "doloret"
//Breakpoint!
Unit
}
}
// PRINT_FRAME
// EXPRESSION: k
// RESULT: 'k' is not captured
@@ -0,0 +1,21 @@
LineBreakpoint created at frameLambdaNotAccessible.kt:13
Run Java
Connected to the target VM
frameLambdaNotAccessible.kt:13
Compile bytecode for k
frame = invoke:13, FrameLambdaNotAccessibleKt$bar$1 {frameLambdaNotAccessible}
this = this = {frameLambdaNotAccessible.FrameLambdaNotAccessibleKt$bar$1@uniqueID}Function0<kotlin.Unit>
field = arity: int = 0 (sp = Lambda.!EXT!)
local = l: java.lang.String = doloret (sp = frameLambdaNotAccessible.kt, 11)
field = value: char[] = {char[7]@uniqueID} (sp = String.!EXT!)
element = 0 = 'd' 100
element = 1 = 'o' 111
element = 2 = 'l' 108
element = 3 = 'o' 111
element = 4 = 'r' 114
element = 5 = 'e' 101
element = 6 = 't' 116
field = hash: int = 0 (sp = String.!EXT!)
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,27 @@
package frameLambdaVariableFromCorrectFrame
fun main() {
val k = "lorem"
foo {
val j = "ipsum"
{
val l = 5
//Breakpoint!
Unit
}()
}
}
fun foo(block: () -> Any?) {
val k = "doloret"
val j = "sit"
block()
}
// PRINT_FRAME
// EXPRESSION: k
// RESULT: "lorem": Ljava/lang/String;
// EXPRESSION: j
// RESULT: "ipsum": Ljava/lang/String;
@@ -0,0 +1,13 @@
LineBreakpoint created at frameLambdaVariableFromCorrectFrame.kt:10
Run Java
Connected to the target VM
frameLambdaVariableFromCorrectFrame.kt:10
Compile bytecode for k
Compile bytecode for j
frame = invoke:10, FrameLambdaVariableFromCorrectFrameKt$main$1$1 {frameLambdaVariableFromCorrectFrame}
this = this = {frameLambdaVariableFromCorrectFrame.FrameLambdaVariableFromCorrectFrameKt$main$1$1@uniqueID}Function0<kotlin.Unit>
field = arity: int = 0 (sp = Lambda.!EXT!)
local = l: int = 5 (sp = frameLambdaVariableFromCorrectFrame.kt, 8)
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,28 @@
package nonCapturedThisInLambda
fun main() {
Foo().bar()
}
class Foo {
val a = "lorem"
val b: String
get() = "ipsum"
fun bar() {
{
//Breakpoint!
Unit
}()
}
}
// PRINT_FRAME
// EXPRESSION: a
// RESULT: "lorem": Ljava/lang/String;
// EXPRESSION: b
// RESULT: "ipsum": Ljava/lang/String;
// EXPRESSION: this
// RESULT: instance of nonCapturedThisInLambda.Foo(id=ID): LnonCapturedThisInLambda/Foo;
@@ -0,0 +1,13 @@
LineBreakpoint created at nonCapturedThisInLambda.kt:14
Run Java
Connected to the target VM
nonCapturedThisInLambda.kt:14
Compile bytecode for a
Compile bytecode for b
Compile bytecode for this
frame = invoke:14, Foo$bar$1 {nonCapturedThisInLambda}
this = this = {nonCapturedThisInLambda.Foo$bar$1@uniqueID}Function0<kotlin.Unit>
field = arity: int = 0 (sp = Lambda.!EXT!)
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,24 @@
package kt32691
fun main() {
//Breakpoint!
Unit
}
class L<R, O>
// EXPRESSION: {}.toString()
// RESULT: "kotlin.jvm.functions.Function0<kotlin.Unit>": Ljava/lang/String;
// EXPRESSION: {i: Int -> }.toString()
// RESULT: "kotlin.jvm.functions.Function1<java.lang.Integer, kotlin.Unit>": Ljava/lang/String;
// EXPRESSION: {i: Int, d: Double -> "239" }.toString()
// RESULT: "kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.Double, java.lang.String>": Ljava/lang/String;
// EXPRESSION: {m : L<in String, out Int> -> ""}.toString()
// RESULT: "kotlin.jvm.functions.Function1<kt32691.L<in java.lang.String, out java.lang.Integer>, java.lang.String>": Ljava/lang/String;
@@ -0,0 +1,11 @@
LineBreakpoint created at kt32691.kt:5
Run Java
Connected to the target VM
kt32691.kt:5
Compile bytecode for {}.toString()
Compile bytecode for {i: Int -> }.toString()
Compile bytecode for {i: Int, d: Double -> "239" }.toString()
Compile bytecode for {m : L<in String, out Int> -> ""}.toString()
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,24 @@
package kt33093
typealias foo = Nothing
typealias bar = foo
fun main() {
//Breakpoint!
Unit
}
// EXPRESSION: Nothing()
// RESULT: Type 'Nothing' can't be instantiated
// EXPRESSION: foo()
// RESULT: Type 'Nothing' can't be instantiated
// EXPRESSION: bar()
// RESULT: Type 'Nothing' can't be instantiated
// EXPRESSION: { Nothing() }
// RESULT: Type 'Nothing' can't be instantiated
// EXPRESSION: { bar() }
// RESULT: Type 'Nothing' can't be instantiated
@@ -0,0 +1,8 @@
LineBreakpoint created at statements.kt:5
Run Java
Connected to the target VM
statements.kt:5
Compile bytecode for val b = 1
Disconnected from the target VM
Process finished with exit code 0
@@ -0,0 +1,33 @@
package kt33181
fun main() {
Bar().foo()
}
open class Foo {
open fun foo(): Int {
return 5
}
}
class Bar : Foo() {
override fun foo(): Int {
//Breakpoint!
return 6
}
}
// EXPRESSION: super.foo()
// RESULT: 5: I
// EXPRESSION: for (i in 1..1) { super.foo()}
// RESULT: VOID_VALUE
// EXPRESSION: { super.foo() }
// RESULT: Evaluation of 'super' calls inside lambdas and functions is not supported
// EXPRESSION: fun() { super.foo() }
// RESULT: Evaluation of 'super' calls inside lambdas and functions is not supported
// EXPRESSION: if(true) { fun named() { super.foo() } } // hack to avoid "Anonymous functions with names are prohibited"
// RESULT: Evaluation of 'super' calls inside lambdas and functions is not supported
@@ -0,0 +1,9 @@
LineBreakpoint created at kt33181.kt:16
Run Java
Connected to the target VM
kt33181.kt:16
Compile bytecode for super.foo()
Compile bytecode for for (i in 1..1) { super.foo()}
Disconnected from the target VM
Process finished with exit code 0