forked from Kotlin/dokka
/
CliIntegrationTest.kt
371 lines (318 loc) · 14.4 KB
/
CliIntegrationTest.kt
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package org.jetbrains.dokka.it.cli
import org.jetbrains.dokka.it.awaitProcessResult
import java.io.File
import java.io.PrintWriter
import java.lang.IllegalStateException
import kotlin.test.*
class CliIntegrationTest : AbstractCliIntegrationTest() {
@BeforeTest
fun copyProject() {
val templateProjectDir = File("projects", "it-cli")
templateProjectDir.copyRecursively(projectDir)
}
@Test
fun runHelp() {
val process = ProcessBuilder("java", "-jar", cliJarFile.path, "-h")
.redirectErrorStream(true)
.start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
assertTrue("Usage: " in result.output)
}
@Test
fun runCli() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-moduleName", "Basic Project",
"-sourceSet",
buildString {
append(" -sourceSetName cliMain")
append(" -src ${File(projectDir, "src").path}")
append(" -jdkVersion 8")
append(" -analysisPlatform jvm")
append(" -reportUndocumented")
append(" -skipDeprecated")
}
)
.redirectErrorStream(true)
.start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
val extensionLoadedRegex = Regex("""Extension: org\.jetbrains\.dokka\.base\.DokkaBase""")
val amountOfExtensionsLoaded = extensionLoadedRegex.findAll(result.output).count()
assertTrue(
amountOfExtensionsLoaded > 10,
"Expected more than 10 extensions being present (found $amountOfExtensionsLoaded)"
)
val undocumentedReportRegex = Regex("""Undocumented:""")
val amountOfUndocumentedReports = undocumentedReportRegex.findAll(result.output).count()
assertTrue(
amountOfUndocumentedReports > 0,
"Expected at least one report of undocumented code (found $amountOfUndocumentedReports)"
)
assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")
val imagesDir = File(dokkaOutputDir, "images")
assertTrue(imagesDir.isDirectory, "Missing images directory")
val scriptsDir = File(dokkaOutputDir, "scripts")
assertTrue(scriptsDir.isDirectory, "Missing scripts directory")
val stylesDir = File(dokkaOutputDir, "styles")
assertTrue(stylesDir.isDirectory, "Missing styles directory")
val navigationHtml = File(dokkaOutputDir, "navigation.html")
assertTrue(navigationHtml.isFile, "Missing navigation.html")
projectDir.allHtmlFiles().forEach { file ->
assertContainsNoErrorClass(file)
assertNoUnresolvedLinks(file)
assertNoEmptyLinks(file)
assertNoEmptySpans(file)
}
assertContentVisibility(
contentFiles = projectDir.allHtmlFiles().toList(),
documentPublic = true,
documentInternal = false,
documentProtected = false,
documentPrivate = false
)
assertFalse(
projectDir.resolve("output").resolve("index.html").readText().contains("emptypackagetest"),
"Expected not to render empty packages"
)
}
@Test
fun failCli() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-moduleName", "Basic Project",
"-failOnWarning",
"-sourceSet",
buildString {
append(" -sourceSetName cliMain")
append(" -src ${File(projectDir, "src").path}")
append(" -jdkVersion 8")
append(" -analysisPlatform jvm")
append(" -reportUndocumented")
}
)
.redirectErrorStream(true)
.start()
val result = process.awaitProcessResult()
assertEquals(1, result.exitCode, "Expected exitCode 1 (Fail)")
assertTrue(result.output.contains("Exception in thread \"main\" org.jetbrains.dokka.DokkaException: Failed with warningCount"))
}
@Test
fun emptyPackagesTest() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-moduleName", "Basic Project",
"-sourceSet",
buildString {
append(" -sourceSetName cliMain")
append(" -src ${File(projectDir, "src").path}")
append(" -jdkVersion 8")
append(" -analysisPlatform jvm")
append(" -noSkipEmptyPackages")
}
)
.redirectErrorStream(true)
.start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
assertTrue(
projectDir.resolve("output").resolve("index.html").readText().contains("emptypackagetest"),
"Expected to render empty packages"
)
}
@Test
fun `module name should be optional`() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-loggingLevel", "DEBUG",
"-pluginsClasspath", basePluginJarFile.path,
"-sourceSet",
buildString {
append(" -src ${File(projectDir, "src").path}")
}
)
.redirectErrorStream(true)
.start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
assertTrue(result.output.contains("Loaded plugins: "), "Expected output to not contain info logs")
assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")
val imagesDir = File(dokkaOutputDir, "images")
assertTrue(imagesDir.isDirectory, "Missing images directory")
val scriptsDir = File(dokkaOutputDir, "scripts")
assertTrue(scriptsDir.isDirectory, "Missing scripts directory")
val stylesDir = File(dokkaOutputDir, "styles")
assertTrue(stylesDir.isDirectory, "Missing styles directory")
val navigationHtml = File(dokkaOutputDir, "navigation.html")
assertTrue(navigationHtml.isFile, "Missing navigation.html")
}
@Test
fun `logging level should be respected`() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-loggingLevel", "WARN",
"-pluginsClasspath", basePluginJarFile.path,
"-sourceSet",
buildString {
append(" -src ${File(projectDir, "src").path}")
}
)
.redirectErrorStream(true)
.start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
assertFalse(result.output.contains("Loaded plugins: "), "Expected output to not contain info logs")
}
@Test
fun `custom documented visibility`() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-moduleName", "Basic Project",
"-sourceSet",
buildString {
append(" -sourceSetName cliMain")
append(" -src ${File(projectDir, "src").path}")
append(" -jdkVersion 8")
append(" -analysisPlatform jvm")
append(" -documentedVisibilities PUBLIC;PROTECTED")
append(" -perPackageOptions it.overriddenVisibility.*,+visibility:PRIVATE")
}
)
.redirectErrorStream(true)
.start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
val allHtmlFiles = projectDir.allHtmlFiles().toList()
assertContentVisibility(
contentFiles = allHtmlFiles,
documentPublic = true,
documentProtected = true, // sourceSet documentedVisibilities
documentInternal = false,
documentPrivate = true // for overriddenVisibility package
)
assertContainsFilePaths(
outputFiles = allHtmlFiles,
expectedFilePaths = listOf(
// documentedVisibilities is overridden for package `overriddenVisibility` specifically
// to include private code, so html pages for it are expected to have been created
Regex("it\\.overriddenVisibility/-visible-private-class/private-method\\.html"),
Regex("it\\.overriddenVisibility/-visible-private-class/private-val\\.html"),
)
)
}
@Test
fun json() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val jsonPath = javaClass.getResource("/my-file.json")?.path ?: throw IllegalStateException("No JSON found!")
PrintWriter(jsonPath).run {
write(jsonBuilder(dokkaOutputDir.path, basePluginJarFile.path, File(projectDir, "src").path, reportUndocumented = true))
close()
}
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path, jsonPath
).redirectErrorStream(true).start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
val extensionLoadedRegex = Regex("""Extension: org\.jetbrains\.dokka\.base\.DokkaBase""")
val amountOfExtensionsLoaded = extensionLoadedRegex.findAll(result.output).count()
assertTrue(
amountOfExtensionsLoaded > 10,
"Expected more than 10 extensions being present (found $amountOfExtensionsLoaded)"
)
val undocumentedReportRegex = Regex("""Undocumented:""")
val amountOfUndocumentedReports = undocumentedReportRegex.findAll(result.output).count()
assertTrue(
amountOfUndocumentedReports > 0,
"Expected at least one report of undocumented code (found $amountOfUndocumentedReports)"
)
assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")
}
/**
* This test disables global `reportUndocumneted` property and set `reportUndocumented` via perPackageOptions to
* make sure that global settings apply to dokka context.
*/
@Test
fun jsonWithGlobals() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val jsonPath = javaClass.getResource("/my-file.json")?.path ?: throw IllegalStateException("No JSON found!")
PrintWriter(jsonPath).run {
write(
jsonBuilder(
outputPath = dokkaOutputDir.path,
pluginsClasspath = basePluginJarFile.path,
projectPath = File(projectDir, "src").path,
globalSourceLinks = """
{
"localDirectory": "/home/Vadim.Mishenev/dokka/examples/cli/src/main/kotlin",
"remoteUrl": "https://github.com/Kotlin/dokka/tree/master/examples/gradle/dokka-gradle-example/src/main/kotlin",
"remoteLineSuffix": "#L"
}
""".trimIndent(),
globalExternalDocumentationLinks = """
{
"url": "https://docs.oracle.com/javase/8/docs/api/",
"packageListUrl": "https://docs.oracle.com/javase/8/docs/api/package-list"
},
{
"url": "https://kotlinlang.org/api/latest/jvm/stdlib/",
"packageListUrl": "https://kotlinlang.org/api/latest/jvm/stdlib/package-list"
}
""".trimIndent(),
globalPerPackageOptions = """
{
"matchingRegex": ".*",
"skipDeprecated": "true",
"reportUndocumented": "true",
"documentedVisibilities": ["PUBLIC", "PRIVATE", "PROTECTED", "INTERNAL", "PACKAGE"]
}
""".trimIndent(),
reportUndocumented = false
),
)
close()
}
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path, jsonPath
).redirectErrorStream(true).start()
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
val extensionLoadedRegex = Regex("""Extension: org\.jetbrains\.dokka\.base\.DokkaBase""")
val amountOfExtensionsLoaded = extensionLoadedRegex.findAll(result.output).count()
assertTrue(
amountOfExtensionsLoaded > 10,
"Expected more than 10 extensions being present (found $amountOfExtensionsLoaded)"
)
val undocumentedReportRegex = Regex("""Undocumented:""")
val amountOfUndocumentedReports = undocumentedReportRegex.findAll(result.output).count()
assertTrue(
amountOfUndocumentedReports > 0,
"Expected at least one report of undocumented code (found $amountOfUndocumentedReports)"
)
assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")
}
}