Skip to content

Commit 58df05e

Browse files
mazhukinevgeniySpace Team
authored and
Space Team
committed
[Tests] More tests for inline fun abi snapshotting
^KT-75529
1 parent 9512893 commit 58df05e

File tree

9 files changed

+117
-1
lines changed

9 files changed

+117
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
val result = calculate()
2+
3+
fun main(args: Array<String>) {
4+
println(result)
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
inline fun calculate(): Int {
2+
return 42
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
inline fun calculate(): Int {
2+
class Calc {
3+
val item = 42
4+
}
5+
return Calc().item
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
inline fun calculate(): Int {
2+
class Calc {
3+
val item = 42 + 3
4+
}
5+
return Calc().item
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example.ictest
2+
3+
fun main() {
4+
println(Holder().regularInlineFun())
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.ictest
2+
3+
class Holder() {
4+
val item: String = "nice data"
5+
6+
inline fun regularInlineFun(): String {
7+
return item
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.ictest
2+
3+
class Holder() {
4+
val item: String = "even nicer data"
5+
6+
inline fun regularInlineFun(): String {
7+
return item
8+
}
9+
}

compiler/build-tools/kotlin-build-tools-api-tests/src/testCrossModuleIncrementalChanges/kotlin/InlinedLambdaChangeTest.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package org.jetbrains.kotlin.buildtools.api.tests.compilation
66

77
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
88
import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity
9+
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertLogContainsPatterns
910
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.DefaultStrategyAgnosticCompilationTest
11+
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.LogLevel
1012
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.SnapshotConfig
1113
import org.jetbrains.kotlin.buildtools.api.tests.compilation.scenario.scenario
1214
import org.jetbrains.kotlin.buildtools.api.tests.compilation.util.compile
@@ -138,6 +140,26 @@ class InlinedLambdaChangeTest : BaseCompilationTest() {
138140
}
139141
}
140142

143+
@DefaultStrategyAgnosticCompilationTest
144+
@DisplayName("Changes in inlined named class")
145+
@TestMetadata("ic-scenarios/inline-local-class/local-named/lib")
146+
fun testLocalNamedClass(strategyConfig: CompilerExecutionStrategyConfiguration) {
147+
scenario(strategyConfig) {
148+
val lib = module("ic-scenarios/inline-local-class/local-named/lib")
149+
val app = module(
150+
"ic-scenarios/inline-local-class/local-named/app",
151+
dependencies = listOf(lib),
152+
snapshotConfig = SnapshotConfig(ClassSnapshotGranularity.CLASS_MEMBER_LEVEL, true),
153+
)
154+
lib.replaceFileWithVersion("inlinedLocalClass.kt", "addNamedClass")
155+
lib.compile { module, scenarioModule ->
156+
expectFail()
157+
assertLogContainsPatterns(LogLevel.ERROR, ".*Local classes are not yet supported in inline functions.*".toRegex())
158+
}
159+
// if at any point local named classes become supported, test the scenario as usual
160+
}
161+
}
162+
141163
@DefaultStrategyAgnosticCompilationTest
142164
@DisplayName("Changes in unused code should not trigger recompilation of call site")
143165
@TestMetadata("ic-scenarios/inline-local-class/no-recompile/lib")
@@ -273,7 +295,7 @@ class InlinedLambdaChangeTest : BaseCompilationTest() {
273295
}
274296
}
275297

276-
@Disabled("should be fixed if we start snapshotting bytecode")
298+
@Disabled("KT-75883 - here callable's code creates a new object so there's no INSTANCE")
277299
@DefaultStrategyAgnosticCompilationTest
278300
@DisplayName("Recompilation of call site affected by an anonymous object - slightly evil")
279301
@TestMetadata("ic-scenarios/inline-local-class/inline-anonymous-object-evil/lib")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
package org.jetbrains.kotlin.buildtools.api.tests.compilation
7+
8+
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
9+
import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity
10+
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.DefaultStrategyAgnosticCompilationTest
11+
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.SnapshotConfig
12+
import org.jetbrains.kotlin.buildtools.api.tests.compilation.scenario.scenario
13+
import org.jetbrains.kotlin.buildtools.api.tests.compilation.util.compile
14+
import org.jetbrains.kotlin.buildtools.api.tests.compilation.util.execute
15+
import org.jetbrains.kotlin.test.TestMetadata
16+
import org.junit.jupiter.api.DisplayName
17+
18+
class RegularInlineFunTest : BaseCompilationTest() {
19+
20+
@DefaultStrategyAgnosticCompilationTest
21+
@DisplayName("When regular inline function changes, its call site is recompiled")
22+
@TestMetadata("ic-scenarios/regular-inline-fun/basic-change/lib")
23+
fun testBasicCase(strategyConfig: CompilerExecutionStrategyConfiguration) {
24+
scenario(strategyConfig) {
25+
val lib = module("ic-scenarios/regular-inline-fun/basic-change/lib")
26+
val app = module(
27+
"ic-scenarios/regular-inline-fun/basic-change/app",
28+
dependencies = listOf(lib),
29+
snapshotConfig = SnapshotConfig(ClassSnapshotGranularity.CLASS_MEMBER_LEVEL, true),
30+
)
31+
32+
app.execute(mainClass = "com.example.ictest.CallSiteKt", exactOutput = "nice data")
33+
34+
lib.replaceFileWithVersion("com/example/ictest/inlineFun.kt", "changeConstantPool")
35+
36+
lib.compile(expectedDirtySet = setOf("com/example/ictest/inlineFun.kt"))
37+
app.compile(expectedDirtySet = setOf())
38+
app.execute(mainClass = "com.example.ictest.CallSiteKt", exactOutput = "even nicer data")
39+
40+
lib.changeFile("com/example/ictest/inlineFun.kt") { it.replace("return item", "return \"bar\"") }
41+
lib.compile(expectedDirtySet = setOf("com/example/ictest/inlineFun.kt"))
42+
app.compile(expectedDirtySet = setOf("com/example/ictest/callSite.kt"))
43+
app.execute(mainClass = "com.example.ictest.CallSiteKt", exactOutput = "bar")
44+
45+
lib.changeFile("com/example/ictest/inlineFun.kt") { it.replace("return \"bar\"", "return \"foo\"") }
46+
lib.compile(expectedDirtySet = setOf("com/example/ictest/inlineFun.kt"))
47+
app.compile(expectedDirtySet = setOf("com/example/ictest/callSite.kt"))
48+
app.execute(mainClass = "com.example.ictest.CallSiteKt", exactOutput = "foo")
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)