Skip to content

Commit cf79619

Browse files
committed
Build project before launching in test fixture
1 parent 7bc0a25 commit cf79619

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

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

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,45 @@ import org.eclipse.lsp4j.debug.services.IDebugProtocolClient
1010
import org.javacs.ktda.adapter.KotlinDebugAdapter
1111
import org.javacs.ktda.jdi.launch.JDILauncher
1212
import org.junit.After
13+
import org.junit.Assert.assertThat
14+
import org.junit.Before
15+
import org.hamcrest.Matchers.equalTo
1316

1417
abstract class DebugAdapterTestFixture(
1518
relativeWorkspaceRoot: String,
1619
private val mainClass: String
1720
) : IDebugProtocolClient {
1821
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+
}
3752

3853
fun launch() {
3954
println("Launching...")

0 commit comments

Comments
 (0)