Skip to content

Commit 81666e9

Browse files
authored
[K2] Run Gradle integration tests (#3390)
* [K2] Run Gradle integration tests * [K2] Pass the property to a test fork * [K2] Fix "Modules are inconsistent" in the Basic Groovy test * [K2] Fix "Modules are inconsistent" in the `SequentialTasksExecutionStressTest` test * [K2] Mute failed tests * [K2] Add doc * Add comments
1 parent b855a0b commit 81666e9

File tree

16 files changed

+153
-6
lines changed

16 files changed

+153
-6
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ val integrationTest by tasks.registering(NonCacheableIntegrationTest::class) {
5050
testClassesDirs = integrationTestSourceSet.output.classesDirs
5151
classpath = integrationTestSourceSet.runtimeClasspath
5252

53-
useJUnitPlatform()
53+
useJUnitPlatform {
54+
val useK2 = (project.properties["org.jetbrains.dokka.experimental.tryK2"] as? String)?.toBoolean() ?: false
55+
if (useK2) excludeTags("onlyDescriptors", "onlyDescriptorsMPP")
56+
}
5457

5558
setForkEvery(1)
5659
project.properties["dokka_integration_test_parallelism"]?.toString()?.toIntOrNull()?.let { parallelism ->

dokka-integration-tests/gradle/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ In order to update:
1919
* Go to `$pathToProjectInDokka`, `git fetch && git checkout $revisionNumber`
2020
- Prior to that, ensure that you have your git submodules initialized
2121
* Ensure that the corresponding `GradleIntegrationTest` passes locally and push
22+
23+
24+
### Run integration tests with K2 (symbols)
25+
26+
To run integration tests with K2, the property `org.jetbrains.dokka.experimental.tryK2` should be set to `true`.
27+
By default, the task `integrationTest` is run with K1 (descriptors).

dokka-integration-tests/gradle/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ dependencies {
2222
val aggregatingProject = gradle.includedBuild("dokka")
2323

2424
tasks.integrationTest {
25+
// pass the property to a test fork
26+
project.findProperty("org.jetbrains.dokka.experimental.tryK2")
27+
?.let { systemProperty("org.jetbrains.dokka.experimental.tryK2", it) }
28+
2529
dependsOn(aggregatingProject.task(":publishToMavenLocal"))
2630

2731
environment("DOKKA_VERSION", project.version)

dokka-integration-tests/gradle/projects/it-basic-groovy/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ dokkaHtml {
1313
outputDirectory = new File(buildDir, "/dokka/customHtml")
1414
failOnWarning = false
1515
dokkaSourceSets {
16+
// create a new source set
1617
customSourceSet {
17-
sourceRoot(file("src/main/java"))
18-
sourceRoot(file("src/main/kotlin"))
18+
sourceRoot(file("src/custom/java"))
19+
sourceRoot(file("src/custom/kotlin"))
1920
displayName.set("custom")
2021
reportUndocumented.set(true)
2122
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package it.basic.java;
2+
3+
import it.basic.PublicClass;
4+
5+
/**
6+
* This class is, unlike {@link PublicClass}, written in Java
7+
*/
8+
@SuppressWarnings("unused")
9+
public class SampleJavaClass {
10+
11+
/**
12+
* @return Empty instance of {@link PublicClass}
13+
*/
14+
public PublicClass publicDocumentedFunction() {
15+
return new PublicClass();
16+
}
17+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@file:Suppress("unused")
2+
3+
package it.basic
4+
5+
class PublicClass {
6+
/**
7+
* This function is public and documented
8+
*/
9+
fun publicDocumentedFunction(): String = ""
10+
11+
fun publicUndocumentedFunction(): String = ""
12+
13+
/**
14+
* This function is internal and documented
15+
*/
16+
internal fun internalDocumentedFunction(): String = ""
17+
18+
internal fun internalUndocumentedFunction(): String = ""
19+
20+
/**
21+
* This function is private and documented
22+
*/
23+
private fun privateDocumentedFunction(): String = ""
24+
25+
private fun privateUndocumentedFunction(): String = ""
26+
27+
28+
/**
29+
* This property is public and documented
30+
*/
31+
val publicDocumentedProperty: Int = 0
32+
33+
val publicUndocumentedProperty: Int = 0
34+
35+
/**
36+
* This property internal and documented
37+
*/
38+
val internalDocumentedProperty: Int = 0
39+
40+
val internalUndocumentedProperty: Int = 0
41+
42+
/**
43+
* This property private and documented
44+
*/
45+
private val privateDocumentedProperty: Int = 0
46+
47+
private val privateUndocumentedProperty: Int = 0
48+
}

dokka-integration-tests/gradle/projects/it-sequential-tasks-execution-stress/build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ fun createTask(name: String) {
2626
tasks.register(name, org.jetbrains.dokka.gradle.DokkaTask::class) {
2727
dokkaSourceSets {
2828
moduleName.set("Some example")
29+
// create a new source set
2930
register("kotlin-stdlib-common") {
30-
sourceRoots.from("src/main/java")
31-
sourceRoots.from("src/main/kotlin")
32-
samples.from("src/main/kotlin")
31+
sourceRoots.from("src/common/java")
32+
sourceRoots.from("src/common/kotlin")
33+
samples.from("src/common/kotlin")
3334
}
3435
}
3536
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package it.basic.java;
2+
3+
import it.basic.PublicClass;
4+
5+
/**
6+
* This class is, unlike {@link PublicClass}, written in Java
7+
*/
8+
@SuppressWarnings("unused")
9+
public class SampleJavaClass {
10+
11+
/**
12+
* @return Empty instance of {@link PublicClass}
13+
*/
14+
public PublicClass publicDocumentedFunction() {
15+
return new PublicClass();
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@file:Suppress("unused")
2+
3+
/**
4+
* A class that lives inside the root package
5+
*/
6+
class RootPackageClass {
7+
val description = "I do live in the root package!"
8+
}

dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/JsIRGradleIntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class JsIRGradleIntegrationTest : AbstractGradleIntegrationTest() {
3636
File(templateProjectDir, "src").copyRecursively(File(projectDir, "src"))
3737
}
3838

39+
@OnlyDescriptors
3940
@ParameterizedTest(name = "{0}")
4041
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
4142
fun execute(buildVersions: BuildVersions) {

dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class WasmGradleIntegrationTest : AbstractGradleIntegrationTest() {
4141
File(templateProjectDir, "src").copyRecursively(File(projectDir, "src"))
4242
}
4343

44+
@OnlyDescriptors
4445
@ParameterizedTest(name = "{0}")
4546
@ArgumentsSource(WasmTestedVersionsArgumentsProvider::class)
4647
fun execute(buildVersions: BuildVersions) {

dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmJsWasiGradleIntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class WasmJsWasiGradleIntegrationTest : AbstractGradleIntegrationTest() {
4040
File(templateProjectDir, "src").copyRecursively(File(projectDir, "src"))
4141
}
4242

43+
@OnlyDescriptors
4344
@ParameterizedTest(name = "{0}")
4445
@ArgumentsSource(WasmJsWasiTestedVersionsArgumentsProvider::class)
4546
fun execute(buildVersions: BuildVersions) {

dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/kotlin/CoroutinesGradleIntegrationTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.dokka.it.TestOutputCopier
99
import org.jetbrains.dokka.it.copyAndApplyGitDiff
1010
import org.jetbrains.dokka.it.gradle.AbstractGradleIntegrationTest
1111
import org.jetbrains.dokka.it.gradle.BuildVersions
12+
import org.jetbrains.dokka.it.gradle.OnlyDescriptors
1213
import org.junit.jupiter.api.extension.ExtensionContext
1314
import org.junit.jupiter.params.ParameterizedTest
1415
import org.junit.jupiter.params.provider.Arguments
@@ -45,6 +46,7 @@ class CoroutinesGradleIntegrationTest : AbstractGradleIntegrationTest(), TestOut
4546
copyAndApplyGitDiff(File("projects", "coroutines/coroutines.diff"))
4647
}
4748

49+
@OnlyDescriptors
4850
@ParameterizedTest(name = "{0}")
4951
@ArgumentsSource(CoroutinesBuildVersionsArgumentsProvider::class)
5052
fun execute(buildVersions: BuildVersions) {

dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/kotlin/SerializationGradleIntegrationTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.dokka.it.TestOutputCopier
99
import org.jetbrains.dokka.it.copyAndApplyGitDiff
1010
import org.jetbrains.dokka.it.gradle.AbstractGradleIntegrationTest
1111
import org.jetbrains.dokka.it.gradle.BuildVersions
12+
import org.jetbrains.dokka.it.gradle.OnlyDescriptors
1213
import org.junit.jupiter.api.extension.ExtensionContext
1314
import org.junit.jupiter.params.ParameterizedTest
1415
import org.junit.jupiter.params.provider.Arguments
@@ -44,6 +45,7 @@ class SerializationGradleIntegrationTest : AbstractGradleIntegrationTest(), Test
4445
copyAndApplyGitDiff(File("projects", "serialization/serialization.diff"))
4546
}
4647

48+
@OnlyDescriptors // failed due to https://github.com/Kotlin/dokka/issues/3207
4749
@ParameterizedTest(name = "{0}")
4850
@ArgumentsSource(SerializationBuildVersionsArgumentsProvider::class)
4951
fun execute(buildVersions: BuildVersions) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest()
4141
buildVersions.androidGradlePluginVersion?.let { androidVersion ->
4242
"-Pdokka_it_android_gradle_plugin_version=$androidVersion"
4343
},
44+
// property flag to use K2
45+
if (TestEnvironment.shouldUseK2())
46+
"-P${TestEnvironment.TRY_K2}=true"
47+
else
48+
null,
49+
4450
* arguments
4551
)
4652
).run { this as DefaultGradleRunner }

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44

55
package org.jetbrains.dokka.it.gradle
66

7+
import org.junit.jupiter.api.Tag
8+
79
public object TestEnvironment {
10+
public const val TRY_K2: String = "org.jetbrains.dokka.experimental.tryK2"
11+
812
public val isExhaustive: Boolean = checkNotNull(System.getenv("isExhaustive")) {
913
"Missing `isExhaustive` environment variable"
1014
}.toBoolean()
15+
16+
/**
17+
* By default, it is disabled
18+
*/
19+
public fun shouldUseK2(): Boolean = getBooleanProperty(TRY_K2)
20+
21+
private fun getBooleanProperty(propertyName: String): Boolean {
22+
return System.getProperty(propertyName) in setOf("1", "true")
23+
}
1124
}
1225

1326
/**
@@ -16,3 +29,19 @@ public object TestEnvironment {
1629
public inline fun <reified T> ifExhaustive(vararg values: T): Array<out T> {
1730
return if (TestEnvironment.isExhaustive) values else emptyArray()
1831
}
32+
33+
/**
34+
* Run a test only for descriptors (K1), not symbols (K2).
35+
* The test with this annotation will be ignored only if the property [TestEnvironment.TRY_K2] = true.
36+
*/
37+
@Target(
38+
AnnotationTarget.CLASS,
39+
AnnotationTarget.FUNCTION,
40+
AnnotationTarget.PROPERTY_GETTER,
41+
AnnotationTarget.PROPERTY_SETTER
42+
)
43+
@Retention(
44+
AnnotationRetention.RUNTIME
45+
)
46+
@Tag("onlyDescriptors")
47+
public annotation class OnlyDescriptors(val reason: String = "")

0 commit comments

Comments
 (0)