Skip to content

Commit 2b86ffb

Browse files
AbdullinAMwhyoleg
andauthored
Add integration test target with experimental KDoc resolution enabled (#4454)
* Add integration test target with experimental KDoc resolution enabled * Create a separate annotation/tag for tests with new KDoc resolution * Forward new KDoc resolution flаg to IT Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
1 parent 4108892 commit 2b86ffb

File tree

10 files changed

+93
-30
lines changed

10 files changed

+93
-30
lines changed

build-logic/src/main/kotlin/dokkabuild.test-integration.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ tasks.withType<Test>().configureEach {
3838
val useK2 = dokkaBuild.integrationTestUseK2
3939
systemProperty.inputProperty("org.jetbrains.dokka.experimental.tryK2", useK2)
4040
.optional(true)
41+
42+
val enableExperimentalKDocResolution = dokkaBuild.integrationTestEnableExperimentalKDocResolution
43+
systemProperty.inputProperty("org.jetbrains.dokka.analysis.enableExperimentalKDocResolution", enableExperimentalKDocResolution)
44+
.optional(true)
45+
4146
useJUnitPlatform {
4247
if (useK2.get()) excludeTags("onlyDescriptors", "onlyDescriptorsMPP")
4348
}

build-logic/src/main/kotlin/dokkabuild.test-k2.gradle.kts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ testing {
4747
// JUnit tags for descriptors (K1) and symbols (K2) are defined with annotations in test classes.
4848
val onlyDescriptorTags = listOf("onlyDescriptors", "onlyDescriptorsMPP")
4949
val onlySymbolsTags = listOf("onlySymbols")
50+
val onlyNewKdocResolutionTags = listOf("onlyNewKDocResolution")
5051

5152
// Create a new target for _only_ running test compatible with descriptor-analysis (K1).
5253
val testDescriptorsTarget = targets.register("testDescriptors") {
5354
testTask.configure {
54-
description = "Runs tests using descriptors-analysis (K1) (excluding tags: ${onlySymbolsTags})"
55+
val excludedTags = onlySymbolsTags + onlyNewKdocResolutionTags
56+
description = "Runs tests using descriptors-analysis (K1) (excluding tags: ${excludedTags})"
5557
useJUnitPlatform {
56-
excludeTags.addAll(onlySymbolsTags)
58+
excludeTags.addAll(excludedTags)
5759
}
5860
// Analysis dependencies from `descriptorsTestImplementation` should precede all other dependencies
5961
// in order to use the shadowed stdlib from the analysis dependencies
@@ -64,16 +66,34 @@ testing {
6466
// Create a new target for _only_ running test compatible with symbols-analysis (K2).
6567
val testSymbolsTarget = targets.register("testSymbols") {
6668
testTask.configure {
67-
description = "Runs tests using symbols-analysis (K2) (excluding tags: ${onlyDescriptorTags})"
69+
val excludedTags = onlyDescriptorTags + onlyNewKdocResolutionTags
70+
description = "Runs tests using symbols-analysis (K2) (excluding tags: ${excludedTags})"
6871
useJUnitPlatform {
69-
excludeTags.addAll(onlyDescriptorTags)
72+
excludeTags.addAll(excludedTags)
7073
}
7174
// Analysis dependencies from `symbolsTestImplementation` should precede all other dependencies
7275
// in order to use the shadowed stdlib from the analysis dependencies
7376
classpath = symbolsTestImplementationResolver.incoming.files + classpath
7477
}
7578
}
7679

80+
// Create a new target for running symbols-analysis tests with enabled experimental KDoc resolution (K2).
81+
val testSymbolsWithNewKDocResolutionTarget = targets.register("testSymbolsWithNewKDocResolution") {
82+
testTask.configure {
83+
val excludedTags = onlyDescriptorTags
84+
description = "Runs tests using symbols-analysis and experimental KDoc resolution (K2)" +
85+
" (excluding tags: ${excludedTags})"
86+
useJUnitPlatform {
87+
excludeTags.addAll(excludedTags)
88+
}
89+
// Analysis dependencies from `symbolsTestImplementation` should precede all other dependencies
90+
// in order to use the shadowed stdlib from the analysis dependencies
91+
classpath = symbolsTestImplementationResolver.incoming.files + classpath
92+
93+
systemProperty("org.jetbrains.dokka.analysis.enableExperimentalKDocResolution", "true")
94+
}
95+
}
96+
7797
// Run both K1 and K2, when running :test
7898
// don't run the task itself, as it's just an aggregate for K1/K2 tests.
7999
// Ideally, we don't really need this `test` target, but it's not possible to remove it.
@@ -82,6 +102,7 @@ testing {
82102
onlyIf { false }
83103
dependsOn(testDescriptorsTarget.map { it.testTask })
84104
dependsOn(testSymbolsTarget.map { it.testTask })
105+
dependsOn(testSymbolsWithNewKDocResolutionTarget.map { it.testTask })
85106
}
86107
}
87108
}

build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.gradle.api.file.ProjectLayout
88
import org.gradle.api.provider.Provider
99
import org.gradle.api.provider.ProviderFactory
1010
import org.gradle.jvm.toolchain.JavaLanguageVersion
11-
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
1211
import java.io.File
1312
import javax.inject.Inject
1413

@@ -87,6 +86,11 @@ abstract class DokkaBuildProperties @Inject constructor(
8786
val integrationTestDokkaVersionOverride: Provider<String> =
8887
dokkaProperty("integration_test.dokkaVersionOverride") { it }
8988

89+
/** Control whether integration tests should use the `org.jetbrains.dokka.analysis.enableExperimentalKDocResolution` flag. */
90+
val integrationTestEnableExperimentalKDocResolution: Provider<Boolean> =
91+
dokkaProperty("integration_test.enableExperimentalKDocResolution", String::toBoolean)
92+
.orElse(false)
93+
9094
val androidSdkDir: Provider<File> =
9195
providers
9296
// first try finding a local.properties file in any parent directory

dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest() {
112112

113113
// property flag to use K2
114114
add("-P${TestEnvironment.TRY_K2}=${TestEnvironment.shouldUseK2()}")
115+
add("-P${TestEnvironment.TRY_EXPERIMENTAL_KDOC_RESOLUTION}=${TestEnvironment.shouldUseExperimentalKDocResolution()}")
115116

116117
// Decrease Gradle daemon idle timeout to prevent old agents lingering on CI.
117118
// A lower timeout means slower tests, which is preferred over OOMs and locked processes.

dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestEnvironment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Tag
99

1010
object TestEnvironment {
1111
const val TRY_K2: String = "org.jetbrains.dokka.experimental.tryK2"
12+
const val TRY_EXPERIMENTAL_KDOC_RESOLUTION = "org.jetbrains.dokka.analysis.enableExperimentalKDocResolution"
1213

1314
val isExhaustive: Boolean by systemProperty(String::toBoolean)
1415

@@ -19,6 +20,11 @@ object TestEnvironment {
1920
*/
2021
fun shouldUseK2(): Boolean = getBooleanProperty(TRY_K2)
2122

23+
/**
24+
* By default, it is disabled
25+
*/
26+
fun shouldUseExperimentalKDocResolution(): Boolean = getBooleanProperty(TRY_EXPERIMENTAL_KDOC_RESOLUTION)
27+
2228
private fun getBooleanProperty(propertyName: String): Boolean {
2329
return System.getProperty(propertyName) in setOf("1", "true")
2430
}

dokka-subprojects/analysis-kotlin-api/src/test/kotlin/org/jetbrains/dokka/analysis/test/TagsAnnotations.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,20 @@ annotation class OnlySymbols(val reason: String = "")
5959
)
6060
@Tag("onlyDescriptorsMPP")
6161
annotation class OnlyDescriptorsMPP(val reason: String = "")
62+
63+
/**
64+
* Run a test only for a new KDoc resolution (with K2)
65+
*
66+
* After we switch to the new KDoc resolution by default, this annotation should be removed
67+
*/
68+
@Target(
69+
AnnotationTarget.CLASS,
70+
AnnotationTarget.FUNCTION,
71+
AnnotationTarget.PROPERTY_GETTER,
72+
AnnotationTarget.PROPERTY_SETTER
73+
)
74+
@Retention(
75+
AnnotationRetention.RUNTIME
76+
)
77+
@Tag("onlyNewKDocResolution")
78+
annotation class OnlyNewKDocResolution(val reason: String = "")

dokka-subprojects/plugin-base/src/test/kotlin/content/kdoc/KDocAmbiguityResolutionTest.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ import org.jetbrains.dokka.pages.ClasslikePageNode
2727
import org.jetbrains.dokka.pages.ContentDRILink
2828
import org.jetbrains.dokka.pages.ContentPage
2929
import org.jetbrains.dokka.pages.MemberPageNode
30-
import utils.OnlySymbols
30+
import utils.OnlyNewKDocResolution
3131
import utils.findTestType
32-
import utils.withExperimentalKDocResolution
3332
import kotlin.test.Test
3433
import kotlin.test.assertEquals
3534

36-
@OnlySymbols("KEEP #389: New KDoc resolution")
35+
@OnlyNewKDocResolution("KEEP #389: New KDoc resolution")
3736
class KDocAmbiguityResolutionTest : BaseAbstractTest() {
3837
private val testConfiguration = dokkaConfiguration {
3938
sourceSets {
@@ -46,7 +45,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
4645
}
4746

4847
@Test
49-
fun `#3451 ambiguous link to the class`() = withExperimentalKDocResolution {
48+
fun `#3451 ambiguous link to the class`() {
5049
testInline(
5150
"""
5251
|/src/main/kotlin/test/source.kt
@@ -120,7 +119,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
120119
}
121120

122121
@Test
123-
fun `#3451 ambiguous link to function and property`() = withExperimentalKDocResolution {
122+
fun `#3451 ambiguous link to function and property`() {
124123
testInline(
125124
"""
126125
|/src/main/kotlin/test/source.kt
@@ -212,7 +211,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
212211
}
213212

214213
@Test
215-
fun `#3451 ambiguous link with factory functions`() = withExperimentalKDocResolution {
214+
fun `#3451 ambiguous link with factory functions`() {
216215
testInline(
217216
"""
218217
|/src/main/kotlin/test/source.kt
@@ -359,7 +358,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
359358
}
360359

361360
@Test
362-
fun `#3451 ambiguous link to inner class`() = withExperimentalKDocResolution {
361+
fun `#3451 ambiguous link to inner class`() {
363362
testInline(
364363
"""
365364
|/src/main/kotlin/test/source.kt
@@ -411,7 +410,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
411410
}
412411

413412
@Test
414-
fun `#3179 KDoc link to property`() = withExperimentalKDocResolution {
413+
fun `#3179 KDoc link to property`() {
415414
testInline(
416415
"""
417416
|/src/main/kotlin/test/source.kt
@@ -485,7 +484,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
485484
}
486485

487486
@Test
488-
fun `#3179 KDoc link to parameter`() = withExperimentalKDocResolution {
487+
fun `#3179 KDoc link to parameter`() {
489488
testInline(
490489
"""
491490
|/src/main/kotlin/test/source.kt
@@ -535,7 +534,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
535534

536535

537536
@Test
538-
fun `#3604 KDoc reference to class from constructor`() = withExperimentalKDocResolution {
537+
fun `#3604 KDoc reference to class from constructor`() {
539538
testInline(
540539
"""
541540
|/src/main/kotlin/test/source.kt
@@ -603,7 +602,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
603602
}
604603

605604
@Test
606-
fun `#3632 KDoc reference to extension`() = withExperimentalKDocResolution {
605+
fun `#3632 KDoc reference to extension`() {
607606
testInline(
608607
"""
609608
|/src/main/kotlin/test/source.kt
@@ -665,7 +664,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
665664
}
666665

667666
@Test
668-
fun `#3632 KDoc reference to member in extension`() = withExperimentalKDocResolution {
667+
fun `#3632 KDoc reference to member in extension`() {
669668
testInline(
670669
"""
671670
|/src/main/kotlin/test/source.kt
@@ -725,7 +724,7 @@ class KDocAmbiguityResolutionTest : BaseAbstractTest() {
725724
}
726725

727726
@Test
728-
fun `#4327 KDoc reference to properties named the same as constructor parameters`() = withExperimentalKDocResolution {
727+
fun `#4327 KDoc reference to properties named the same as constructor parameters`() {
729728
testInline(
730729
"""
731730
|/src/main/kotlin/test/source.kt

dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import org.jetbrains.dokka.pages.ClasslikePageNode
1616
import org.jetbrains.dokka.pages.ContentDRILink
1717
import org.jetbrains.dokka.pages.MemberPageNode
1818
import utils.OnlyDescriptors
19+
import utils.OnlyNewKDocResolution
1920
import utils.OnlySymbols
2021
import utils.text
21-
import utils.withExperimentalKDocResolution
2222
import kotlin.test.Test
2323
import kotlin.test.assertEquals
2424
import kotlin.test.assertNotNull
@@ -613,8 +613,8 @@ class LinkTest : BaseAbstractTest() {
613613
}
614614

615615
@Test
616-
@OnlySymbols("KEEP #389: New KDoc resolution")
617-
fun `fully qualified link should lead to function`() = withExperimentalKDocResolution {
616+
@OnlyNewKDocResolution("KEEP #389: New KDoc resolution")
617+
fun `fully qualified link should lead to function`() {
618618
// for the test case, there is the only one link candidate in K1 and K2
619619
testInline(
620620
"""
@@ -796,8 +796,8 @@ class LinkTest : BaseAbstractTest() {
796796
}
797797

798798
@Test
799-
@OnlySymbols("KEEP #389: New KDoc resolution")
800-
fun `short link should lead to function`() = withExperimentalKDocResolution {
799+
@OnlyNewKDocResolution("KEEP #389: New KDoc resolution")
800+
fun `short link should lead to function`() {
801801
testInline(
802802
"""
803803
|/src/main/kotlin/Testing.kt

dokka-subprojects/plugin-base/src/test/kotlin/utils/TagsAnnotations.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,20 @@ annotation class OnlySymbols(val reason: String = "")
5858
)
5959
@Tag("onlyDescriptorsMPP")
6060
annotation class OnlyDescriptorsMPP(val reason: String = "")
61+
62+
/**
63+
* Run a test only for a new KDoc resolution (with K2)
64+
*
65+
* After we switch to the new KDoc resolution by default, this annotation should be removed
66+
*/
67+
@Target(
68+
AnnotationTarget.CLASS,
69+
AnnotationTarget.FUNCTION,
70+
AnnotationTarget.PROPERTY_GETTER,
71+
AnnotationTarget.PROPERTY_SETTER
72+
)
73+
@Retention(
74+
AnnotationRetention.RUNTIME
75+
)
76+
@Tag("onlyNewKDocResolution")
77+
annotation class OnlyNewKDocResolution(val reason: String = "")

dokka-subprojects/plugin-base/src/test/kotlin/utils/systemProperties.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ internal fun withSinceKotlin(block: () -> Unit): Unit =
2121
internal fun withAllowKotlinPackage(block: () -> Unit): Unit =
2222
DokkaBaseInternalConfiguration.withProperty("org.jetbrains.dokka.analysis.allowKotlinPackage", "true", block)
2323

24-
/**
25-
* This property works only for K2
26-
* Enable experimental KDoc resolution
27-
*/
28-
internal fun withExperimentalKDocResolution(block: () -> Unit): Unit =
29-
DokkaBaseInternalConfiguration.withProperty("org.jetbrains.dokka.analysis.enableExperimentalKDocResolution", "true", block)
30-
3124
internal fun DokkaBaseInternalConfiguration.withProperty(propertyName: String, value: String, block: () -> Unit) {
3225
setProperty(propertyName, value)
3326
try {

0 commit comments

Comments
 (0)