Skip to content

Commit

Permalink
Fix suddenly appearing all-modules-page/index.md file (#2475)
Browse files Browse the repository at this point in the history
* Fix suddenly appearing all-modules-page/index.md file

* Add a kdoc for `useOutputLocationFromConfig` param
  • Loading branch information
IgnatBeresnev committed Apr 28, 2022
1 parent 2aabdea commit 2e88c6f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
43 changes: 28 additions & 15 deletions core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MultiModuleDocumentationTest : MultiModuleAbstractTest() {
includes = listOf(folder.root.resolve("README.md"))
}

testFromData(configuration, preserveOutputLocation = true) {
testFromData(configuration) {
allModulesPageCreationStage = { rootPage ->
(rootPage as? MultimoduleRootPageNode)?.content?.dfs { it.dci.kind == ContentKind.Cover }?.children?.firstOrNull()
?.assertNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() {
val contentFile = setup(link)
val configuration = configuration()

testFromData(configuration, preserveOutputLocation = true) {
testFromData(configuration, useOutputLocationFromConfig = true) {
finishProcessingSubmodules = {
assertHtmlEqualsIgnoringWhitespace(expected, contentFile.readText())
}
Expand Down Expand Up @@ -88,7 +88,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() {
val contentFile = setup(link)
val configuration = configuration()

testFromData(configuration, preserveOutputLocation = true) {
testFromData(configuration, useOutputLocationFromConfig = true) {
finishProcessingSubmodules = {
assertHtmlEqualsIgnoringWhitespace(expected, contentFile.readText())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ResolveLinkGfmCommandResolutionTest : MultiModuleAbstractTest() {
val content = setup(link)
val configuration = configuration()

testFromData(configuration, pluginOverrides = listOf(GfmTemplateProcessingPlugin(), GfmPlugin()), preserveOutputLocation = true) {
testFromData(configuration, pluginOverrides = listOf(GfmTemplateProcessingPlugin(), GfmPlugin()), useOutputLocationFromConfig = true) {
finishProcessingSubmodules = {
assertEquals(expected, content.readText().trim())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AddToNavigationCommandResolutionTest : TemplatingAbstractTest() {
val module2Navigation = module2.resolve("navigation.html")
module2Navigation.writeText(inputForModule("module2"))

testFromData(configuration, preserveOutputLocation = true) {
testFromData(configuration, useOutputLocationFromConfig = true) {
finishProcessingSubmodules = { ctx ->
test(ctx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AddToSearchCommandResolutionTest : TemplatingAbstractTest() {
this.outputDir = outputDir
}

testFromData(configuration, preserveOutputLocation = true) {
testFromData(configuration, useOutputLocationFromConfig = true) {
finishProcessingSubmodules = { _ ->
val expected = elements.map { it.copy(location = "module1/${it.location}") } +
elements.map { it.copy(location = "module2/${it.location}") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class SubstitutionCommandResolutionTest : TemplatingAbstractTest() {
this.outputDir = folder.root
}

testFromData(configuration, preserveOutputLocation = true){
testFromData(configuration, useOutputLocationFromConfig = true){
finishProcessingSubmodules = {
assertHtmlEqualsIgnoringWhitespace(expected, testedFile.readText())
}
Expand Down

0 comments on commit 2e88c6f

Please sign in to comment.