1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package transformers
import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.junit.jupiter.api.io.TempDir
import transformers.AbstractContextModuleAndPackageDocumentationReaderTest.Companion.texts
import utils.OnlyDescriptorsMPP
import java.nio.file.Path
import kotlin.test.Test
import kotlin.test.assertEquals
class ModuleAndPackageDocumentationTransformerFunctionalTest : BaseAbstractTest() {
@OnlyDescriptorsMPP
@Test
fun `multiplatform project`(@TempDir tempDir: Path) {
val include = tempDir.resolve("include.md").toFile()
include.writeText(
"""
# Module moduleA
This is moduleA
# Package
This is the root package
# Package [root]
This is also the root package
# Package common
This is the common package
# Package jvm
This is the jvm package
# Package js
This is the js package
""".trimIndent()
)
val configuration = dokkaConfiguration {
moduleName = "moduleA"
sourceSets {
sourceSet {
name = "commonMain"
displayName = "common"
analysisPlatform = "common"
sourceRoots = listOf("src/commonMain/kotlin")
includes = listOf(include.canonicalPath)
}
sourceSet {
name = "jsMain"
displayName = "js"
analysisPlatform = "js"
sourceRoots = listOf("src/jsMain/kotlin")
dependentSourceSets = setOf(DokkaSourceSetID("moduleA", "commonMain"))
includes = listOf(include.canonicalPath)
}
sourceSet {
name = "jvmMain"
displayName = "jvm"
analysisPlatform = "jvm"
sourceRoots = listOf("src/jvmMain/kotlin")
dependentSourceSets = setOf(DokkaSourceSetID("moduleA", "commonMain"))
includes = listOf(include.canonicalPath)
}
}
}
testInline(
"""
/src/commonMain/kotlin/common/CommonApi.kt
package common
val commonApi = "common"
/src/jsMain/kotlin/js/JsApi.kt
package js
val jsApi = "js"
/src/jvmMain/kotlin/jvm/JvmApi.kt
package jvm
val jvmApi = "jvm"
/src/commonMain/kotlin/CommonRoot.kt
val commonRoot = "commonRoot"
/src/jsMain/kotlin/JsRoot.kt
val jsRoot = "jsRoot"
/src/jvmMain/kotlin/JvmRoot.kt
val jvmRoot = "jvmRoot"
""".trimIndent(),
configuration
) {
this.documentablesMergingStage = { module ->
val packageNames = module.packages.map { it.dri.packageName ?: "NULL" }
assertEquals(
listOf("", "common", "js", "jvm").sorted(), packageNames.sorted(),
"Expected all packages to be present"
)
/* Assert module documentation */
assertEquals(3, module.documentation.keys.size, "Expected all three source sets")
assertEquals("This is moduleA", module.documentation.texts.distinct().joinToString())
/* Assert root package */
val rootPackage = module.packages.single { it.dri.packageName == "" }
assertEquals(3, rootPackage.documentation.keys.size, "Expected all three source sets")
assertEquals(
listOf("This is the root package", "This is also the root package"),
rootPackage.documentation.texts.distinct()
)
/* Assert common package */
val commonPackage = module.packages.single { it.dri.packageName == "common" }
assertEquals(3, commonPackage.documentation.keys.size, "Expected all three source sets")
assertEquals("This is the common package", commonPackage.documentation.texts.distinct().joinToString())
/* Assert js package */
val jsPackage = module.packages.single { it.dri.packageName == "js" }
assertEquals(
"This is the js package",
jsPackage.documentation.texts.joinToString()
)
/* Assert the jvm package */
val jvmPackage = module.packages.single { it.dri.packageName == "jvm" }
assertEquals(
"This is the jvm package",
jvmPackage.documentation.texts.joinToString()
)
}
}
}
}
|