Skip to content

Commit 0ac98a8

Browse files
committed
KotlinMultiplatformFunctionalTest moved to a separate PR because GitHub Actions doesn't like them (OOM), so I'll deal with them in adamko-dev#115
1 parent 7635161 commit 0ac98a8

File tree

2 files changed

+106
-150
lines changed

2 files changed

+106
-150
lines changed

modules/dokkatoo-plugin/src/testFixtures/kotlin/GradleTestKitUtils.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ class GradleProjectTest(
5656
}
5757

5858

59+
///**
60+
// * Load a project from the [GradleProjectTest.dokkaSrcIntegrationTestProjectsDir]
61+
// */
62+
//fun gradleKtsProjectIntegrationTest(
63+
// testProjectName: String,
64+
// build: GradleProjectTest.() -> Unit,
65+
//): GradleProjectTest =
66+
// GradleProjectTest(
67+
// baseDir = GradleProjectTest.dokkaSrcIntegrationTestProjectsDir,
68+
// testProjectName = testProjectName,
69+
// ).apply(build)
70+
71+
5972
/**
6073
* Builder for testing a Gradle project that uses Kotlin script DSL and creates default
6174
* `settings.gradle.kts` and `gradle.properties` files.
@@ -72,10 +85,10 @@ fun gradleKtsProjectTest(
7285
settingsGradleKts = """
7386
|rootProject.name = "test"
7487
|
75-
|pluginManagement {
88+
|@Suppress("UnstableApiUsage")
89+
|dependencyResolutionManagement {
7690
| repositories {
7791
| mavenCentral()
78-
| gradlePluginPortal()
7992
| maven(file("$testMavenRepoRelativePath")) {
8093
| mavenContent {
8194
| includeGroup("dev.adamko.dokkatoo")
@@ -85,10 +98,10 @@ fun gradleKtsProjectTest(
8598
| }
8699
|}
87100
|
88-
|@Suppress("UnstableApiUsage")
89-
|dependencyResolutionManagement {
101+
|pluginManagement {
90102
| repositories {
91103
| mavenCentral()
104+
| gradlePluginPortal()
92105
| maven(file("$testMavenRepoRelativePath")) {
93106
| mavenContent {
94107
| includeGroup("dev.adamko.dokkatoo")
@@ -145,8 +158,6 @@ fun gradleGroovyProjectTest(
145158
gradleProperties = """
146159
|kotlin.mpp.stability.nowarn=true
147160
|org.gradle.cache=true
148-
|org.gradle.daemon=false
149-
|
150161
""".trimMargin()
151162

152163
build()
@@ -230,16 +241,12 @@ fun ProjectDirectoryScope.findFiles(matcher: (File) -> Boolean): Sequence<File>
230241

231242
/** Set the content of `settings.gradle.kts` */
232243
@delegate:Language("kts")
233-
var ProjectDirectoryScope.settingsGradleKts: String by TestProjectFileDelegate(
234-
/* language=text */ "settings.gradle.kts"
235-
)
244+
var ProjectDirectoryScope.settingsGradleKts: String by TestProjectFileDelegate("settings.gradle.kts")
236245

237246

238247
/** Set the content of `build.gradle.kts` */
239248
@delegate:Language("kts")
240-
var ProjectDirectoryScope.buildGradleKts: String by TestProjectFileDelegate(
241-
/* language=text */ "build.gradle.kts"
242-
)
249+
var ProjectDirectoryScope.buildGradleKts: String by TestProjectFileDelegate("build.gradle.kts")
243250

244251

245252
/** Set the content of `settings.gradle` */

modules/dokkatoo-plugin/src/testFunctional/kotlin/KotlinMultiplatformFunctionalTest.kt

Lines changed: 87 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -13,119 +13,95 @@ import io.kotest.matchers.string.shouldNotContain
1313

1414
class KotlinMultiplatformFunctionalTest : FunSpec({
1515

16-
val kotlinVersionsToTest = listOf(
17-
"1.8.22",
18-
"1.9.10",
19-
"1.9.20-dev-9102",
20-
)
21-
22-
for (kotlinVersion in kotlinVersionsToTest) {
23-
testKotlinMultiplatformProject(kotlinVersion)
24-
}
25-
})
16+
context("when dokkatoo generates all formats") {
17+
val project = initKotlinMultiplatformProject()
18+
19+
project.runner
20+
.addArguments(
21+
"clean",
22+
":dokkatooGeneratePublicationHtml",
23+
"--stacktrace",
24+
)
25+
.forwardOutput()
26+
.build {
27+
test("expect build is successful") {
28+
output shouldContain "BUILD SUCCESSFUL"
29+
}
30+
}
2631

32+
test("expect all dokka workers are successful") {
33+
project
34+
.findFiles { it.name == "dokka-worker.log" }
35+
.shouldBeSingleton { dokkaWorkerLog ->
36+
dokkaWorkerLog.shouldBeAFile()
37+
dokkaWorkerLog.readText().shouldNotContainAnyOf(
38+
"[ERROR]",
39+
"[WARN]",
40+
)
41+
}
42+
}
2743

28-
private fun FunSpec.testKotlinMultiplatformProject(
29-
kotlinVersion: String,
30-
): Unit = context("when dokkatoo generates all formats for Kotlin v$kotlinVersion project") {
31-
val project = initKotlinMultiplatformProject(kotlinVersion)
44+
context("expect HTML site is generated") {
3245

33-
project.runner
34-
.addArguments(
35-
"clean",
36-
":dokkatooGeneratePublicationHtml",
37-
"--stacktrace",
38-
)
39-
.forwardOutput()
40-
.build {
41-
test("expect build is successful") {
42-
output shouldContain "BUILD SUCCESSFUL"
46+
test("with expected HTML files") {
47+
project.projectDir.resolve("build/dokka/html/index.html").shouldBeAFile()
48+
project.projectDir.resolve("build/dokka/html/com/project/hello/Hello.html")
49+
.shouldBeAFile()
4350
}
44-
}
4551

46-
test("expect all dokka workers are successful") {
47-
project
48-
.findFiles { it.name == "dokka-worker.log" }
49-
.shouldBeSingleton { dokkaWorkerLog ->
50-
dokkaWorkerLog.shouldBeAFile()
51-
dokkaWorkerLog.readText().shouldNotContainAnyOf(
52-
"[ERROR]",
53-
"[WARN]",
54-
)
52+
test("and dokka_parameters.json is generated") {
53+
project.projectDir.resolve("build/dokka/html/dokka_parameters.json")
54+
.shouldBeAFile()
5555
}
56-
}
57-
58-
context("expect HTML site is generated") {
5956

60-
test("with expected HTML files") {
61-
project.projectDir.resolve("build/dokka/html/index.html").shouldBeAFile()
62-
project.projectDir.resolve("build/dokka/html/com/project/hello/Hello.html")
63-
.shouldBeAFile()
64-
}
65-
66-
test("and dokka_parameters.json is generated") {
67-
project.projectDir.resolve("build/dokka/html/dokka_parameters.json")
68-
.shouldBeAFile()
69-
}
70-
71-
test("with element-list") {
72-
project.projectDir.resolve("build/dokka/html/test/package-list").shouldBeAFile()
73-
project.projectDir.resolve("build/dokka/html/test/package-list").toFile().readText()
74-
.sortLines()
75-
.shouldContain( /* language=text */ """
76-
|${'$'}dokka.format:html-v1
77-
|${'$'}dokka.linkExtension:html
78-
|${'$'}dokka.location:com.project////PointingToDeclaration/test/com.project/index.html
79-
|${'$'}dokka.location:com.project//goodbye/#kotlinx.serialization.json.JsonObject/PointingToDeclaration/test/com.project/goodbye.html
80-
|${'$'}dokka.location:com.project/Hello///PointingToDeclaration/test/com.project/-hello/index.html
81-
|${'$'}dokka.location:com.project/Hello/Hello/#/PointingToDeclaration/test/com.project/-hello/-hello.html
82-
|${'$'}dokka.location:com.project/Hello/sayHello/#kotlinx.serialization.json.JsonObject/PointingToDeclaration/test/com.project/-hello/say-hello.html
83-
|com.project
84-
""".trimMargin()
85-
)
86-
}
57+
test("with element-list") {
58+
project.projectDir.resolve("build/dokka/html/test/package-list").shouldBeAFile()
59+
project.projectDir.resolve("build/dokka/html/test/package-list").toFile().readText()
60+
.sortLines()
61+
.shouldContain( /* language=text */ """
62+
|${'$'}dokka.format:html-v1
63+
|${'$'}dokka.linkExtension:html
64+
|${'$'}dokka.location:com.project////PointingToDeclaration/test/com.project/index.html
65+
|${'$'}dokka.location:com.project//goodbye/#kotlinx.serialization.json.JsonObject/PointingToDeclaration/test/com.project/goodbye.html
66+
|${'$'}dokka.location:com.project/Hello///PointingToDeclaration/test/com.project/-hello/index.html
67+
|${'$'}dokka.location:com.project/Hello/Hello/#/PointingToDeclaration/test/com.project/-hello/-hello.html
68+
|${'$'}dokka.location:com.project/Hello/sayHello/#kotlinx.serialization.json.JsonObject/PointingToDeclaration/test/com.project/-hello/say-hello.html
69+
|com.project
70+
""".trimMargin()
71+
)
72+
}
8773

88-
test("expect no 'unknown class' message in HTML files") {
89-
val htmlFiles = project.projectDir.toFile()
90-
.resolve("build/dokka/html")
91-
.walk()
92-
.filter { it.isFile && it.extension == "html" }
74+
test("expect no 'unknown class' message in HTML files") {
75+
val htmlFiles = project.projectDir.toFile()
76+
.resolve("build/dokka/html")
77+
.walk()
78+
.filter { it.isFile && it.extension == "html" }
9379

94-
htmlFiles.shouldNotBeEmpty()
80+
htmlFiles.shouldNotBeEmpty()
9581

96-
htmlFiles.forEach { htmlFile ->
97-
val relativePath = htmlFile.relativeTo(project.projectDir.toFile())
98-
withClue("$relativePath should not contain Error class: unknown class") {
99-
htmlFile.useLines { lines ->
100-
lines.shouldForAll { line -> line.shouldNotContain("Error class: unknown class") }
82+
htmlFiles.forEach { htmlFile ->
83+
val relativePath = htmlFile.relativeTo(project.projectDir.toFile())
84+
withClue("$relativePath should not contain Error class: unknown class") {
85+
htmlFile.useLines { lines ->
86+
lines.shouldForAll { line -> line.shouldNotContain("Error class: unknown class") }
87+
}
10188
}
10289
}
10390
}
10491
}
10592
}
106-
}
93+
})
10794

10895

10996
private fun initKotlinMultiplatformProject(
110-
kotlinVersion: String,
11197
config: GradleProjectTest.() -> Unit = {},
11298
): GradleProjectTest {
113-
return gradleKtsProjectTest("kotlin-multiplatform-project-v$kotlinVersion") {
99+
return gradleKtsProjectTest("kotlin-multiplatform-project") {
114100

115-
settingsGradleKts = settingsGradleKts.replace(
116-
"""
117-
|pluginManagement {
118-
| repositories {
119-
""".trimMargin(),
120-
"""
121-
|pluginManagement {
122-
| repositories {
123-
| maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
124-
""".trimMargin(),
125-
)
126101
settingsGradleKts += """
127102
|
128103
|dependencyResolutionManagement {
104+
|
129105
| repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
130106
|
131107
| repositories {
@@ -155,40 +131,14 @@ private fun initKotlinMultiplatformProject(
155131
| }
156132
| filter { includeGroup("com.yarnpkg") }
157133
| }
158-
| maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
159-
|
160-
| // workaround for https://youtrack.jetbrains.com/issue/KT-51379
161-
| exclusiveContent {
162-
| forRepository {
163-
| ivy("https://download.jetbrains.com/kotlin/native/builds") {
164-
| name = "Kotlin Native"
165-
| patternLayout {
166-
| listOf(
167-
| "macos-x86_64",
168-
| "macos-aarch64",
169-
| "osx-x86_64",
170-
| "osx-aarch64",
171-
| "linux-x86_64",
172-
| "windows-x86_64",
173-
| ).forEach { os ->
174-
| listOf("dev", "releases").forEach { stage ->
175-
artifact("${'$'}stage/[revision]/${'$'}os/[artifact]-[revision].[ext]")
176-
| }
177-
| }
178-
| }
179-
| metadataSources { artifact() }
180-
| }
181-
| }
182-
| filter { includeModuleByRegex(".*", ".*kotlin-native-prebuilt.*") }
183-
| }
184134
| }
185135
|}
186136
|
187137
""".trimMargin()
188138

189139
buildGradleKts = """
190140
|plugins {
191-
| kotlin("multiplatform") version "$kotlinVersion"
141+
| kotlin("multiplatform") version "1.8.22"
192142
| id("dev.adamko.dokkatoo") version "${DokkatooConstants.DOKKATOO_VERSION}"
193143
|}
194144
|
@@ -197,11 +147,6 @@ private fun initKotlinMultiplatformProject(
197147
| js(IR) {
198148
| browser()
199149
| }
200-
| linuxX64()
201-
| macosX64()
202-
| macosArm64()
203-
| iosX64()
204-
| mingwX64()
205150
|
206151
| sourceSets {
207152
| commonMain {
@@ -267,30 +212,34 @@ private fun initKotlinMultiplatformProject(
267212
)
268213
}
269214

270-
listOf(
271-
"jvm",
272-
"js",
273-
"linuxX64",
274-
"macosX64",
275-
"macosArm64",
276-
"iosX64",
277-
"mingwX64",
278-
).forEach { target ->
215+
dir("src/jvmMain/kotlin/") {
216+
createKotlinFile(
217+
"goodbyeJvm.kt",
218+
"""
219+
|package com.project
220+
|
221+
|import kotlinx.serialization.json.JsonObject
222+
|
223+
|/** JVM implementation - prints `goodbye` and [json] to the console */
224+
|actual fun goodbye(json: JsonObject) = println("[JVM] goodbye ${'$'}json")
225+
|
226+
""".trimMargin()
227+
)
228+
}
279229

280-
dir("src/${target}Main/kotlin/") {
281-
createKotlinFile(
282-
"goodbye_${target}.kt",
283-
"""
230+
dir("src/jsMain/kotlin/") {
231+
createKotlinFile(
232+
"goodbyeJs.kt",
233+
"""
284234
|package com.project
285235
|
286236
|import kotlinx.serialization.json.JsonObject
287237
|
288-
|/** $target implementation - prints `goodbye` and [json] to the console */
289-
|actual fun goodbye(json: JsonObject) = println("[target] goodbye ${'$'}json")
238+
|/** JS implementation - prints `goodbye` and [json] to the console */
239+
|actual fun goodbye(json: JsonObject) = println("[JS] goodbye ${'$'}json")
290240
|
291241
""".trimMargin()
292-
)
293-
}
242+
)
294243
}
295244

296245
config()

0 commit comments

Comments
 (0)