Skip to content

Commit 4fac439

Browse files
committed
Print outputs in test fixture and implement client interface
1 parent e101a17 commit 4fac439

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

adapter/src/test/kotlin/org/javacs/ktda/DebugAdapterTestFixture.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ package org.javacs.ktda
33
import java.nio.file.Path
44
import java.nio.file.Paths
55
import org.eclipse.lsp4j.debug.DisconnectArguments
6+
import org.eclipse.lsp4j.debug.OutputEventArguments
7+
import org.eclipse.lsp4j.debug.services.IDebugProtocolClient
68
import org.javacs.ktda.adapter.KotlinDebugAdapter
79
import org.javacs.ktda.jdi.launch.JDILauncher
810
import org.junit.After
911

10-
abstract class DebugAdapterTestFixture(relativeWorkspaceRoot: String, mainClass: String) {
12+
abstract class DebugAdapterTestFixture(relativeWorkspaceRoot: String, mainClass: String) : IDebugProtocolClient {
1113
val absoluteWorkspaceRoot: Path = Paths.get(DebugAdapterTestFixture::class.java.getResource("/").toURI()).resolve(relativeWorkspaceRoot)
1214
val debugAdapter: KotlinDebugAdapter = JDILauncher()
1315
.let(::KotlinDebugAdapter)
16+
.also { it.connect(this) }
1417

1518
fun launch() {
1619
debugAdapter.launch(mapOf(
@@ -22,4 +25,8 @@ abstract class DebugAdapterTestFixture(relativeWorkspaceRoot: String, mainClass:
2225
@After fun closeDebugAdapter() {
2326
debugAdapter.disconnect(DisconnectArguments()).join()
2427
}
28+
29+
override fun output(args: OutputEventArguments) {
30+
println(args.output)
31+
}
2532
}

adapter/src/test/kotlin/org/javacs/ktda/SampleWorkspaceTest.kt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.eclipse.lsp4j.debug.StackFrame
88
import org.eclipse.lsp4j.debug.StackTraceArguments
99
import org.eclipse.lsp4j.debug.StoppedEventArguments
1010
import org.eclipse.lsp4j.debug.VariablesArguments
11-
import org.eclipse.lsp4j.debug.services.IDebugProtocolClient
1211
import org.junit.Assert.assertThat
1312
import org.junit.Test
1413
import org.hamcrest.Matchers.contains
@@ -20,33 +19,9 @@ import java.util.concurrent.Semaphore
2019
* using a sample application.
2120
*/
2221
class SampleWorkspaceTest : DebugAdapterTestFixture("sample-workspace", "sample.workspace.AppKt") {
23-
@Test fun testBreakpointsAndVariables() {
24-
val semaphore = Semaphore(0)
25-
26-
debugAdapter.connect(object : IDebugProtocolClient {
27-
override fun stopped(args: StoppedEventArguments) {
28-
assertThat(args.reason, equalTo("breakpoint"))
22+
private val semaphore = Semaphore(0)
2923

30-
// Query information about the debuggee's current state
31-
val stackTrace = debugAdapter.stackTrace(StackTraceArguments().apply {
32-
threadId = args.threadId
33-
}).join()
34-
val topFrame = stackTrace.stackFrames.first()
35-
val scopes = debugAdapter.scopes(ScopesArguments().apply {
36-
frameId = topFrame.id
37-
}).join()
38-
val scope = scopes.scopes.first()
39-
val variables = debugAdapter.variables(VariablesArguments().apply {
40-
variablesReference = scope.variablesReference
41-
}).join()
42-
43-
assertThat(variables.variables.map { Pair(it.name, it.value) }, contains(
44-
Pair("member", "\"test\""),
45-
Pair("local", "123")
46-
))
47-
semaphore.release()
48-
}
49-
})
24+
@Test fun testBreakpointsAndVariables() {
5025
debugAdapter.setBreakpoints(SetBreakpointsArguments().apply {
5126
source = Source().apply {
5227
path = absoluteWorkspaceRoot
@@ -65,4 +40,27 @@ class SampleWorkspaceTest : DebugAdapterTestFixture("sample-workspace", "sample.
6540
launch()
6641
semaphore.acquire() // Wait for the end
6742
}
43+
44+
override fun stopped(args: StoppedEventArguments) {
45+
assertThat(args.reason, equalTo("breakpoint"))
46+
47+
// Query information about the debuggee's current state
48+
val stackTrace = debugAdapter.stackTrace(StackTraceArguments().apply {
49+
threadId = args.threadId
50+
}).join()
51+
val topFrame = stackTrace.stackFrames.first()
52+
val scopes = debugAdapter.scopes(ScopesArguments().apply {
53+
frameId = topFrame.id
54+
}).join()
55+
val scope = scopes.scopes.first()
56+
val variables = debugAdapter.variables(VariablesArguments().apply {
57+
variablesReference = scope.variablesReference
58+
}).join()
59+
60+
assertThat(variables.variables.map { Pair(it.name, it.value) }, contains(
61+
Pair("member", "\"test\""),
62+
Pair("local", "123")
63+
))
64+
semaphore.release()
65+
}
6866
}

0 commit comments

Comments
 (0)