Skip to content

Commit e101a17

Browse files
committed
Fix private methods and synchronize stop event
1 parent 145c9ec commit e101a17

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import java.nio.file.Paths
55
import org.eclipse.lsp4j.debug.DisconnectArguments
66
import org.javacs.ktda.adapter.KotlinDebugAdapter
77
import org.javacs.ktda.jdi.launch.JDILauncher
8-
import org.junit.AfterClass
8+
import org.junit.After
99

10-
abstract class DebugAdapterTestFixture(relativeWorkspaceRoot: String) {
10+
abstract class DebugAdapterTestFixture(relativeWorkspaceRoot: String, mainClass: String) {
1111
val absoluteWorkspaceRoot: Path = Paths.get(DebugAdapterTestFixture::class.java.getResource("/").toURI()).resolve(relativeWorkspaceRoot)
1212
val debugAdapter: KotlinDebugAdapter = JDILauncher()
1313
.let(::KotlinDebugAdapter)
14-
.also { it.launch(mapOf(
14+
15+
fun launch() {
16+
debugAdapter.launch(mapOf(
1517
"projectRoot" to absoluteWorkspaceRoot.toString(),
1618
"mainClass" to "sample.workspace.AppKt"
17-
)) }
19+
))
20+
}
1821

19-
@AfterClass private fun closeDebugAdapter() {
22+
@After fun closeDebugAdapter() {
2023
debugAdapter.disconnect(DisconnectArguments()).join()
2124
}
2225
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ import org.junit.Assert.assertThat
1313
import org.junit.Test
1414
import org.hamcrest.Matchers.contains
1515
import org.hamcrest.Matchers.equalTo
16+
import java.util.concurrent.Semaphore
1617

1718
/**
1819
* Tests a very basic debugging scenario
1920
* using a sample application.
2021
*/
21-
class SampleWorkspaceTest : DebugAdapterTestFixture("sample-workspace") {
22-
@Test private fun testBreakpointsAndVariables() {
22+
class SampleWorkspaceTest : DebugAdapterTestFixture("sample-workspace", "sample.workspace.AppKt") {
23+
@Test fun testBreakpointsAndVariables() {
24+
val semaphore = Semaphore(0)
25+
2326
debugAdapter.connect(object : IDebugProtocolClient {
2427
override fun stopped(args: StoppedEventArguments) {
2528
assertThat(args.reason, equalTo("breakpoint"))
@@ -41,6 +44,7 @@ class SampleWorkspaceTest : DebugAdapterTestFixture("sample-workspace") {
4144
Pair("member", "\"test\""),
4245
Pair("local", "123")
4346
))
47+
semaphore.release()
4448
}
4549
})
4650
debugAdapter.setBreakpoints(SetBreakpointsArguments().apply {
@@ -58,5 +62,7 @@ class SampleWorkspaceTest : DebugAdapterTestFixture("sample-workspace") {
5862
line = 8
5963
})
6064
})
65+
launch()
66+
semaphore.acquire() // Wait for the end
6167
}
6268
}

0 commit comments

Comments
 (0)