aboutsummaryrefslogtreecommitdiff
path: root/core/test-api
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2022-04-28 13:59:57 +0300
committerGitHub <noreply@github.com>2022-04-28 13:59:57 +0300
commit2e88c6f70feff1edb9f386110a071df897f3b319 (patch)
tree07947e3c1c7cbcacd3bc6d074ba744f83ec9bdbd /core/test-api
parent2aabdea6113da6cb50edf18afb146b7120071e68 (diff)
downloaddokka-2e88c6f70feff1edb9f386110a071df897f3b319.tar.gz
dokka-2e88c6f70feff1edb9f386110a071df897f3b319.tar.bz2
dokka-2e88c6f70feff1edb9f386110a071df897f3b319.zip
Fix suddenly appearing all-modules-page/index.md file (#2475)
* Fix suddenly appearing all-modules-page/index.md file * Add a kdoc for `useOutputLocationFromConfig` param
Diffstat (limited to 'core/test-api')
-rw-r--r--core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt43
1 files changed, 28 insertions, 15 deletions
diff --git a/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt b/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt
index de0cd896..44353535 100644
--- a/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt
+++ b/core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt
@@ -28,22 +28,28 @@ abstract class AbstractTest<M : TestMethods, T : TestBuilder<M>, D : DokkaTestGe
File("src/test/resources/$name").takeIf { it.exists() }?.toPath()
?: throw InvalidPathException(name, "Cannot be found")
+ /**
+ * @param useOutputLocationFromConfig if set to true, output location specified in [DokkaConfigurationImpl.outputDir]
+ * will be used. If set to false, a temporary folder will be used instead.
+ */
protected fun testFromData(
configuration: DokkaConfigurationImpl,
cleanupOutput: Boolean = true,
- preserveOutputLocation: Boolean = false,
+ useOutputLocationFromConfig: Boolean = false,
pluginOverrides: List<DokkaPlugin> = emptyList(),
block: T.() -> Unit
) {
val testMethods = testBuilder().apply(block).build()
- val configurationToUse = if (!preserveOutputLocation) {
- val tempDir = getTempDir(cleanupOutput)
- if (!cleanupOutput)
- logger.info("Output generated under: ${tempDir.root.absolutePath}")
- configuration.copy(
- outputDir = tempDir.root
- )
- } else configuration
+ val configurationToUse =
+ if (useOutputLocationFromConfig) {
+ configuration
+ } else {
+ val tempDir = getTempDir(cleanupOutput)
+ if (!cleanupOutput) {
+ logger.info("Output generated under: ${tempDir.root.absolutePath}")
+ }
+ configuration.copy(outputDir = tempDir.root)
+ }
dokkaTestGenerator(
configurationToUse,
@@ -131,12 +137,19 @@ abstract class AbstractTest<M : TestMethods, T : TestBuilder<M>, D : DokkaTestGe
Files.write(file, content.toByteArray(charset))
}
- private fun getTempDir(cleanupOutput: Boolean) = if (cleanupOutput) {
- TemporaryFolder().apply { create() }
- } else {
- object : TemporaryFolder() {
- override fun after() {}
- }.apply { create() }
+ private fun getTempDir(cleanupOutput: Boolean) =
+ if (cleanupOutput) {
+ TemporaryFolder().apply { create() }
+ } else {
+ TemporaryFolderWithoutCleanup().apply { create() }
+ }
+
+ /**
+ * Creates a temporary folder, but doesn't delete files
+ * right after it's been used, delegating it to the OS
+ */
+ private class TemporaryFolderWithoutCleanup : TemporaryFolder() {
+ override fun after() { }
}
protected fun dokkaConfiguration(block: TestDokkaConfigurationBuilder.() -> Unit): DokkaConfigurationImpl =