aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/base-test-utils/src/main/kotlin/testRunner/baseTestApi.kt
blob: 25f6656e23294b17b42e2c848f712b1fb01d23a5 (plain)
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
package org.jetbrains.dokka.base.testApi.testRunner

import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaGenerator
import org.jetbrains.dokka.base.generation.SingleModuleGeneration
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.testApi.logger.TestLogger
import org.jetbrains.dokka.testApi.testRunner.*
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.utilities.LoggingLevel

class BaseDokkaTestGenerator(
    configuration: DokkaConfiguration,
    logger: DokkaLogger,
    testMethods: BaseTestMethods,
    additionalPlugins: List<DokkaPlugin> = emptyList()
) : DokkaTestGenerator<BaseTestMethods>(configuration, logger, testMethods, additionalPlugins) {

    override fun generate() = with(testMethods) {
        val dokkaGenerator = DokkaGenerator(configuration, logger)

        val context =
            dokkaGenerator.initializePlugins(configuration, logger, additionalPlugins)
        pluginsSetupStage(context)

        val singleModuleGeneration = context.single(CoreExtensions.generation) as SingleModuleGeneration

        val modulesFromPlatforms = singleModuleGeneration.createDocumentationModels()
        documentablesCreationStage(modulesFromPlatforms)

        verificationStage { singleModuleGeneration.validityCheck(context) }

        val filteredModules = singleModuleGeneration.transformDocumentationModelBeforeMerge(modulesFromPlatforms)
        documentablesFirstTransformationStep(filteredModules)

        val documentationModel = singleModuleGeneration.mergeDocumentationModels(filteredModules)
        documentablesMergingStage(documentationModel!!)

        val transformedDocumentation = singleModuleGeneration.transformDocumentationModelAfterMerge(documentationModel)
        documentablesTransformationStage(transformedDocumentation)

        val pages = singleModuleGeneration.createPages(transformedDocumentation)
        pagesGenerationStage(pages)

        val transformedPages = singleModuleGeneration.transformPages(pages)
        pagesTransformationStage(transformedPages)

        singleModuleGeneration.render(transformedPages)
        renderingStage(transformedPages, context)

        singleModuleGeneration.reportAfterRendering()
    }
}

data class BaseTestMethods(
    override val pluginsSetupStage: (DokkaContext) -> Unit,
    override val verificationStage: (() -> Unit) -> Unit,
    override val documentablesCreationStage: (List<DModule>) -> Unit,
    val documentablesFirstTransformationStep: (List<DModule>) -> Unit,
    override val documentablesMergingStage: (DModule) -> Unit,
    override val documentablesTransformationStage: (DModule) -> Unit,
    override val pagesGenerationStage: (RootPageNode) -> Unit,
    override val pagesTransformationStage: (RootPageNode) -> Unit,
    override val renderingStage: (RootPageNode, DokkaContext) -> Unit
) : CoreTestMethods(
    pluginsSetupStage,
    verificationStage,
    documentablesCreationStage,
    documentablesMergingStage,
    documentablesTransformationStage,
    pagesGenerationStage,
    pagesTransformationStage,
    renderingStage,
)

class BaseTestBuilder : TestBuilder<BaseTestMethods>() {
    var pluginsSetupStage: (DokkaContext) -> Unit = {}
    var verificationStage: (() -> Unit) -> Unit = {}
    var documentablesCreationStage: (List<DModule>) -> Unit = {}
    var preMergeDocumentablesTransformationStage: (List<DModule>) -> Unit = {}
    var documentablesMergingStage: (DModule) -> Unit = {}
    var documentablesTransformationStage: (DModule) -> Unit = {}
    var pagesGenerationStage: (RootPageNode) -> Unit = {}
    var pagesTransformationStage: (RootPageNode) -> Unit = {}
    var renderingStage: (RootPageNode, DokkaContext) -> Unit = { _, _ -> }

    override fun build() = BaseTestMethods(
        pluginsSetupStage,
        verificationStage,
        documentablesCreationStage,
        preMergeDocumentablesTransformationStage,
        documentablesMergingStage,
        documentablesTransformationStage,
        pagesGenerationStage,
        pagesTransformationStage,
        renderingStage
    )
}

abstract class BaseAbstractTest(logger: TestLogger = TestLogger(DokkaConsoleLogger(LoggingLevel.DEBUG))) : AbstractTest<BaseTestMethods, BaseTestBuilder, BaseDokkaTestGenerator>(
    ::BaseTestBuilder,
    ::BaseDokkaTestGenerator,
    logger,
)