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 | |
parent | 4417ab37e0e16663bde81efd5207c0e1929b881a (diff) | |
download | dokka-154c3f0d83ea5f9990a06962ba8cfc36a832e04d.tar.gz dokka-154c3f0d83ea5f9990a06962ba8cfc36a832e04d.tar.bz2 dokka-154c3f0d83ea5f9990a06962ba8cfc36a832e04d.zip |
tests moved to :testApi module
-rw-r--r-- | core/build.gradle | 1 | ||||
-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/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt | 81 | ||||
-rw-r--r-- | core/testApi/src/main/kotlin/testApi/TestAPI.kt | 353 | ||||
-rw-r--r-- | plugins/build.gradle | 6 | ||||
-rw-r--r-- | plugins/javadoc8/build.gradle | 2 | ||||
-rw-r--r-- | settings.gradle | 3 | ||||
-rw-r--r-- | testApi/build.gradle (renamed from core/testApi/build.gradle) | 10 | ||||
-rw-r--r-- | testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt (renamed from core/src/test/kotlin/testRunner/DokkaTestGenerator.kt) | 2 | ||||
-rw-r--r-- | testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt (renamed from core/src/test/kotlin/testRunner/TestRunner.kt) | 5 |
11 files changed, 31 insertions, 451 deletions
diff --git a/core/build.gradle b/core/build.gradle index 23e2ff24..31833cf9 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -21,6 +21,7 @@ allprojects { } dependencies { + testCompile project(':testApi') compile project(":integration") compile project(path: ":coreDependencies", configuration: "shadow") 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/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt b/core/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt deleted file mode 100644 index 58356e27..00000000 --- a/core/testApi/src/main/kotlin/testApi/DokkaConfigurationTestImplementations.kt +++ /dev/null @@ -1,81 +0,0 @@ -package org.jetbrains.dokka.testApi - -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.Platform -import java.io.File - - -data class SourceLinkDefinitionImpl(override val path: String, - override val url: String, - override val lineSuffix: String?) : DokkaConfiguration.SourceLinkDefinition { - companion object { - fun parseSourceLinkDefinition(srcLink: String): DokkaConfiguration.SourceLinkDefinition { - val (path, urlAndLine) = srcLink.split('=') - return SourceLinkDefinitionImpl( - File(path).canonicalPath, - urlAndLine.substringBefore("#"), - urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" }) - } - } -} - -class SourceRootImpl(path: String) : DokkaConfiguration.SourceRoot { - override val path: String = File(path).absolutePath - - companion object { - fun parseSourceRoot(sourceRoot: String): DokkaConfiguration.SourceRoot = SourceRootImpl(sourceRoot) - } -} - -data class PackageOptionsImpl(override val prefix: String, - override val includeNonPublic: Boolean = false, - override val reportUndocumented: Boolean = true, - override val skipDeprecated: Boolean = false, - override val suppress: Boolean = false) : DokkaConfiguration.PackageOptions - - class DokkaConfigurationImpl( - override val outputDir: String = "", - override val format: String = "html", - override val generateIndexPages: Boolean = false, - override val cacheRoot: String? = null, - override val impliedPlatforms: List<String> = emptyList(), - override val passesConfigurations: List<DokkaConfiguration.PassConfiguration> = emptyList() -) : DokkaConfiguration - -class PassConfigurationImpl ( - override val classpath: List<String> = emptyList(), - override val moduleName: String = "", - override val sourceRoots: List<DokkaConfiguration.SourceRoot> = emptyList(), - override val samples: List<String> = emptyList(), - override val includes: List<String> = emptyList(), - override val includeNonPublic: Boolean = false, - override val includeRootPackage: Boolean = false, - override val reportUndocumented: Boolean = false, - override val skipEmptyPackages: Boolean = false, - override val skipDeprecated: Boolean = false, - override val jdkVersion: Int = 6, - override val sourceLinks: List<DokkaConfiguration.SourceLinkDefinition> = emptyList(), - override val perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(), - externalDocumentationLinks: List<DokkaConfiguration.ExternalDocumentationLink> = emptyList(), - override val languageVersion: String? = null, - override val apiVersion: String? = null, - override val noStdlibLink: Boolean = false, - override val noJdkLink: Boolean = false, - override val suppressedFiles: List<String> = emptyList(), - override val collectInheritedExtensionsFromLibraries: Boolean = false, - override val analysisPlatform: Platform = Platform.DEFAULT, - override val targets: List<String> = emptyList(), - override val sinceKotlin: String? = null -): DokkaConfiguration.PassConfiguration { - private val defaultLinks = run { - val links = mutableListOf<DokkaConfiguration.ExternalDocumentationLink>() - if (!noJdkLink) - links += DokkaConfiguration.ExternalDocumentationLink.Builder("https://docs.oracle.com/javase/$jdkVersion/docs/api/").build() - - if (!noStdlibLink) - links += DokkaConfiguration.ExternalDocumentationLink.Builder("https://kotlinlang.org/api/latest/jvm/stdlib/").build() - links - } - override val externalDocumentationLinks = defaultLinks + externalDocumentationLinks -} - diff --git a/core/testApi/src/main/kotlin/testApi/TestAPI.kt b/core/testApi/src/main/kotlin/testApi/TestAPI.kt deleted file mode 100644 index 7856591c..00000000 --- a/core/testApi/src/main/kotlin/testApi/TestAPI.kt +++ /dev/null @@ -1,353 +0,0 @@ -package org.jetbrains.dokka.testApi - -import com.google.inject.Guice -import com.intellij.openapi.application.PathManager -import com.intellij.openapi.util.Disposer -import com.intellij.openapi.util.io.FileUtil -import com.intellij.rt.execution.junit.FileComparisonFailure -import org.jetbrains.dokka.* -import org.jetbrains.dokka.Utilities.DokkaAnalysisModule -import org.jetbrains.dokka.Utilities.DokkaRunModule -import org.jetbrains.kotlin.cli.common.config.ContentRoot -import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity -import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.utils.PathUtil -import org.junit.Assert -import org.junit.Assert.fail -import java.io.File - -data class ModelConfig( - val roots: Array<ContentRoot> = arrayOf(), - val withJdk: Boolean = false, - val withKotlinRuntime: Boolean = false, - val format: String = "html", - val includeNonPublic: Boolean = true, - val perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(), - val analysisPlatform: Platform = Platform.DEFAULT, - val defaultPlatforms: List<String> = emptyList(), - val noStdlibLink: Boolean = true, - val collectInheritedExtensionsFromLibraries: Boolean = false, - val sourceLinks: List<DokkaConfiguration.SourceLinkDefinition> = emptyList() -) - -fun verifyModel( - modelConfig: ModelConfig, - verifier: (DocumentationModule) -> Unit -) { - val documentation = DocumentationModule("test") - - val passConfiguration = PassConfigurationImpl( - includeNonPublic = modelConfig.includeNonPublic, - skipEmptyPackages = false, - includeRootPackage = true, - sourceLinks = modelConfig.sourceLinks, - perPackageOptions = modelConfig.perPackageOptions, - noStdlibLink = modelConfig.noStdlibLink, - noJdkLink = false, - languageVersion = null, - apiVersion = null, - collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries - ) - val configuration = DokkaConfigurationImpl( - outputDir = "", - format = modelConfig.format, - generateIndexPages = false, - cacheRoot = "default", - passesConfigurations = listOf(passConfiguration) - ) - - appendDocumentation(documentation, configuration, passConfiguration, modelConfig) - documentation.prepareForGeneration(configuration) - - verifier(documentation) -} - -fun appendDocumentation( - documentation: DocumentationModule, - dokkaConfiguration: DokkaConfiguration, - passConfiguration: DokkaConfiguration.PassConfiguration, - modelConfig: ModelConfig -) { - val messageCollector = object : MessageCollector { - override fun clear() { - - } - - override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { - when (severity) { - CompilerMessageSeverity.STRONG_WARNING, - CompilerMessageSeverity.WARNING, - CompilerMessageSeverity.LOGGING, - CompilerMessageSeverity.OUTPUT, - CompilerMessageSeverity.INFO, - CompilerMessageSeverity.ERROR -> { - println("$severity: $message at $location") - } - CompilerMessageSeverity.EXCEPTION -> { - fail("$severity: $message at $location") - } - } - } - - override fun hasErrors() = false - } - - val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) - environment.apply { - if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { - addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) - } - if (modelConfig.withKotlinRuntime) { - if (analysisPlatform == Platform.jvm) { - val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") - addClasspath(File(kotlinStrictfpRoot)) - } - if (analysisPlatform == Platform.js) { - val kotlinStdlibJsRoot = PathManager.getResourceRoot(Any::class.java, "/kotlin/jquery") - addClasspath(File(kotlinStdlibJsRoot)) - } - - if (analysisPlatform == Platform.common) { - // TODO: Feels hacky - val kotlinStdlibCommonRoot = ClassLoader.getSystemResource("kotlin/UInt.kotlin_metadata") - addClasspath(File(kotlinStdlibCommonRoot.file.replace("file:", "").replaceAfter(".jar", ""))) - } - } - addRoots(modelConfig.roots.toList()) - - loadLanguageVersionSettings(passConfiguration.languageVersion, passConfiguration.apiVersion) - } - val defaultPlatformsProvider = object : DefaultPlatformsProvider { - override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms - } - - val globalInjector = Guice.createInjector( - DokkaRunModule(dokkaConfiguration) - ) - - val injector = globalInjector.createChildInjector( - DokkaAnalysisModule( - environment, - dokkaConfiguration, - defaultPlatformsProvider, - documentation.nodeRefGraph, - passConfiguration, - DokkaConsoleLogger - ) - ) - - buildDocumentationModule(injector, documentation) - Disposer.dispose(environment) -} - -fun checkSourceExistsAndVerifyModel( - source: String, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationModule) -> Unit -) { - require(File(source).exists()) { - "Cannot find test data file $source" - } - verifyModel( - ModelConfig( - roots = arrayOf(contentRootFromPath(source)), - withJdk = modelConfig.withJdk, - withKotlinRuntime = modelConfig.withKotlinRuntime, - format = modelConfig.format, - includeNonPublic = modelConfig.includeNonPublic, - sourceLinks = modelConfig.sourceLinks, - analysisPlatform = modelConfig.analysisPlatform - ), - - verifier = verifier - ) -} - -fun verifyPackageMember( - source: String, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationNode) -> Unit -) { - checkSourceExistsAndVerifyModel( - source, - modelConfig = ModelConfig( - withJdk = modelConfig.withJdk, - withKotlinRuntime = modelConfig.withKotlinRuntime, - analysisPlatform = modelConfig.analysisPlatform - ) - ) { model -> - val pkg = model.members.single() - verifier(pkg.members.single()) - } -} - -fun verifyJavaModel( - source: String, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationModule) -> Unit -) { - val tempDir = FileUtil.createTempDirectory("dokka", "") - try { - val sourceFile = File(source) - FileUtil.copy(sourceFile, File(tempDir, sourceFile.name)) - verifyModel( - ModelConfig( - roots = arrayOf(JavaSourceRoot(tempDir, null)), - withJdk = true, - withKotlinRuntime = modelConfig.withKotlinRuntime, - analysisPlatform = modelConfig.analysisPlatform - ), - verifier = verifier - ) - } finally { - FileUtil.delete(tempDir) - } -} - -fun verifyJavaPackageMember( - source: String, - modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationNode) -> Unit -) { - verifyJavaModel(source, modelConfig) { model -> - val pkg = model.members.single() - verifier(pkg.members.single()) - } -} - -fun verifyOutput( - modelConfig: ModelConfig = ModelConfig(), - outputExtension: String, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - verifyModel(modelConfig) { - verifyModelOutput(it, outputExtension, modelConfig.roots.first().path, outputGenerator) - } -} - -fun verifyOutput( - path: String, - outputExtension: String, - modelConfig: ModelConfig = ModelConfig(), - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - verifyOutput( - ModelConfig( - roots = arrayOf(contentRootFromPath(path)) + modelConfig.roots, - withJdk = modelConfig.withJdk, - withKotlinRuntime = modelConfig.withKotlinRuntime, - format = modelConfig.format, - includeNonPublic = modelConfig.includeNonPublic, - analysisPlatform = modelConfig.analysisPlatform, - noStdlibLink = modelConfig.noStdlibLink, - collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries - ), - outputExtension, - outputGenerator - ) -} - -fun verifyModelOutput( - it: DocumentationModule, - outputExtension: String, - sourcePath: String, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - val output = StringBuilder() - outputGenerator(it, output) - val ext = outputExtension.removePrefix(".") - val expectedFile = File(sourcePath.replaceAfterLast(".", ext, sourcePath + "." + ext)) - assertEqualsIgnoringSeparators(expectedFile, output.toString()) -} - -fun verifyJavaOutput( - path: String, - outputExtension: String, - modelConfig: ModelConfig = ModelConfig(), - outputGenerator: (DocumentationModule, StringBuilder) -> Unit -) { - verifyJavaModel(path, modelConfig) { model -> - verifyModelOutput(model, outputExtension, path, outputGenerator) - } -} - -fun assertEqualsIgnoringSeparators(expectedFile: File, output: String) { - if (!expectedFile.exists()) expectedFile.createNewFile() - val expectedText = expectedFile.readText().replace("\r\n", "\n") - val actualText = output.replace("\r\n", "\n") - - if (expectedText != actualText) - throw FileComparisonFailure("", expectedText, actualText, expectedFile.canonicalPath) -} - -fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) { - Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n")) -} - -fun StringBuilder.appendChildren(node: ContentBlock): StringBuilder { - for (child in node.children) { - val childText = child.toTestString() - append(childText) - } - return this -} - -fun StringBuilder.appendNode(node: ContentNode): StringBuilder { - when (node) { - is ContentText -> { - append(node.text) - } - is ContentEmphasis -> append("*").appendChildren(node).append("*") - is ContentBlockCode -> { - if (node.language.isNotBlank()) - appendln("[code lang=${node.language}]") - else - appendln("[code]") - appendChildren(node) - appendln() - appendln("[/code]") - } - is ContentNodeLink -> { - append("[") - appendChildren(node) - append(" -> ") - append(node.node.toString()) - append("]") - } - is ContentBlock -> { - appendChildren(node) - } - is NodeRenderContent -> { - append("render(") - append(node.node) - append(",") - append(node.mode) - append(")") - } - is ContentSymbol -> { - append(node.text) - } - is ContentEmpty -> { /* nothing */ - } - else -> throw IllegalStateException("Don't know how to format node $node") - } - return this -} - -fun ContentNode.toTestString(): String { - val node = this - return StringBuilder().apply { - appendNode(node) - }.toString() -} - -val ContentRoot.path: String - get() = when (this) { - is KotlinSourceRoot -> path - is JavaSourceRoot -> file.path - else -> throw UnsupportedOperationException() - } diff --git a/plugins/build.gradle b/plugins/build.gradle index 55f6b014..a0bc5ee1 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -16,4 +16,10 @@ allprojects { jvmTarget = "1.8" } } +} + +subprojects { + dependencies { + testCompile project(':testApi') + } }
\ No newline at end of file diff --git a/plugins/javadoc8/build.gradle b/plugins/javadoc8/build.gradle index cc1e5c29..31bf9f41 100644 --- a/plugins/javadoc8/build.gradle +++ b/plugins/javadoc8/build.gradle @@ -9,7 +9,7 @@ dependencies { compileOnly toolsJar testCompile toolsJar - testImplementation project(":core:testApi") +// testImplementation project(":core:testApi") testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit', version: kotlin_version }
\ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 4e006020..323af4b9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,4 +12,5 @@ include 'core', 'runners:gradle-plugin', // 'plugins:javadoc8' 'plugins:mathjax', - 'plugins:xml' + 'plugins:xml', + 'testApi' diff --git a/core/testApi/build.gradle b/testApi/build.gradle index 82d0fd41..5425b7bc 100644 --- a/core/testApi/build.gradle +++ b/testApi/build.gradle @@ -1,6 +1,12 @@ +buildscript { + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} +apply plugin: 'kotlin' + dependencies { - compileOnly project(":core") + implementation project(':core') implementation group: 'junit', name: 'junit', version: '4.12' implementation group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit', version: kotlin_version - implementation ideaRT() }
\ No newline at end of file diff --git a/core/src/test/kotlin/testRunner/DokkaTestGenerator.kt b/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt index 840ab10e..50e88f2b 100644 --- a/core/src/test/kotlin/testRunner/DokkaTestGenerator.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt @@ -1,4 +1,4 @@ -package testRunner +package testApi.testRunner import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaGenerator diff --git a/core/src/test/kotlin/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index a2b0f96c..fdc2d0f7 100644 --- a/core/src/test/kotlin/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -1,4 +1,4 @@ -package testRunner +package testApi.testRunner import org.jetbrains.dokka.* import org.jetbrains.dokka.model.Module @@ -59,7 +59,8 @@ abstract class AbstractCoreTest { DokkaTestGenerator(newConfiguration, logger, testMethods).generate() } - private fun String.toFileMap(): Map<String, String> = this.replace("\r\n", "\n") + private fun String.toFileMap(): Map<String, String> = this.trimMargin().removePrefix("|") + .replace("\r\n", "\n") .split("\n/") .map { fileString -> fileString.split("\n", limit = 2) |