Skip to content

Commit 2cd26d7

Browse files
committed
Test member variables and ensure semaphore is always released
1 parent 27bbd43 commit 2cd26d7

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

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

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.junit.Assert.assertThat
1212
import org.junit.Test
1313
import org.hamcrest.Matchers.contains
1414
import org.hamcrest.Matchers.equalTo
15+
import org.hamcrest.Matchers.nullValue
16+
import org.hamcrest.Matchers.not
1517
import java.util.concurrent.Semaphore
1618

1719
/**
@@ -43,25 +45,33 @@ class SampleWorkspaceTest : DebugAdapterTestFixture("sample-workspace", "sample.
4345
}
4446

4547
override fun stopped(args: StoppedEventArguments) {
46-
assertThat(args.reason, equalTo("breakpoint"))
48+
try {
49+
assertThat(args.reason, equalTo("breakpoint"))
4750

48-
// Query information about the debuggee's current state
49-
val stackTrace = debugAdapter.stackTrace(StackTraceArguments().apply {
50-
threadId = args.threadId
51-
}).join()
52-
val topFrame = stackTrace.stackFrames.first()
53-
val scopes = debugAdapter.scopes(ScopesArguments().apply {
54-
frameId = topFrame.id
55-
}).join()
56-
val scope = scopes.scopes.first()
57-
val variables = debugAdapter.variables(VariablesArguments().apply {
58-
variablesReference = scope.variablesReference
59-
}).join()
60-
61-
assertThat(variables.variables.map { Pair(it.name, it.value) }, contains(
62-
Pair("member", "\"test\""),
63-
Pair("local", "123")
64-
))
65-
semaphore.release()
51+
// Query information about the debuggee's current state
52+
val stackTrace = debugAdapter.stackTrace(StackTraceArguments().apply {
53+
threadId = args.threadId
54+
}).join()
55+
val topFrame = stackTrace.stackFrames.first()
56+
val scopes = debugAdapter.scopes(ScopesArguments().apply {
57+
frameId = topFrame.id
58+
}).join()
59+
val scope = scopes.scopes.first()
60+
val variables = debugAdapter.variables(VariablesArguments().apply {
61+
variablesReference = scope.variablesReference
62+
}).join()
63+
val receiver = variables.variables.find { it.name == "this" }
64+
65+
assertThat(variables.variables.map { Pair(it.name, it.value) }, contains(Pair("local", "123")))
66+
assertThat(receiver, not(nullValue()))
67+
68+
val members = debugAdapter.variables(VariablesArguments().apply {
69+
variablesReference = receiver!!.variablesReference
70+
}).join()
71+
72+
assertThat(members.variables.map { Pair(it.name, it.value) }, contains(Pair("member", "test")))
73+
} finally {
74+
semaphore.release()
75+
}
6676
}
6777
}

adapter/src/test/resources/sample-workspace/src/main/kotlin/sample/workspace/App.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class App {
77
val local: Int = 123
88
return "Hello world."
99
}
10+
11+
override fun toString(): String = "App"
1012
}
1113

1214
fun main(args: Array<String>) {

0 commit comments

Comments
 (0)