From 2e88c6f70feff1edb9f386110a071df897f3b319 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 28 Apr 2022 13:59:57 +0300 Subject: 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 --- .../main/kotlin/testApi/testRunner/TestRunner.kt | 43 ++++++++++++++-------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'core/test-api/src/main') 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, 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 = 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, 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 = -- cgit