@@ -10,30 +10,45 @@ import org.eclipse.lsp4j.debug.services.IDebugProtocolClient
10
10
import org.javacs.ktda.adapter.KotlinDebugAdapter
11
11
import org.javacs.ktda.jdi.launch.JDILauncher
12
12
import org.junit.After
13
+ import org.junit.Assert.assertThat
14
+ import org.junit.Before
15
+ import org.hamcrest.Matchers.equalTo
13
16
14
17
abstract class DebugAdapterTestFixture (
15
18
relativeWorkspaceRoot : String ,
16
19
private val mainClass : String
17
20
) : IDebugProtocolClient {
18
21
val absoluteWorkspaceRoot: Path = Paths .get(DebugAdapterTestFixture ::class .java.getResource(" /Anchor.txt" ).toURI()).parent.resolve(relativeWorkspaceRoot)
19
- val debugAdapter: KotlinDebugAdapter = JDILauncher ()
20
- .let (::KotlinDebugAdapter )
21
- .also {
22
- it.connect(this )
23
- val configDone = it.configurationDone(ConfigurationDoneArguments ())
24
- it.initialize(InitializeRequestArguments ().apply {
25
- adapterID = " test-debug-adapter"
26
- linesStartAt1 = true
27
- columnsStartAt1 = true
28
- }).join()
29
- // Slightly hacky workaround to ensure someone is
30
- // waiting on the ConfigurationDoneResponse. See
31
- // KotlinDebugAdapter.kt:performInitialization for
32
- // details.
33
- Thread {
34
- configDone.join()
35
- }.start()
36
- }
22
+ lateinit var debugAdapter: KotlinDebugAdapter
23
+
24
+ @Before fun startDebugAdapter () {
25
+ // Build the project first
26
+ val process = ProcessBuilder (" ./gradlew" , " assemble" )
27
+ .directory(absoluteWorkspaceRoot.toFile())
28
+ .inheritIO()
29
+ .start()
30
+ process.waitFor()
31
+ assertThat(process.exitValue(), equalTo(0 ))
32
+
33
+ debugAdapter = JDILauncher ()
34
+ .let (::KotlinDebugAdapter )
35
+ .also {
36
+ it.connect(this )
37
+ val configDone = it.configurationDone(ConfigurationDoneArguments ())
38
+ it.initialize(InitializeRequestArguments ().apply {
39
+ adapterID = " test-debug-adapter"
40
+ linesStartAt1 = true
41
+ columnsStartAt1 = true
42
+ }).join()
43
+ // Slightly hacky workaround to ensure someone is
44
+ // waiting on the ConfigurationDoneResponse. See
45
+ // KotlinDebugAdapter.kt:performInitialization for
46
+ // details.
47
+ Thread {
48
+ configDone.join()
49
+ }.start()
50
+ }
51
+ }
37
52
38
53
fun launch () {
39
54
println (" Launching..." )
0 commit comments