Skip to content

Commit 5ee29bd

Browse files
committed
test: variable scope
1 parent 4ac6152 commit 5ee29bd

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2023 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package integration.breakpoint
18+
19+
import integration.ProbeIntegrationTest
20+
import io.vertx.junit5.VertxTestContext
21+
import io.vertx.kotlin.coroutines.await
22+
import kotlinx.coroutines.runBlocking
23+
import org.junit.jupiter.api.Assertions.assertEquals
24+
import org.junit.jupiter.api.Assertions.assertNotNull
25+
import org.junit.jupiter.api.Test
26+
import spp.protocol.instrument.LiveBreakpoint
27+
import spp.protocol.instrument.event.LiveBreakpointHit
28+
import spp.protocol.instrument.event.LiveInstrumentEvent
29+
import spp.protocol.instrument.event.LiveInstrumentEventType
30+
import spp.protocol.instrument.location.LiveSourceLocation
31+
32+
class VariableScopeBreakpointTest : ProbeIntegrationTest() {
33+
34+
private fun doTest() {
35+
val z = 1
36+
for (i in 0 until 100) {
37+
}
38+
}
39+
40+
@Test
41+
fun `variable scope`() = runBlocking {
42+
val instrumentId = "variable-scope"
43+
val testContext = VertxTestContext()
44+
getLiveInstrumentSubscription(instrumentId).handler {
45+
testContext.verify {
46+
val event = LiveInstrumentEvent.fromJson(it.body())
47+
if (event.eventType == LiveInstrumentEventType.BREAKPOINT_HIT) {
48+
val item = event as LiveBreakpointHit
49+
val vars = item.stackTrace.first().variables
50+
assertEquals(2, vars.size)
51+
assertNotNull(vars.first { it.name == "this" })
52+
assertNotNull(vars.first { it.name == "z" })
53+
54+
testContext.completeNow()
55+
}
56+
}
57+
}
58+
59+
//add live breakpoint
60+
instrumentService.addLiveInstrument(
61+
LiveBreakpoint(
62+
location = LiveSourceLocation(
63+
VariableScopeBreakpointTest::class.java.name,
64+
38,
65+
service = "spp-test-probe"
66+
),
67+
applyImmediately = true,
68+
id = instrumentId,
69+
)
70+
).await()
71+
72+
//trigger live breakpoint
73+
doTest()
74+
75+
errorOnTimeout(testContext)
76+
}
77+
}

0 commit comments

Comments
 (0)