diff options
author | Szymon Świstun <sswistun@virtuslab.com> | 2020-01-21 16:19:18 +0100 |
---|---|---|
committer | Szymon Świstun <sswistun@virtuslab.com> | 2020-01-22 10:58:24 +0100 |
commit | 154c3f0d83ea5f9990a06962ba8cfc36a832e04d (patch) | |
tree | 65be9c6323abd91e824bff5c8b54f11fb4192e61 /core/src | |
parent | 4417ab37e0e16663bde81efd5207c0e1929b881a (diff) | |
download | dokka-154c3f0d83ea5f9990a06962ba8cfc36a832e04d.tar.gz dokka-154c3f0d83ea5f9990a06962ba8cfc36a832e04d.tar.bz2 dokka-154c3f0d83ea5f9990a06962ba8cfc36a832e04d.zip |
tests moved to :testApi module
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/DokkaGenerator.kt | 17 | ||||
-rw-r--r-- | core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt | 2 | ||||
-rw-r--r-- | core/src/test/kotlin/testRunner/DokkaTestGenerator.kt | 41 | ||||
-rw-r--r-- | core/src/test/kotlin/testRunner/TestRunner.kt | 206 |
4 files changed, 9 insertions, 257 deletions
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 06de6c27..036cbfda 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -7,7 +7,6 @@ import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.single -import org.jetbrains.dokka.renderers.FileWriter import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity @@ -51,43 +50,43 @@ class DokkaGenerator( render(transformedPages, context) } - internal fun setUpAnalysis(configuration: DokkaConfiguration): Map<PlatformData, EnvironmentAndFacade> = + fun setUpAnalysis(configuration: DokkaConfiguration): Map<PlatformData, EnvironmentAndFacade> = configuration.passesConfigurations.map { PlatformData(it.moduleName, it.analysisPlatform, it.targets) to createEnvironmentAndFacade(it) }.toMap() - internal fun initializePlugins( + fun initializePlugins( configuration: DokkaConfiguration, logger: DokkaLogger, platforms: Map<PlatformData, EnvironmentAndFacade> ) = DokkaContext.create(configuration, logger, platforms) - internal fun createDocumentationModels( + fun createDocumentationModels( platforms: Map<PlatformData, EnvironmentAndFacade>, context: DokkaContext ) = platforms.map { (pdata, _) -> translateDescriptors(pdata, context) } - internal fun mergeDocumentationModels( + fun mergeDocumentationModels( modulesFromPlatforms: List<Module>, context: DokkaContext ) = context.single(CoreExtensions.documentationMerger).invoke(modulesFromPlatforms, context) - internal fun transformDocumentationModel( + fun transformDocumentationModel( documentationModel: Module, context: DokkaContext ) = context[CoreExtensions.documentationTransformer].fold(documentationModel) { acc, t -> t(acc, context) } - internal fun createPages( + fun createPages( transformedDocumentation: Module, context: DokkaContext ) = context.single(CoreExtensions.documentationToPageTranslator).invoke(transformedDocumentation, context) - internal fun transformPages( + fun transformPages( pages: ModulePageNode, context: DokkaContext ) = context[CoreExtensions.pageTransformer].fold(pages) { acc, t -> t(acc, context) } - internal fun render( + fun render( transformedPages: ModulePageNode, context: DokkaContext ) { diff --git a/core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt b/core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt index da5103c2..ad165cdb 100644 --- a/core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt +++ b/core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt @@ -1,7 +1,7 @@ package multiplatform import org.junit.Test -import testRunner.AbstractCoreTest +import testApi.testRunner.AbstractCoreTest import kotlin.test.assertEquals class BasicMultiplatformTest : AbstractCoreTest() { diff --git a/core/src/test/kotlin/testRunner/DokkaTestGenerator.kt b/core/src/test/kotlin/testRunner/DokkaTestGenerator.kt deleted file mode 100644 index 840ab10e..00000000 --- a/core/src/test/kotlin/testRunner/DokkaTestGenerator.kt +++ /dev/null @@ -1,41 +0,0 @@ -package testRunner - -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.DokkaGenerator -import org.jetbrains.dokka.EnvironmentAndFacade -import org.jetbrains.dokka.pages.PlatformData -import org.jetbrains.dokka.utilities.DokkaLogger - -internal class DokkaTestGenerator( - private val configuration: DokkaConfiguration, - private val logger: DokkaLogger, - private val testMethods: TestMethods -) { - - fun generate() = with(testMethods) { - val dokkaGenerator = DokkaGenerator(configuration, logger) - - val platforms: Map<PlatformData, EnvironmentAndFacade> = dokkaGenerator.setUpAnalysis(configuration) - analysisSetupStage(platforms) - - val context = dokkaGenerator.initializePlugins(configuration, logger, platforms) - pluginsSetupStage(context) - - val modulesFromPlatforms = dokkaGenerator.createDocumentationModels(platforms, context) - documentablesCreationStage(modulesFromPlatforms) - - val documentationModel = dokkaGenerator.mergeDocumentationModels(modulesFromPlatforms, context) - documentablesMergingStage(documentationModel) - - val transformedDocumentation = dokkaGenerator.transformDocumentationModel(documentationModel, context) - documentablesTransformationStage(transformedDocumentation) - - val pages = dokkaGenerator.createPages(transformedDocumentation, context) - pagesGenerationStage(pages) - - val transformedPages = dokkaGenerator.transformPages(pages, context) - pagesTransformationStage(transformedPages) - - dokkaGenerator.render(transformedPages, context) - } -}
\ No newline at end of file diff --git a/core/src/test/kotlin/testRunner/TestRunner.kt b/core/src/test/kotlin/testRunner/TestRunner.kt deleted file mode 100644 index a2b0f96c..00000000 --- a/core/src/test/kotlin/testRunner/TestRunner.kt +++ /dev/null @@ -1,206 +0,0 @@ -package testRunner - -import org.jetbrains.dokka.* -import org.jetbrains.dokka.model.Module -import org.jetbrains.dokka.pages.ModulePageNode -import org.jetbrains.dokka.pages.PlatformData -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.utilities.DokkaConsoleLogger -import org.junit.rules.TemporaryFolder -import java.io.File -import java.nio.charset.Charset -import java.nio.file.Files -import java.nio.file.InvalidPathException -import java.nio.file.Path -import java.nio.file.Paths - -// TODO: take dokka configuration from file -abstract class AbstractCoreTest { - protected val logger = DokkaConsoleLogger - - protected fun getTestDataDir(name: String) = - File("src/test/resources/$name").takeIf { it.exists() }?.toPath() - ?: throw InvalidPathException(name, "Cannot be found") - - protected fun testFromData( - configuration: DokkaConfigurationImpl, - cleanupOutput: Boolean = true, - block: TestBuilder.() -> Unit - ) { - val testMethods = TestBuilder().apply(block).build() - val tempDir = getTempDir(cleanupOutput) - if (!cleanupOutput) - logger.info("Output generated under: ${tempDir.root.absolutePath}") - val newConfiguration = - configuration.copy( - outputDir = tempDir.root.toPath().toAbsolutePath().toString() - ) - DokkaTestGenerator(newConfiguration, logger, testMethods).generate() - } - - protected fun testInline( - query: String, - configuration: DokkaConfigurationImpl, - cleanupOutput: Boolean = true, - block: TestBuilder.() -> Unit - ) { - val testMethods = TestBuilder().apply(block).build() - val testDirPath = getTempDir(cleanupOutput).root.toPath() - val fileMap = query.toFileMap() - fileMap.materializeFiles(testDirPath.toAbsolutePath()) - if (!cleanupOutput) - logger.info("Output generated under: ${testDirPath.toAbsolutePath()}") - val newConfiguration = - configuration.copy( - outputDir = testDirPath.toAbsolutePath().toString(), - passesConfigurations = configuration.passesConfigurations - .map { it.copy(sourceRoots = it.sourceRoots.map { it.copy(path = "${testDirPath.toAbsolutePath()}/${it.path}") }) } - ) - DokkaTestGenerator(newConfiguration, logger, testMethods).generate() - } - - private fun String.toFileMap(): Map<String, String> = this.replace("\r\n", "\n") - .split("\n/") - .map { fileString -> - fileString.split("\n", limit = 2) - .let { - it.first().trim().removePrefix("/") to it.last().trim() - } - }.toMap() - - private fun Map<String, String>.materializeFiles( - root: Path = Paths.get("."), - charset: Charset = Charset.forName("utf-8") - ) = this.map { (path, content) -> - val file = root.resolve(path) - Files.createDirectories(file.parent) - Files.write(file, content.toByteArray(charset)) - } - - private fun getTempDir(cleanupOutput: Boolean) = if (cleanupOutput) { - TemporaryFolder().apply { create() } - } else { - object : TemporaryFolder() { - override fun after() {} - }.apply { create() } - } - - protected class TestBuilder { - var analysisSetupStage: (Map<PlatformData, EnvironmentAndFacade>) -> Unit = {} - var pluginsSetupStage: (DokkaContext) -> Unit = {} - var documentablesCreationStage: (List<Module>) -> Unit = {} - var documentablesMergingStage: (Module) -> Unit = {} - var documentablesTransformationStage: (Module) -> Unit = {} - var pagesGenerationStage: (ModulePageNode) -> Unit = {} - var pagesTransformationStage: (ModulePageNode) -> Unit = {} - - fun build() = TestMethods( - analysisSetupStage, - pluginsSetupStage, - documentablesCreationStage, - documentablesMergingStage, - documentablesTransformationStage, - pagesGenerationStage, - pagesTransformationStage - ) - } - - protected fun dokkaConfiguration(block: DokkaConfigurationBuilder.() -> Unit): DokkaConfigurationImpl = - DokkaConfigurationBuilder().apply(block).build() - - @DslMarker - protected annotation class DokkaConfigurationDsl - - @DokkaConfigurationDsl - protected class DokkaConfigurationBuilder { - var outputDir: String = "out" - var format: String = "html" - var generateIndexPages: Boolean = true - var cacheRoot: String? = null - var pluginsClasspath: List<File> = emptyList() - private val passesConfigurations = mutableListOf<PassConfigurationImpl>() - - fun build() = DokkaConfigurationImpl( - outputDir = outputDir, - format = format, - generateIndexPages = generateIndexPages, - cacheRoot = cacheRoot, - impliedPlatforms = emptyList(), - passesConfigurations = passesConfigurations, - pluginsClasspath = pluginsClasspath - ) - - fun passes(block: Passes.() -> Unit) { - passesConfigurations.addAll(Passes().apply(block)) - } - } - - @DokkaConfigurationDsl - protected class Passes : ArrayList<PassConfigurationImpl>() { - fun pass(block: DokkaPassConfigurationBuilder.() -> Unit) = - add(DokkaPassConfigurationBuilder().apply(block).build()) - } - - @DokkaConfigurationDsl - protected class DokkaPassConfigurationBuilder( - var moduleName: String = "root", - var classpath: List<String> = emptyList(), - var sourceRoots: List<String> = emptyList(), - var samples: List<String> = emptyList(), - var includes: List<String> = emptyList(), - var includeNonPublic: Boolean = true, - var includeRootPackage: Boolean = true, - var reportUndocumented: Boolean = false, - var skipEmptyPackages: Boolean = false, - var skipDeprecated: Boolean = false, - var jdkVersion: Int = 6, - var languageVersion: String? = null, - var apiVersion: String? = null, - var noStdlibLink: Boolean = false, - var noJdkLink: Boolean = false, - var suppressedFiles: List<String> = emptyList(), - var collectInheritedExtensionsFromLibraries: Boolean = true, - var analysisPlatform: String = "jvm", - var targets: List<String> = listOf("jvm"), - var sinceKotlin: String? = null, - var perPackageOptions: List<PackageOptionsImpl> = emptyList(), - var externalDocumentationLinks: List<ExternalDocumentationLinkImpl> = emptyList(), - var sourceLinks: List<SourceLinkDefinitionImpl> = emptyList() - ) { - fun build() = PassConfigurationImpl( - moduleName = moduleName, - classpath = classpath, - sourceRoots = sourceRoots.map { SourceRootImpl(it) }, - samples = samples, - includes = includes, - includeNonPublic = includeNonPublic, - includeRootPackage = includeRootPackage, - reportUndocumented = reportUndocumented, - skipEmptyPackages = skipEmptyPackages, - skipDeprecated = skipDeprecated, - jdkVersion = jdkVersion, - languageVersion = languageVersion, - apiVersion = apiVersion, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, - suppressedFiles = suppressedFiles, - collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries, - analysisPlatform = Platform.fromString(analysisPlatform), - targets = targets, - sinceKotlin = sinceKotlin, - perPackageOptions = perPackageOptions, - externalDocumentationLinks = externalDocumentationLinks, - sourceLinks = sourceLinks - ) - } -} - -data class TestMethods( - val analysisSetupStage: (Map<PlatformData, EnvironmentAndFacade>) -> Unit, - val pluginsSetupStage: (DokkaContext) -> Unit, - val documentablesCreationStage: (List<Module>) -> Unit, - val documentablesMergingStage: (Module) -> Unit, - val documentablesTransformationStage: (Module) -> Unit, - val pagesGenerationStage: (ModulePageNode) -> Unit, - val pagesTransformationStage: (ModulePageNode) -> Unit -)
\ No newline at end of file |