From 7acc52ba723eab08fe796fcfd68755e7f0eb6a66 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 2 Dec 2017 00:50:08 +0300 Subject: WIP: Refactoring, remove LocationService, rework FormatDescriptor --- core/src/test/kotlin/TestAPI.kt | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'core/src/test') diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index ff8a5260..aa3eff48 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -270,21 +270,6 @@ fun ContentNode.toTestString(): String { }.toString() } -class InMemoryLocation(override val path: String): Location { - override fun relativePathTo(other: Location, anchor: String?): String = - if (anchor != null) other.path + "#" + anchor else other.path -} - -object InMemoryLocationService: LocationService { - override fun location(qualifiedName: List, hasMembers: Boolean) = - InMemoryLocation(relativePathToNode(qualifiedName, hasMembers)) - - override val root: Location - get() = InMemoryLocation("") -} - -val tempLocation = InMemoryLocation("") - val ContentRoot.path: String get() = when(this) { is KotlinSourceRoot -> path -- cgit From e126ff625eba33d91b3242a4e6e951d1e9f94080 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 2 Dec 2017 05:59:01 +0300 Subject: Update tests to new reality --- core/src/test/kotlin/TestAPI.kt | 11 +++++ core/src/test/kotlin/format/GFMFormatTest.kt | 19 ++++++-- core/src/test/kotlin/format/HtmlFormatTest.kt | 21 +++++--- .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 21 ++++++-- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 16 +++++-- .../KotlinWebSiteRunnableSamplesFormatTest.kt | 56 +++++++++++----------- core/src/test/kotlin/format/MarkdownFormatTest.kt | 52 ++++++++++++-------- core/src/test/kotlin/format/PackageDocsTest.kt | 13 +++-- 8 files changed, 140 insertions(+), 69 deletions(-) (limited to 'core/src/test') diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index aa3eff48..4cd11390 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -276,3 +276,14 @@ val ContentRoot.path: String is JavaSourceRoot -> file.path else -> throw UnsupportedOperationException() } + + +val TestFileGenerator = FileGenerator(createTempDir()) + +fun FileGenerator.buildPagesAndReadInto(nodes: List, sb: StringBuilder) { + buildPages(nodes) + nodes.forEach { + val fileForNode = TestFileGenerator.location(it).file + sb.append(fileForNode.readText()) + } +} \ No newline at end of file diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt index c097c5c8..f5b833f6 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -2,22 +2,33 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.GFMFormatService import org.jetbrains.dokka.KotlinLanguageService +import org.junit.Before import org.junit.Test class GFMFormatTest { - private val gfmService = GFMFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) + private val gfmService = GFMFormatService(TestFileGenerator, KotlinLanguageService(), listOf()) - @Test fun sample() { + @Before + fun prepareFileGenerator() { + TestFileGenerator.formatService = gfmService + } + + @Test + fun sample() { verifyGFMNodeByName("sample", "Foo") } - @Test fun listInTableCell() { + @Test + fun listInTableCell() { verifyGFMNodeByName("listInTableCell", "Foo") } private fun verifyGFMNodeByName(fileName: String, name: String) { verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> - gfmService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) + TestFileGenerator.buildPagesAndReadInto( + model.members.single().members.filter { it.name == name }, + output + ) } } } diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt index 01e4559e..4906fbfa 100644 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -3,11 +3,17 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.junit.Before import org.junit.Test import java.io.File class HtmlFormatTest { - private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) + private val htmlService = HtmlFormatService(TestFileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) + + @Before + fun prepareFileGenerator() { + TestFileGenerator.formatService = htmlService + } @Test fun classWithCompanionObject() { verifyHtmlNode("classWithCompanionObject") @@ -31,10 +37,10 @@ class HtmlFormatTest { @Test fun deprecated() { verifyOutput("testdata/format/deprecated.kt", ".package.html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + TestFileGenerator.buildPagesAndReadInto(model.members, output) } verifyOutput("testdata/format/deprecated.kt", ".class.html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) } } @@ -102,7 +108,10 @@ class HtmlFormatTest { verifyOutput(arrayOf(KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null)), ".html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == "Bar" }) + TestFileGenerator.buildPagesAndReadInto( + model.members.single().members.filter { it.name == "Bar" }, + output + ) } } @@ -158,7 +167,7 @@ class HtmlFormatTest { withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List) { verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) } } @@ -170,7 +179,7 @@ class HtmlFormatTest { withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List) { verifyJavaOutput("testdata/format/$fileName.java", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) } } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index af44b048..b3ea82b7 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -1,12 +1,19 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.junit.Before import org.junit.Ignore import org.junit.Test @Ignore class KotlinWebSiteFormatTest { - private val kwsService = KotlinWebsiteFormatService(InMemoryLocationService, KotlinLanguageService(), listOf(), DokkaConsoleLogger) + private val kwsService = KotlinWebsiteFormatService(TestFileGenerator, KotlinLanguageService(), listOf(), DokkaConsoleLogger) + + @Before + fun prepareFileGenerator() { + TestFileGenerator.formatService = kwsService + } + @Test fun sample() { verifyKWSNodeByName("sample", "foo") @@ -29,14 +36,20 @@ class KotlinWebSiteFormatTest { val path = "dataTagsInGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/website/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode })) + TestFileGenerator.buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) } verifyMultiplatformPackage(module, path) } private fun verifyKWSNodeByName(fileName: String, name: String) { verifyOutput("testdata/format/website/$fileName.kt", ".md", format = "kotlin-website") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) + TestFileGenerator.buildPagesAndReadInto( + model.members.single().members.filter { it.name == name }, + output + ) } } @@ -58,7 +71,7 @@ class KotlinWebSiteFormatTest { private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.md", "testdata/format/website/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + TestFileGenerator.buildPagesAndReadInto(model.members, output) } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index 433c9c13..8c94fdcb 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -1,11 +1,16 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.junit.Before import org.junit.Test class KotlinWebSiteHtmlFormatTest { - private val kwsService = KotlinWebsiteHtmlFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) + private val kwsService = KotlinWebsiteHtmlFormatService(TestFileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) + @Before + fun prepareFileGenerator() { + TestFileGenerator.formatService = kwsService + } @Test fun dropImport() { verifyKWSNodeByName("dropImport", "foo") @@ -44,14 +49,17 @@ class KotlinWebSiteHtmlFormatTest { val path = "dataTagsInGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode })) + TestFileGenerator.buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) } verifyMultiplatformPackage(module, path) } private fun verifyKWSNodeByName(fileName: String, name: String) { verifyOutput("testdata/format/website-html/$fileName.kt", ".html", format = "kotlin-website-html") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) + TestFileGenerator.buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) } } @@ -73,7 +81,7 @@ class KotlinWebSiteHtmlFormatTest { private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + TestFileGenerator.buildPagesAndReadInto(model.members, output) } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt index 44155004..453b1de8 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt @@ -8,32 +8,32 @@ import org.junit.Test @Ignore class KotlinWebSiteRunnableSamplesFormatTest { - private val kwsService = KotlinWebsiteRunnableSamplesFormatService(InMemoryLocationService, KotlinLanguageService(), listOf(), DokkaConsoleLogger) - - - @Test fun dropImport() { - verifyKWSNodeByName("dropImport", "foo") - } - - @Test fun sample() { - verifyKWSNodeByName("sample", "foo") - } - - @Test fun sampleWithAsserts() { - verifyKWSNodeByName("sampleWithAsserts", "a") - } - - @Test fun newLinesInSamples() { - verifyKWSNodeByName("newLinesInSamples", "foo") - } - - @Test fun newLinesInImportList() { - verifyKWSNodeByName("newLinesInImportList", "foo") - } - - private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website-samples/$fileName.kt", ".md", format = "kotlin-website-samples") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) - } - } +// private val kwsService = KotlinWebsiteRunnableSamplesFormatService(InMemoryLocationService, KotlinLanguageService(), listOf(), DokkaConsoleLogger) +// +// +// @Test fun dropImport() { +// verifyKWSNodeByName("dropImport", "foo") +// } +// +// @Test fun sample() { +// verifyKWSNodeByName("sample", "foo") +// } +// +// @Test fun sampleWithAsserts() { +// verifyKWSNodeByName("sampleWithAsserts", "a") +// } +// +// @Test fun newLinesInSamples() { +// verifyKWSNodeByName("newLinesInSamples", "foo") +// } +// +// @Test fun newLinesInImportList() { +// verifyKWSNodeByName("newLinesInImportList", "foo") +// } +// +// private fun verifyKWSNodeByName(fileName: String, name: String) { +// verifyOutput("testdata/format/website-samples/$fileName.kt", ".md", format = "kotlin-website-samples") { model, output -> +// kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) +// } +// } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 820af361..e273f6c1 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -1,10 +1,16 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.junit.Before import org.junit.Test class MarkdownFormatTest { - private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) + private val markdownService = MarkdownFormatService(TestFileGenerator, KotlinLanguageService(), listOf()) + + @Before + fun prepareFileGenerator() { + TestFileGenerator.formatService = markdownService + } @Test fun emptyDescription() { verifyMarkdownNode("emptyDescription") @@ -34,21 +40,23 @@ class MarkdownFormatTest { @Test fun extensions() { verifyOutput("testdata/format/extensions.kt", ".package.md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + TestFileGenerator.buildPagesAndReadInto(model.members, output) } verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) } } @Test fun enumClass() { verifyOutput("testdata/format/enumClass.kt", ".md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) } verifyOutput("testdata/format/enumClass.kt", ".value.md") { model, output -> val enumClassNode = model.members.single().members[0] - markdownService.createOutputBuilder(output, tempLocation).appendNodes( - enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }) + TestFileGenerator.buildPagesAndReadInto( + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, + output + ) } } @@ -282,22 +290,22 @@ class MarkdownFormatTest { @Test fun multiplePlatformsMergeMembers() { val module = buildMultiplePlatforms("multiplatform/mergeMembers") verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) } } @Test fun multiplePlatformsOmitRedundant() { val module = buildMultiplePlatforms("multiplatform/omitRedundant") verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) } } @Test fun multiplePlatformsImplied() { val module = buildMultiplePlatforms("multiplatform/implied") verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> - MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf("JVM", "JS")) - .createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) +// MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf("JVM", "JS")) +// .createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) } } @@ -328,8 +336,10 @@ class MarkdownFormatTest { val path = "multiplatform/groupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation) - .appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode })) + TestFileGenerator.buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) } verifyMultiplatformPackage(module, path) } @@ -338,8 +348,10 @@ class MarkdownFormatTest { val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation) - .appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function))) + TestFileGenerator.buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), + output + ) } } @@ -428,15 +440,15 @@ class MarkdownFormatTest { private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + TestFileGenerator.buildPagesAndReadInto(model.members, output) } } private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { model, output -> - MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) - .createOutputBuilder(output, tempLocation).appendNodes(listOf(model)) +// MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) +// .createOutputBuilder(output, tempLocation).appendNodes(listOf(model)) } } @@ -446,7 +458,7 @@ class MarkdownFormatTest { private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + TestFileGenerator.buildPagesAndReadInto(model.members, output) } } @@ -466,7 +478,7 @@ class MarkdownFormatTest { withKotlinRuntime = withKotlinRuntime, includeNonPublic = includeNonPublic ) { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) } } @@ -476,7 +488,7 @@ class MarkdownFormatTest { private fun verifyJavaMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List) { verifyJavaOutput("testdata/format/$fileName.java", ".md", withKotlinRuntime = withKotlinRuntime) { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) } } diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt index a5547025..067ff775 100644 --- a/core/src/test/kotlin/format/PackageDocsTest.kt +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -5,14 +5,14 @@ import com.nhaarman.mockito_kotlin.doAnswer import com.nhaarman.mockito_kotlin.eq import com.nhaarman.mockito_kotlin.mock import org.jetbrains.dokka.* -import org.jetbrains.dokka.tests.InMemoryLocationService +import org.jetbrains.dokka.tests.TestFileGenerator import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.junit.Assert.assertEquals import org.junit.Test import java.io.File -public class PackageDocsTest { +class PackageDocsTest { @Test fun verifyParse() { val docs = PackageDocs(null, DokkaConsoleLogger) docs.parse("testdata/packagedocs/stdlib.md", emptyList()) @@ -38,7 +38,14 @@ public class PackageDocsTest { fun checkMarkdownOutput(docs: PackageDocs, expectedFilePrefix: String) { val out = StringBuilder() - val outputBuilder = MarkdownOutputBuilder(out, InMemoryLocationService.root, InMemoryLocationService, KotlinLanguageService(), ".md", emptyList()) + val outputBuilder = MarkdownOutputBuilder( + out, + FileLocation(TestFileGenerator.root), + TestFileGenerator, + KotlinLanguageService(), + ".md", + emptyList() + ) fun checkOutput(content: Content, filePostfix: String) { outputBuilder.appendContent(content) val expectedFile = File(expectedFilePrefix + filePostfix) -- cgit From 3098b8e7665bcda25f8ead2496c161e10512d7b3 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 4 Dec 2017 18:12:01 +0300 Subject: Introduce test case with preset FileGenerator --- core/src/test/kotlin/TestAPI.kt | 11 -------- .../test/kotlin/format/FileGeneratorTestCase.kt | 31 ++++++++++++++++++++ core/src/test/kotlin/format/GFMFormatTest.kt | 12 ++------ core/src/test/kotlin/format/HtmlFormatTest.kt | 19 +++++-------- .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 16 ++++------- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 15 ++++------ core/src/test/kotlin/format/MarkdownFormatTest.kt | 33 +++++++++------------- core/src/test/kotlin/format/PackageDocsTest.kt | 7 +++-- 8 files changed, 69 insertions(+), 75 deletions(-) create mode 100644 core/src/test/kotlin/format/FileGeneratorTestCase.kt (limited to 'core/src/test') diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 4cd11390..aa3eff48 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -276,14 +276,3 @@ val ContentRoot.path: String is JavaSourceRoot -> file.path else -> throw UnsupportedOperationException() } - - -val TestFileGenerator = FileGenerator(createTempDir()) - -fun FileGenerator.buildPagesAndReadInto(nodes: List, sb: StringBuilder) { - buildPages(nodes) - nodes.forEach { - val fileForNode = TestFileGenerator.location(it).file - sb.append(fileForNode.readText()) - } -} \ No newline at end of file diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt new file mode 100644 index 00000000..7f6d6f3f --- /dev/null +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -0,0 +1,31 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.DocumentationNode +import org.jetbrains.dokka.FileGenerator +import org.jetbrains.dokka.FormatService +import org.junit.Before +import org.junit.Rule +import org.junit.rules.TemporaryFolder + + +abstract class FileGeneratorTestCase { + abstract val formatService: FormatService + + @get:Rule + var folder = TemporaryFolder() + + val fileGenerator = FileGenerator(folder.apply { create() }.root) + + @Before + fun bindGenerator() { + fileGenerator.formatService = formatService + } + + fun buildPagesAndReadInto(nodes: List, sb: StringBuilder) = with(fileGenerator) { + buildPages(nodes) + nodes.forEach { + val fileForNode = location(it).file + sb.append(fileForNode.readText()) + } + } +} \ No newline at end of file diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt index f5b833f6..b90ab2bf 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -2,16 +2,10 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.GFMFormatService import org.jetbrains.dokka.KotlinLanguageService -import org.junit.Before import org.junit.Test -class GFMFormatTest { - private val gfmService = GFMFormatService(TestFileGenerator, KotlinLanguageService(), listOf()) - - @Before - fun prepareFileGenerator() { - TestFileGenerator.formatService = gfmService - } +class GFMFormatTest : FileGeneratorTestCase() { + override val formatService = GFMFormatService(fileGenerator, KotlinLanguageService(), listOf()) @Test fun sample() { @@ -25,7 +19,7 @@ class GFMFormatTest { private fun verifyGFMNodeByName(fileName: String, name: String) { verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( model.members.single().members.filter { it.name == name }, output ) diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt index 4906fbfa..54c367fd 100644 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -7,13 +7,8 @@ import org.junit.Before import org.junit.Test import java.io.File -class HtmlFormatTest { - private val htmlService = HtmlFormatService(TestFileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) - - @Before - fun prepareFileGenerator() { - TestFileGenerator.formatService = htmlService - } +class HtmlFormatTest: FileGeneratorTestCase() { + override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) @Test fun classWithCompanionObject() { verifyHtmlNode("classWithCompanionObject") @@ -37,10 +32,10 @@ class HtmlFormatTest { @Test fun deprecated() { verifyOutput("testdata/format/deprecated.kt", ".package.html") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members, output) + buildPagesAndReadInto(model.members, output) } verifyOutput("testdata/format/deprecated.kt", ".class.html") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) + buildPagesAndReadInto(model.members.single().members, output) } } @@ -108,7 +103,7 @@ class HtmlFormatTest { verifyOutput(arrayOf(KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null)), ".html") { model, output -> - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( model.members.single().members.filter { it.name == "Bar" }, output ) @@ -167,7 +162,7 @@ class HtmlFormatTest { withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List) { verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) + buildPagesAndReadInto(nodeFilter(model), output) } } @@ -179,7 +174,7 @@ class HtmlFormatTest { withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List) { verifyJavaOutput("testdata/format/$fileName.java", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) + buildPagesAndReadInto(nodeFilter(model), output) } } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index b3ea82b7..b971b54d 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -6,14 +6,8 @@ import org.junit.Ignore import org.junit.Test @Ignore -class KotlinWebSiteFormatTest { - private val kwsService = KotlinWebsiteFormatService(TestFileGenerator, KotlinLanguageService(), listOf(), DokkaConsoleLogger) - - @Before - fun prepareFileGenerator() { - TestFileGenerator.formatService = kwsService - } - +class KotlinWebSiteFormatTest: FileGeneratorTestCase() { + override val formatService = KotlinWebsiteFormatService(fileGenerator, KotlinLanguageService(), listOf(), DokkaConsoleLogger) @Test fun sample() { verifyKWSNodeByName("sample", "foo") @@ -36,7 +30,7 @@ class KotlinWebSiteFormatTest { val path = "dataTagsInGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/website/$path/multiplatform.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), output ) @@ -46,7 +40,7 @@ class KotlinWebSiteFormatTest { private fun verifyKWSNodeByName(fileName: String, name: String) { verifyOutput("testdata/format/website/$fileName.kt", ".md", format = "kotlin-website") { model, output -> - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( model.members.single().members.filter { it.name == name }, output ) @@ -71,7 +65,7 @@ class KotlinWebSiteFormatTest { private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.md", "testdata/format/website/$path/multiplatform.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members, output) + buildPagesAndReadInto(model.members, output) } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index 8c94fdcb..49fa6d2f 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -4,13 +4,8 @@ import org.jetbrains.dokka.* import org.junit.Before import org.junit.Test -class KotlinWebSiteHtmlFormatTest { - private val kwsService = KotlinWebsiteHtmlFormatService(TestFileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) - - @Before - fun prepareFileGenerator() { - TestFileGenerator.formatService = kwsService - } +class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { + override val formatService = KotlinWebsiteHtmlFormatService(fileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) @Test fun dropImport() { verifyKWSNodeByName("dropImport", "foo") @@ -49,7 +44,7 @@ class KotlinWebSiteHtmlFormatTest { val path = "dataTagsInGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), output ) @@ -59,7 +54,7 @@ class KotlinWebSiteHtmlFormatTest { private fun verifyKWSNodeByName(fileName: String, name: String) { verifyOutput("testdata/format/website-html/$fileName.kt", ".html", format = "kotlin-website-html") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) + buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) } } @@ -81,7 +76,7 @@ class KotlinWebSiteHtmlFormatTest { private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members, output) + buildPagesAndReadInto(model.members, output) } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index e273f6c1..b0e2a985 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -4,13 +4,8 @@ import org.jetbrains.dokka.* import org.junit.Before import org.junit.Test -class MarkdownFormatTest { - private val markdownService = MarkdownFormatService(TestFileGenerator, KotlinLanguageService(), listOf()) - - @Before - fun prepareFileGenerator() { - TestFileGenerator.formatService = markdownService - } +class MarkdownFormatTest: FileGeneratorTestCase() { + override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) @Test fun emptyDescription() { verifyMarkdownNode("emptyDescription") @@ -40,20 +35,20 @@ class MarkdownFormatTest { @Test fun extensions() { verifyOutput("testdata/format/extensions.kt", ".package.md") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members, output) + buildPagesAndReadInto(model.members, output) } verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) + buildPagesAndReadInto(model.members.single().members, output) } } @Test fun enumClass() { verifyOutput("testdata/format/enumClass.kt", ".md") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) + buildPagesAndReadInto(model.members.single().members, output) } verifyOutput("testdata/format/enumClass.kt", ".value.md") { model, output -> val enumClassNode = model.members.single().members[0] - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, output ) @@ -290,14 +285,14 @@ class MarkdownFormatTest { @Test fun multiplePlatformsMergeMembers() { val module = buildMultiplePlatforms("multiplatform/mergeMembers") verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) + buildPagesAndReadInto(model.members.single().members, output) } } @Test fun multiplePlatformsOmitRedundant() { val module = buildMultiplePlatforms("multiplatform/omitRedundant") verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members.single().members, output) + buildPagesAndReadInto(model.members.single().members, output) } } @@ -336,7 +331,7 @@ class MarkdownFormatTest { val path = "multiplatform/groupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), output ) @@ -348,7 +343,7 @@ class MarkdownFormatTest { val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto( + buildPagesAndReadInto( listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), output ) @@ -440,7 +435,7 @@ class MarkdownFormatTest { private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members, output) + buildPagesAndReadInto(model.members, output) } } @@ -458,7 +453,7 @@ class MarkdownFormatTest { private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> - TestFileGenerator.buildPagesAndReadInto(model.members, output) + buildPagesAndReadInto(model.members, output) } } @@ -478,7 +473,7 @@ class MarkdownFormatTest { withKotlinRuntime = withKotlinRuntime, includeNonPublic = includeNonPublic ) { model, output -> - TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) + buildPagesAndReadInto(nodeFilter(model), output) } } @@ -488,7 +483,7 @@ class MarkdownFormatTest { private fun verifyJavaMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List) { verifyJavaOutput("testdata/format/$fileName.java", ".md", withKotlinRuntime = withKotlinRuntime) { model, output -> - TestFileGenerator.buildPagesAndReadInto(nodeFilter(model), output) + buildPagesAndReadInto(nodeFilter(model), output) } } diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt index 067ff775..704f7b99 100644 --- a/core/src/test/kotlin/format/PackageDocsTest.kt +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -5,7 +5,6 @@ import com.nhaarman.mockito_kotlin.doAnswer import com.nhaarman.mockito_kotlin.eq import com.nhaarman.mockito_kotlin.mock import org.jetbrains.dokka.* -import org.jetbrains.dokka.tests.TestFileGenerator import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.junit.Assert.assertEquals @@ -37,11 +36,13 @@ class PackageDocsTest { fun checkMarkdownOutput(docs: PackageDocs, expectedFilePrefix: String) { + val generator = FileGenerator(File("")) + val out = StringBuilder() val outputBuilder = MarkdownOutputBuilder( out, - FileLocation(TestFileGenerator.root), - TestFileGenerator, + FileLocation(generator.root), + generator, KotlinLanguageService(), ".md", emptyList() -- cgit From 7aa5b52a7e8cd69a384ef29aeeb199061b92584f Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 5 Dec 2017 16:01:39 +0300 Subject: Check file path in testData, when more then one node --- core/src/test/kotlin/format/FileGeneratorTestCase.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'core/src/test') diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt index 7f6d6f3f..6d70292f 100644 --- a/core/src/test/kotlin/format/FileGeneratorTestCase.kt +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.FileGenerator import org.jetbrains.dokka.FormatService +import org.jetbrains.dokka.relativeToRoot import org.junit.Before import org.junit.Rule import org.junit.rules.TemporaryFolder @@ -23,9 +24,12 @@ abstract class FileGeneratorTestCase { fun buildPagesAndReadInto(nodes: List, sb: StringBuilder) = with(fileGenerator) { buildPages(nodes) - nodes.forEach { - val fileForNode = location(it).file - sb.append(fileForNode.readText()) + val byLocations = nodes.groupBy { location(it) } + byLocations.forEach { (loc, _) -> + if (byLocations.size > 1) { + sb.appendln("") + } + sb.append(loc.file.readText()) } } } \ No newline at end of file -- cgit From b209ddcfc2d532f4dc5e508e00d89335fdb15caa Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 5 Dec 2017 18:16:04 +0300 Subject: Append line before file path in testData --- core/src/test/kotlin/format/FileGeneratorTestCase.kt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/src/test') diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt index 6d70292f..644d5baa 100644 --- a/core/src/test/kotlin/format/FileGeneratorTestCase.kt +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -27,6 +27,9 @@ abstract class FileGeneratorTestCase { val byLocations = nodes.groupBy { location(it) } byLocations.forEach { (loc, _) -> if (byLocations.size > 1) { + if (sb.isNotBlank() && !sb.endsWith('\n')) { + sb.appendln() + } sb.appendln("") } sb.append(loc.file.readText()) -- cgit From 1bd0f642248e09cfa95fa19bf5a38316606401a2 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 5 Dec 2017 18:16:40 +0300 Subject: Uncomment and fix some special case tests --- core/src/test/kotlin/format/MarkdownFormatTest.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/src/test') diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index b0e2a985..f60969fc 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -299,8 +299,9 @@ class MarkdownFormatTest: FileGeneratorTestCase() { @Test fun multiplePlatformsImplied() { val module = buildMultiplePlatforms("multiplatform/implied") verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> -// MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf("JVM", "JS")) -// .createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) + fileGenerator.formatService = service + buildPagesAndReadInto(model.members.single().members, output) } } @@ -442,8 +443,9 @@ class MarkdownFormatTest: FileGeneratorTestCase() { private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { model, output -> -// MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) -// .createOutputBuilder(output, tempLocation).appendNodes(listOf(model)) + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + fileGenerator.formatService = service + buildPagesAndReadInto(listOf(model), output) } } -- cgit From dbd4774ffae19ff4d52cd21c7cb3906cdc3e0b5c Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 15 Dec 2017 01:00:32 +0300 Subject: Normalize file path's when using as URI --- core/src/main/kotlin/Formats/HtmlTemplateService.kt | 2 +- core/src/main/kotlin/Locations/Location.kt | 10 ++++++---- core/src/test/kotlin/format/FileGeneratorTestCase.kt | 7 ++----- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/Formats/HtmlTemplateService.kt b/core/src/main/kotlin/Formats/HtmlTemplateService.kt index 84e01910..a65a7b18 100644 --- a/core/src/main/kotlin/Formats/HtmlTemplateService.kt +++ b/core/src/main/kotlin/Formats/HtmlTemplateService.kt @@ -24,7 +24,7 @@ interface HtmlTemplateService { to.appendln("$title") } if (css != null) { - val cssPath = basePath.resolve(css) + val cssPath = basePath.resolve(css).toUnixString() to.appendln("") } to.appendln("") diff --git a/core/src/main/kotlin/Locations/Location.kt b/core/src/main/kotlin/Locations/Location.kt index 17538ff5..0e6572d9 100644 --- a/core/src/main/kotlin/Locations/Location.kt +++ b/core/src/main/kotlin/Locations/Location.kt @@ -13,8 +13,8 @@ interface Location { * $file: [File] for this location * $path: [String] representing path of this location */ -data class FileLocation(val file: File): Location { - override val path : String +data class FileLocation(val file: File) : Location { + override val path: String get() = file.path override fun relativePathTo(other: Location, anchor: String?): String { @@ -30,7 +30,6 @@ data class FileLocation(val file: File): Location { } } - fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String { val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() } return if (!hasMembers) { @@ -41,6 +40,7 @@ fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String } } + fun relativePathToNode(node: DocumentationNode) = relativePathToNode(node.path.map { it.name }, node.members.any()) fun identifierToFilename(path: String): String { @@ -56,4 +56,6 @@ fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, fun NodeLocationAwareGenerator.relativeToRoot(from: Location): File { val file = File(from.path) return file.relativeTo(root) -} \ No newline at end of file +} + +fun File.toUnixString() = toString().replace(File.separatorChar, '/') diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt index 644d5baa..948426ea 100644 --- a/core/src/test/kotlin/format/FileGeneratorTestCase.kt +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -1,9 +1,6 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.DocumentationNode -import org.jetbrains.dokka.FileGenerator -import org.jetbrains.dokka.FormatService -import org.jetbrains.dokka.relativeToRoot +import org.jetbrains.dokka.* import org.junit.Before import org.junit.Rule import org.junit.rules.TemporaryFolder @@ -30,7 +27,7 @@ abstract class FileGeneratorTestCase { if (sb.isNotBlank() && !sb.endsWith('\n')) { sb.appendln() } - sb.appendln("") + sb.appendln("") } sb.append(loc.file.readText()) } -- cgit From d6ba6677cff2de399b8231127325af2cea210b50 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 22 Mar 2018 23:12:56 +0300 Subject: Fix external references to Java enum entries Fix #274 --- core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt | 5 ++++- core/src/test/kotlin/format/MarkdownFormatTest.kt | 5 +++++ core/testdata/format/enumRef.kt | 4 ++++ core/testdata/format/enumRef.md | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 core/testdata/format/enumRef.kt create mode 100644 core/testdata/format/enumRef.md (limited to 'core/src/test') diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt index 108cee78..ebea7183 100644 --- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt @@ -5,6 +5,7 @@ import com.google.inject.Singleton import com.intellij.psi.PsiMethod import com.intellij.util.io.* import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor @@ -178,7 +179,9 @@ interface InboundExternalLinkResolutionService { class Javadoc : InboundExternalLinkResolutionService { override fun getPath(symbol: DeclarationDescriptor): String? { - if (symbol is JavaClassDescriptor) { + if (symbol is EnumEntrySyntheticClassDescriptor) { + return getPath(symbol.containingDeclaration)?.let { it + "#" + symbol.name.asString() } + } else if (symbol is JavaClassDescriptor) { return DescriptorUtils.getFqName(symbol).asString().replace(".", "/") + ".html" } else if (symbol is JavaCallableMemberDescriptor) { val containingClass = symbol.containingDeclaration as? JavaClassDescriptor ?: return null diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index f60969fc..f06f0e64 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -419,6 +419,11 @@ class MarkdownFormatTest: FileGeneratorTestCase() { verifyMarkdownNodeByName("companionImplements", "Foo") } + @Test fun enumRef() { + verifyMarkdownNode("enumRef") + } + + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") val options = DocumentationOptions( diff --git a/core/testdata/format/enumRef.kt b/core/testdata/format/enumRef.kt new file mode 100644 index 00000000..5c0b2de9 --- /dev/null +++ b/core/testdata/format/enumRef.kt @@ -0,0 +1,4 @@ +/** + * [java.math.RoundingMode.UP] + */ +fun f() {} \ No newline at end of file diff --git a/core/testdata/format/enumRef.md b/core/testdata/format/enumRef.md new file mode 100644 index 00000000..8b2a6650 --- /dev/null +++ b/core/testdata/format/enumRef.md @@ -0,0 +1,8 @@ +[test](index.md) / [f](./f.md) + +# f + +`fun f(): Unit` + +[java.math.RoundingMode.UP](http://docs.oracle.com/javase/6/docs/api/java/math/RoundingMode.html#UP) + -- cgit From b3fa0d91fd466c3319f3a37a1cc5e82be2b89697 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 16 May 2018 18:06:56 +0300 Subject: Fix link resolution context for inherited docs Fix #229 --- .../kotlin/Kotlin/DescriptorDocumentationParser.kt | 18 ++++++++++++++---- core/src/test/kotlin/format/MarkdownFormatTest.kt | 16 ++++++++++++++++ core/testdata/format/inheritedLink.1.kt | 10 ++++++++++ core/testdata/format/inheritedLink.kt | 11 +++++++++++ core/testdata/format/inheritedLink.md | 17 +++++++++++++++++ 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 core/testdata/format/inheritedLink.1.kt create mode 100644 core/testdata/format/inheritedLink.kt create mode 100644 core/testdata/format/inheritedLink.md (limited to 'core/src/test') diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index f2d9d3a7..6e44df74 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -8,14 +8,17 @@ import org.intellij.markdown.parser.LinkMap import org.jetbrains.dokka.* import org.jetbrains.dokka.Samples.SampleProcessingService import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.kdoc.findKDoc import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag +import org.jetbrains.kotlin.kdoc.psi.api.KDoc import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.annotations.argumentValue import org.jetbrains.kotlin.resolve.constants.StringValue @@ -49,6 +52,13 @@ class DescriptorDocumentationParser } return Content.Empty to { node -> } } + + val contextDescriptor = + (PsiTreeUtil.getParentOfType(kdoc, KDoc::class.java)?.context as? KtDeclaration) + ?.takeIf { it != descriptor.original.sourcePsi() } + ?.resolveToDescriptorIfAny() + ?: descriptor + var kdocText = kdoc.getContent() // workaround for code fence parsing problem in IJ markdown parser if (kdocText.endsWith("```") || kdocText.endsWith("~~~")) { @@ -56,20 +66,20 @@ class DescriptorDocumentationParser } val tree = parseMarkdown(kdocText) val linkMap = LinkMap.buildLinkMap(tree.node, kdocText) - val content = buildContent(tree, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(descriptor, href) }), inline) + val content = buildContent(tree, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(contextDescriptor, href) }), inline) if (kdoc is KDocSection) { val tags = kdoc.getTags() tags.forEach { when (it.knownTag) { KDocKnownTag.SAMPLE -> - content.append(sampleService.resolveSample(descriptor, it.getSubjectName(), it)) + content.append(sampleService.resolveSample(contextDescriptor, it.getSubjectName(), it)) KDocKnownTag.SEE -> - content.addTagToSeeAlso(descriptor, it) + content.addTagToSeeAlso(contextDescriptor, it) else -> { val section = content.addSection(javadocSectionDisplayName(it.name), it.getSubjectName()) val sectionContent = it.getContent() val markdownNode = parseMarkdown(sectionContent) - buildInlineContentTo(markdownNode, section, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(descriptor, href) })) + buildInlineContentTo(markdownNode, section, LinkResolver(linkMap, { href -> linkResolver.resolveContentLink(contextDescriptor, href) })) } } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index f06f0e64..9e4c831d 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -423,6 +423,22 @@ class MarkdownFormatTest: FileGeneratorTestCase() { verifyMarkdownNode("enumRef") } + @Test fun inheritedLink() { + val filePath = "testdata/format/inheritedLink" + verifyOutput( + arrayOf( + contentRootFromPath("$filePath.kt"), + contentRootFromPath("$filePath.1.kt") + ), + ".md", + withJdk = true, + withKotlinRuntime = true, + includeNonPublic = false + ) { model, output -> + buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) + } + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") diff --git a/core/testdata/format/inheritedLink.1.kt b/core/testdata/format/inheritedLink.1.kt new file mode 100644 index 00000000..29cc12b4 --- /dev/null +++ b/core/testdata/format/inheritedLink.1.kt @@ -0,0 +1,10 @@ +package p1 + +import java.util.LinkedList + +interface Foo { + + /** Says hello - [LinkedList]. */ + fun sayHello() : String + +} \ No newline at end of file diff --git a/core/testdata/format/inheritedLink.kt b/core/testdata/format/inheritedLink.kt new file mode 100644 index 00000000..86b8f4e2 --- /dev/null +++ b/core/testdata/format/inheritedLink.kt @@ -0,0 +1,11 @@ +package p2 + +import p1.Foo + +class FooBar : Foo { + + override fun sayHello(): String { + return "Hello!" + } + +} \ No newline at end of file diff --git a/core/testdata/format/inheritedLink.md b/core/testdata/format/inheritedLink.md new file mode 100644 index 00000000..e5af326c --- /dev/null +++ b/core/testdata/format/inheritedLink.md @@ -0,0 +1,17 @@ + +[test](../../index.md) / [p2](../index.md) / [FooBar](index.md) / [<init>](./-init-.md) + +# <init> + +`FooBar()` + +[test](../../index.md) / [p2](../index.md) / [FooBar](index.md) / [sayHello](./say-hello.md) + +# sayHello + +`fun sayHello(): String` + +Overrides [Foo.sayHello](../../p1/-foo/say-hello.md) + +Says hello - [LinkedList](http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html). + -- cgit From 9865da2e6e6c038ab6c719a6a03bb09184542d20 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 17 May 2018 19:48:44 +0300 Subject: Fix incorrect link to stylesheet in html format --- core/src/main/kotlin/Formats/HtmlFormatService.kt | 5 ++--- core/src/main/kotlin/Generation/FileGenerator.kt | 4 +--- core/src/main/kotlin/Locations/Location.kt | 6 +++--- core/src/test/kotlin/format/FileGeneratorTestCase.kt | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt index 0073553c..0ad946be 100644 --- a/core/src/main/kotlin/Formats/HtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt @@ -4,7 +4,6 @@ import com.google.inject.Inject import com.google.inject.name.Named import org.jetbrains.dokka.Utilities.impliedPlatformsName import java.io.File -import java.nio.file.Path open class HtmlOutputBuilder(to: StringBuilder, location: Location, @@ -80,7 +79,7 @@ open class HtmlOutputBuilder(to: StringBuilder, } override fun appendNodes(nodes: Iterable) { - templateService.appendHeader(to, getPageTitle(nodes), generator.relativeToRoot(location)) + templateService.appendHeader(to, getPageTitle(nodes), generator.relativePathToRoot(location)) super.appendNodes(nodes) templateService.appendFooter(to) } @@ -108,7 +107,7 @@ open class HtmlFormatService @Inject constructor(generator: NodeLocationAwareGen HtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms, templateService) override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable) { - templateService.appendHeader(to, "Module Contents", generator.relativeToRoot(location)) + templateService.appendHeader(to, "Module Contents", generator.relativePathToRoot(location)) super.appendOutline(location, to, nodes) templateService.appendFooter(to) } diff --git a/core/src/main/kotlin/Generation/FileGenerator.kt b/core/src/main/kotlin/Generation/FileGenerator.kt index bc08e180..b7c6cf63 100644 --- a/core/src/main/kotlin/Generation/FileGenerator.kt +++ b/core/src/main/kotlin/Generation/FileGenerator.kt @@ -8,15 +8,13 @@ import java.io.FileOutputStream import java.io.IOException import java.io.OutputStreamWriter -class FileGenerator @Inject constructor(@Named("outputDir") val rootFile: File) : NodeLocationAwareGenerator { +class FileGenerator @Inject constructor(@Named("outputDir") override val root: File) : NodeLocationAwareGenerator { @set:Inject(optional = true) var outlineService: OutlineFormatService? = null @set:Inject(optional = true) lateinit var formatService: FormatService @set:Inject(optional = true) lateinit var options: DocumentationOptions @set:Inject(optional = true) var packageListService: PackageListService? = null - override val root: File = rootFile - override fun location(node: DocumentationNode): FileLocation { return FileLocation(fileForNode(node, formatService.linkExtension)) } diff --git a/core/src/main/kotlin/Locations/Location.kt b/core/src/main/kotlin/Locations/Location.kt index 0e6572d9..4cb0ac39 100644 --- a/core/src/main/kotlin/Locations/Location.kt +++ b/core/src/main/kotlin/Locations/Location.kt @@ -53,9 +53,9 @@ fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, return location(owner).relativePathTo(location(node), null) } -fun NodeLocationAwareGenerator.relativeToRoot(from: Location): File { - val file = File(from.path) - return file.relativeTo(root) +fun NodeLocationAwareGenerator.relativePathToRoot(from: Location): File { + val file = File(from.path).parentFile + return root.relativeTo(file) } fun File.toUnixString() = toString().replace(File.separatorChar, '/') diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt index 948426ea..ef9e815d 100644 --- a/core/src/test/kotlin/format/FileGeneratorTestCase.kt +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -27,7 +27,7 @@ abstract class FileGeneratorTestCase { if (sb.isNotBlank() && !sb.endsWith('\n')) { sb.appendln() } - sb.appendln("") + sb.appendln("") } sb.append(loc.file.readText()) } -- cgit From 960ea9ebb01f280c4966e139c1697f083e9d8965 Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Thu, 12 Jul 2018 15:37:18 +0300 Subject: Test refactoring and split by different platforms --- core/src/test/kotlin/TestAPI.kt | 163 ++++--- core/src/test/kotlin/format/BaseHtmlFormatTest.kt | 146 ++++++ .../test/kotlin/format/BaseMarkdownFormatTest.kt | 467 ++++++++++++++++++ core/src/test/kotlin/format/HtmlFormatTest.kt | 181 ------- core/src/test/kotlin/format/JSHtmlFormatTest.kt | 6 + .../src/test/kotlin/format/JSMarkdownFormatTest.kt | 7 + core/src/test/kotlin/format/JVMHtmlFormatTest.kt | 54 +++ .../test/kotlin/format/JVMMarkdownFormatTest.kt | 117 +++++ .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 27 +- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 25 +- core/src/test/kotlin/format/MarkdownFormatTest.kt | 527 --------------------- core/src/test/kotlin/issues/IssuesTest.kt | 7 +- core/src/test/kotlin/javadoc/JavadocTest.kt | 39 +- core/src/test/kotlin/model/BaseClassTest.kt | 269 +++++++++++ core/src/test/kotlin/model/BasePropertyTest.kt | 101 ++++ core/src/test/kotlin/model/ClassTest.kt | 293 ------------ core/src/test/kotlin/model/CommentTest.kt | 28 +- core/src/test/kotlin/model/FunctionTest.kt | 44 +- core/src/test/kotlin/model/JSClassTest.kt | 6 + core/src/test/kotlin/model/JSFunctionTest.kt | 8 + core/src/test/kotlin/model/JSPropertyTest.kt | 8 + core/src/test/kotlin/model/JVMClassTest.kt | 55 +++ core/src/test/kotlin/model/JVMFunctionTest.kt | 29 ++ core/src/test/kotlin/model/JVMPropertyTest.kt | 33 ++ core/src/test/kotlin/model/JavaTest.kt | 34 +- core/src/test/kotlin/model/KotlinAsJavaTest.kt | 14 +- core/src/test/kotlin/model/LinkTest.kt | 12 +- core/src/test/kotlin/model/PackageTest.kt | 40 +- core/src/test/kotlin/model/PropertyTest.kt | 111 ----- core/src/test/kotlin/model/TypeAliasTest.kt | 18 +- 30 files changed, 1570 insertions(+), 1299 deletions(-) create mode 100644 core/src/test/kotlin/format/BaseHtmlFormatTest.kt create mode 100644 core/src/test/kotlin/format/BaseMarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/format/HtmlFormatTest.kt create mode 100644 core/src/test/kotlin/format/JSHtmlFormatTest.kt create mode 100644 core/src/test/kotlin/format/JSMarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/format/JVMHtmlFormatTest.kt create mode 100644 core/src/test/kotlin/format/JVMMarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/format/MarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/model/BaseClassTest.kt create mode 100644 core/src/test/kotlin/model/BasePropertyTest.kt delete mode 100644 core/src/test/kotlin/model/ClassTest.kt create mode 100644 core/src/test/kotlin/model/JSClassTest.kt create mode 100644 core/src/test/kotlin/model/JSFunctionTest.kt create mode 100644 core/src/test/kotlin/model/JSPropertyTest.kt create mode 100644 core/src/test/kotlin/model/JVMClassTest.kt create mode 100644 core/src/test/kotlin/model/JVMFunctionTest.kt create mode 100644 core/src/test/kotlin/model/JVMPropertyTest.kt delete mode 100644 core/src/test/kotlin/model/PropertyTest.kt (limited to 'core/src/test') diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index aa3eff48..bcbbf2fc 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -6,7 +6,6 @@ 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.DokkaConfiguration.SourceLinkDefinition import org.jetbrains.dokka.Utilities.DokkaAnalysisModule import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity @@ -18,24 +17,29 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.junit.Assert import org.junit.Assert.fail import java.io.File +data class ModelConfig( + val roots: Array = arrayOf(), + val withJdk: Boolean = false, + val withKotlinRuntime: Boolean = false, + val format: String = "html", + val includeNonPublic: Boolean = true, + val perPackageOptions: List = emptyList(), + val analysisPlatform: Platform = Platform.js, + val defaultPlatforms: List = emptyList() +) -fun verifyModel(vararg roots: ContentRoot, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - perPackageOptions: List = emptyList(), +fun verifyModel(modelConfig: ModelConfig, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") val options = DocumentationOptions( "", - format, - includeNonPublic = includeNonPublic, + modelConfig.format, + includeNonPublic = modelConfig.includeNonPublic, skipEmptyPackages = false, includeRootPackage = true, sourceLinks = listOf(), - perPackageOptions = perPackageOptions, + perPackageOptions = modelConfig.perPackageOptions, generateIndexPages = false, noStdlibLink = true, cacheRoot = "default", @@ -43,21 +47,16 @@ fun verifyModel(vararg roots: ContentRoot, apiVersion = null ) - appendDocumentation(documentation, *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - options = options) + appendDocumentation(documentation, options, modelConfig) documentation.prepareForGeneration(options) verifier(documentation) } fun appendDocumentation(documentation: DocumentationModule, - vararg roots: ContentRoot, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, options: DocumentationOptions, - defaultPlatforms: List = emptyList()) { + modelConfig: ModelConfig +) { val messageCollector = object : MessageCollector { override fun clear() { @@ -82,22 +81,28 @@ fun appendDocumentation(documentation: DocumentationModule, override fun hasErrors() = false } - val environment = AnalysisEnvironment(messageCollector) + val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) environment.apply { - if (withJdk || withKotlinRuntime) { + if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class") addClasspath(File(stringRoot)) } - if (withKotlinRuntime) { + if (modelConfig.withKotlinRuntime) { val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") addClasspath(File(kotlinStrictfpRoot)) + // TODO: Fix concrete path to correct gradle path providing + if (analysisPlatform == Platform.js) { + addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-jslib.jar")) + addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js.jar")) + addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js-sources.jar")) + } } - addRoots(roots.toList()) + addRoots(modelConfig.roots.toList()) loadLanguageVersionSettings(options.languageVersion, options.apiVersion) } val defaultPlatformsProvider = object : DefaultPlatformsProvider { - override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms + override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms } val injector = Guice.createInjector( DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentation.nodeRefGraph, DokkaConsoleLogger)) @@ -105,41 +110,59 @@ fun appendDocumentation(documentation: DocumentationModule, Disposer.dispose(environment) } -fun verifyModel(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - verifier: (DocumentationModule) -> Unit) { +fun checkSourceExistsAndVerifyModel(source: String, + modelConfig: ModelConfig = ModelConfig(), + verifier: (DocumentationModule) -> Unit +) { if (!File(source).exists()) { throw IllegalArgumentException("Can't find test data file $source") } - verifyModel(contentRootFromPath(source), - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic, - verifier = verifier) + verifyModel( + ModelConfig( + roots = arrayOf(contentRootFromPath(source)), + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + format = modelConfig.format, + includeNonPublic = modelConfig.includeNonPublic, + analysisPlatform = modelConfig.analysisPlatform + ), + + verifier = verifier + ) } fun verifyPackageMember(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationNode) -> Unit) { - verifyModel(source, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model -> + 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, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationModule) -> Unit) { val tempDir = FileUtil.createTempDirectory("dokka", "") try { val sourceFile = File(source) FileUtil.copy(sourceFile, File(tempDir, sourceFile.name)) - verifyModel(JavaSourceRoot(tempDir, null), withJdk = true, withKotlinRuntime = withKotlinRuntime, verifier = verifier) + verifyModel( + ModelConfig( + roots = arrayOf(JavaSourceRoot(tempDir, null)), + withJdk = true, + withKotlinRuntime = modelConfig.withKotlinRuntime, + analysisPlatform = modelConfig.analysisPlatform + ), + verifier = verifier + ) } finally { FileUtil.delete(tempDir) @@ -147,32 +170,40 @@ fun verifyJavaModel(source: String, } fun verifyJavaPackageMember(source: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationNode) -> Unit) { - verifyJavaModel(source, withKotlinRuntime) { model -> + verifyJavaModel(source, modelConfig) { model -> val pkg = model.members.single() verifier(pkg.members.single()) } } -fun verifyOutput(roots: Array, +fun verifyOutput(modelConfig: ModelConfig = ModelConfig(), outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyModel( - *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic - ) { - verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) + 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 + ), + outputExtension, + outputGenerator + ) +} + fun verifyModelOutput(it: DocumentationModule, outputExtension: String, sourcePath: String, @@ -184,29 +215,11 @@ fun verifyModelOutput(it: DocumentationModule, assertEqualsIgnoringSeparators(expectedFile, output.toString()) } -fun verifyOutput(path: String, - outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyOutput( - arrayOf(contentRootFromPath(path)), - outputExtension, - withJdk, - withKotlinRuntime, - format, - includeNonPublic, - outputGenerator - ) -} - fun verifyJavaOutput(path: String, outputExtension: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyJavaModel(path, withKotlinRuntime) { model -> + verifyJavaModel(path, modelConfig) { model -> verifyModelOutput(model, outputExtension, path, outputGenerator) } } diff --git a/core/src/test/kotlin/format/BaseHtmlFormatTest.kt b/core/src/test/kotlin/format/BaseHtmlFormatTest.kt new file mode 100644 index 00000000..7fd331cf --- /dev/null +++ b/core/src/test/kotlin/format/BaseHtmlFormatTest.kt @@ -0,0 +1,146 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.junit.Before +import org.junit.Test +import java.io.File + +abstract class BaseHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) + + @Test fun classWithCompanionObject() { + verifyHtmlNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun htmlEscaping() { + verifyHtmlNode("htmlEscaping", defaultModelConfig) + } + + @Test fun overloads() { + verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } + } + + @Test fun overloadsWithDescription() { + verifyHtmlNode("overloadsWithDescription", defaultModelConfig) + } + + @Test fun overloadsWithDifferentDescriptions() { + verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) + } + + @Test fun deprecated() { + verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun brokenLink() { + verifyHtmlNode("brokenLink", defaultModelConfig) + } + + @Test fun codeSpan() { + verifyHtmlNode("codeSpan", defaultModelConfig) + } + + @Test fun parenthesis() { + verifyHtmlNode("parenthesis", defaultModelConfig) + } + + @Test fun bracket() { + verifyHtmlNode("bracket", defaultModelConfig) + } + + @Test fun see() { + verifyHtmlNode("see", defaultModelConfig) + } + + @Test fun tripleBackticks() { + verifyHtmlNode("tripleBackticks", defaultModelConfig) + } + + @Test fun typeLink() { + verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun parameterAnchor() { + verifyHtmlNode("parameterAnchor", defaultModelConfig) + } + + @Test fun codeBlock() { + verifyHtmlNode("codeBlock", defaultModelConfig) + } + @Test fun orderedList() { + verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun linkWithLabel() { + verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun entity() { + verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun uninterpretedEmphasisCharacters() { + verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) + } + + @Test fun markdownInLinks() { + verifyHtmlNode("markdownInLinks", defaultModelConfig) + } + + @Test fun returnWithLink() { + verifyHtmlNode("returnWithLink", defaultModelConfig) + } + + @Test fun linkWithStarProjection() { + verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyHtmlNode("sinceKotlin", defaultModelConfig) + } + + @Test fun blankLineInsideCodeBlock() { + verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyHtmlNode("indentedCodeBlock", defaultModelConfig) + } + + private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + private fun verifyHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyOutput("testdata/format/$fileName.kt", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } +} + diff --git a/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt b/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt new file mode 100644 index 00000000..5612b1fd --- /dev/null +++ b/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt @@ -0,0 +1,467 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Test + +abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + + @Test fun emptyDescription() { + verifyMarkdownNode("emptyDescription", defaultModelConfig) + } + + @Test fun classWithCompanionObject() { + verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun annotations() { + verifyMarkdownNode("annotations", defaultModelConfig) + } + + @Test fun annotationClass() { + verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun enumClass() { + verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> + val enumClassNode = model.members.single().members[0] + buildPagesAndReadInto( + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, + output + ) + } + } + + @Test fun varargsFunction() { + verifyMarkdownNode("varargsFunction", defaultModelConfig) + } + + @Test fun overridingFunction() { + verifyMarkdownNodes("overridingFunction", defaultModelConfig) { model-> + val classMembers = model.members.single().members.first { it.name == "D" }.members + classMembers.filter { it.name == "f" } + } + } + + @Test fun propertyVar() { + verifyMarkdownNode("propertyVar", defaultModelConfig) + } + + @Test fun functionWithDefaultParameter() { + verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) + } + + @Test fun accessor() { + verifyMarkdownNodes("accessor", defaultModelConfig) { model -> + model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } + } + } + + @Test fun paramTag() { + verifyMarkdownNode("paramTag", defaultModelConfig) + } + + @Test fun throwsTag() { + verifyMarkdownNode("throwsTag", defaultModelConfig) + } + + @Test fun typeParameterBounds() { + verifyMarkdownNode("typeParameterBounds", defaultModelConfig) + } + + @Test fun typeParameterVariance() { + verifyMarkdownNode("typeParameterVariance", defaultModelConfig) + } + + @Test fun typeProjectionVariance() { + verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) + } + + @Test fun codeBlockNoHtmlEscape() { + verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) + } + + @Test fun companionObjectExtension() { + verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) + } + + @Test fun starProjection() { + verifyMarkdownNode("starProjection", defaultModelConfig) + } + + @Test fun extensionFunctionParameter() { + verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) + } + + @Test fun summarizeSignatures() { + verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } + } + + @Test fun reifiedTypeParameter() { + verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun annotatedTypeParameter() { + verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedMembers() { + verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) + } + + @Test fun inheritedExtensions() { + verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun genericInheritedExtensions() { + verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun arrayAverage() { + verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) + } + + @Test fun multipleTypeParameterConstraints() { + verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedCompanionObjectProperties() { + verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) + } + + @Test fun shadowedExtensionFunctions() { + verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun inapplicableExtensionFunctions() { + verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun receiverParameterTypeBound() { + verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) + } + + @Test fun extensionWithDocumentedReceiver() { + verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> + model.members.single().members.single().members.filter { it.name == "fn" } + } + } + + @Test fun codeBlock() { + verifyMarkdownNode("codeBlock", defaultModelConfig) + } + + @Test fun exclInCodeBlock() { + verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun backtickInCodeBlock() { + verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun qualifiedNameLink() { + verifyMarkdownNodeByName("qualifiedNameLink", "foo", + ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun typeAliases() { + verifyMarkdownNode("typeAliases", defaultModelConfig) + verifyMarkdownPackage("typeAliases", defaultModelConfig) + } + + @Test fun sampleByShortName() { + verifyMarkdownNode("sampleByShortName", defaultModelConfig) + } + + + @Test fun suspendParam() { + verifyMarkdownNode("suspendParam", defaultModelConfig) + verifyMarkdownPackage("suspendParam", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyMarkdownNode("sinceKotlin", defaultModelConfig) + verifyMarkdownPackage("sinceKotlin", defaultModelConfig) + } + + @Test fun sinceKotlinWide() { + verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) + } + + @Test fun dynamicType() { + verifyMarkdownNode("dynamicType", defaultModelConfig) + } + + @Test fun dynamicExtension() { + verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun memberExtension() { + verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { + verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) + } + + @Test fun multiplePlatforms() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") + } + + @Test fun multiplePlatformsMerge() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") + } + + @Test fun multiplePlatformsMergeMembers() { + val module = buildMultiplePlatforms("multiplatform/mergeMembers") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsOmitRedundant() { + val module = buildMultiplePlatforms("multiplatform/omitRedundant") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsImplied() { + val module = buildMultiplePlatforms("multiplatform/implied") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) + fileGenerator.formatService = service + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun packagePlatformsWithExtExtensions() { + val path = "multiplatform/packagePlatformsWithExtExtensions" + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation(module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + withKotlinRuntime = true, + analysisPlatform = analysisPlatform + ) + ) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsPackagePlatformFromMembers() { + val path = "multiplatform/packagePlatformsFromMembers" + val module = buildMultiplePlatforms(path) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsGroupNode() { + val path = "multiplatform/groupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) + } + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { + val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), + output + ) + } + } + + @Test fun linksInEmphasis() { + verifyMarkdownNode("linksInEmphasis", defaultModelConfig) + } + + @Test fun linksInStrong() { + verifyMarkdownNode("linksInStrong", defaultModelConfig) + } + + @Test fun linksInHeaders() { + verifyMarkdownNode("linksInHeaders", defaultModelConfig) + } + + @Test fun tokensInEmphasis() { + verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) + } + + @Test fun tokensInStrong() { + verifyMarkdownNode("tokensInStrong", defaultModelConfig) + } + + @Test fun tokensInHeaders() { + verifyMarkdownNode("tokensInHeaders", defaultModelConfig) + } + + @Test fun unorderedLists() { + verifyMarkdownNode("unorderedLists", defaultModelConfig) + } + + @Test fun nestedLists() { + verifyMarkdownNode("nestedLists", defaultModelConfig) + } + + @Test fun referenceLink() { + verifyMarkdownNode("referenceLink", defaultModelConfig) + } + + @Test fun externalReferenceLink() { + verifyMarkdownNode("externalReferenceLink", defaultModelConfig) + } + + @Test fun newlineInTableCell() { + verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) + } + + @Test fun receiverReference() { + verifyMarkdownNode("receiverReference", defaultModelConfig) + } + + @Test fun extensionScope() { + verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) + } + + @Test fun typeParameterReference() { + verifyMarkdownNode("typeParameterReference", defaultModelConfig) + } + + @Test fun notPublishedTypeAliasAutoExpansion() { + verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( + analysisPlatform = analysisPlatform, + includeNonPublic = false + )) + } + + @Test fun companionImplements() { + verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) + } + + + private fun buildMultiplePlatforms(path: String): DocumentationModule { + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + analysisPlatform = Platform.jvm + ) + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), + defaultPlatforms = listOf("JS"), + analysisPlatform = Platform.js + ) + ) + + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { + model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + fileGenerator.formatService = service + buildPagesAndReadInto(listOf(model), output) + } + } + + @Test fun blankLineInsideCodeBlock() { + verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyMarkdownNodes( + fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List + ) { + verifyOutput( + "testdata/format/$fileName.kt", + ".md", + modelConfig + ) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyMarkdownNodeByName( + fileName: String, + name: String, + modelConfig: ModelConfig = ModelConfig() + ) { + verifyMarkdownNodes(fileName, modelConfig) { model-> + val nodesWithName = model.members.single().members.filter { it.name == name } + if (nodesWithName.isEmpty()) { + throw IllegalArgumentException("Found no nodes named $name") + } + nodesWithName + } + } +} diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt deleted file mode 100644 index 54c367fd..00000000 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ /dev/null @@ -1,181 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.junit.Before -import org.junit.Test -import java.io.File - -class HtmlFormatTest: FileGeneratorTestCase() { - override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) - - @Test fun classWithCompanionObject() { - verifyHtmlNode("classWithCompanionObject") - } - - @Test fun htmlEscaping() { - verifyHtmlNode("htmlEscaping") - } - - @Test fun overloads() { - verifyHtmlNodes("overloads") { model -> model.members } - } - - @Test fun overloadsWithDescription() { - verifyHtmlNode("overloadsWithDescription") - } - - @Test fun overloadsWithDifferentDescriptions() { - verifyHtmlNode("overloadsWithDifferentDescriptions") - } - - @Test fun deprecated() { - verifyOutput("testdata/format/deprecated.kt", ".package.html") { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/deprecated.kt", ".class.html") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun brokenLink() { - verifyHtmlNode("brokenLink") - } - - @Test fun codeSpan() { - verifyHtmlNode("codeSpan") - } - - @Test fun parenthesis() { - verifyHtmlNode("parenthesis") - } - - @Test fun bracket() { - verifyHtmlNode("bracket") - } - - @Test fun see() { - verifyHtmlNode("see") - } - - @Test fun tripleBackticks() { - verifyHtmlNode("tripleBackticks") - } - - @Test fun typeLink() { - verifyHtmlNodes("typeLink") { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun parameterAnchor() { - verifyHtmlNode("parameterAnchor") - } - - @Test fun javaSupertypeLink() { - verifyJavaHtmlNodes("JavaSupertype") { model -> - model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } - } - } - - @Test fun codeBlock() { - verifyHtmlNode("codeBlock") - } - - @Test fun javaLinkTag() { - verifyJavaHtmlNode("javaLinkTag") - } - - @Test fun javaLinkTagWithLabel() { - verifyJavaHtmlNode("javaLinkTagWithLabel") - } - - @Test fun javaSeeTag() { - verifyJavaHtmlNode("javaSeeTag") - } - - @Test fun javaDeprecated() { - verifyJavaHtmlNodes("javaDeprecated") { model -> - model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } - } - } - - @Test fun crossLanguageKotlinExtendsJava() { - verifyOutput(arrayOf(KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), - JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null)), - ".html") { model, output -> - buildPagesAndReadInto( - model.members.single().members.filter { it.name == "Bar" }, - output - ) - } - } - - @Test fun orderedList() { - verifyHtmlNodes("orderedList") { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun linkWithLabel() { - verifyHtmlNodes("linkWithLabel") { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun entity() { - verifyHtmlNodes("entity") { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun uninterpretedEmphasisCharacters() { - verifyHtmlNode("uninterpretedEmphasisCharacters") - } - - @Test fun markdownInLinks() { - verifyHtmlNode("markdownInLinks") - } - - @Test fun returnWithLink() { - verifyHtmlNode("returnWithLink") - } - - @Test fun linkWithStarProjection() { - verifyHtmlNode("linkWithStarProjection", withKotlinRuntime = true) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyHtmlNode("functionalTypeWithNamedParameters") - } - - @Test fun sinceKotlin() { - verifyHtmlNode("sinceKotlin") - } - - @Test fun blankLineInsideCodeBlock() { - verifyHtmlNode("blankLineInsideCodeBlock") - } - - @Test fun indentedCodeBlock() { - verifyHtmlNode("indentedCodeBlock") - } - - private fun verifyHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } - } - - private fun verifyHtmlNodes(fileName: String, - withKotlinRuntime: Boolean = false, - nodeFilter: (DocumentationModule) -> List) { - verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - private fun verifyJavaHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyJavaHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } - } - - private fun verifyJavaHtmlNodes(fileName: String, - withKotlinRuntime: Boolean = false, - nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } -} - diff --git a/core/src/test/kotlin/format/JSHtmlFormatTest.kt b/core/src/test/kotlin/format/JSHtmlFormatTest.kt new file mode 100644 index 00000000..afa0ce0a --- /dev/null +++ b/core/src/test/kotlin/format/JSHtmlFormatTest.kt @@ -0,0 +1,6 @@ +package org.jetbrains.dokka.tests.format + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseHtmlFormatTest + +class JSHtmlFormatTest: BaseHtmlFormatTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JSMarkdownFormatTest.kt b/core/src/test/kotlin/format/JSMarkdownFormatTest.kt new file mode 100644 index 00000000..ca92d9f6 --- /dev/null +++ b/core/src/test/kotlin/format/JSMarkdownFormatTest.kt @@ -0,0 +1,7 @@ +package org.jetbrains.dokka.tests.format + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseMarkdownFormatTest + +class JSMarkdownFormatTest: BaseMarkdownFormatTest(Platform.js) { +} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMHtmlFormatTest.kt b/core/src/test/kotlin/format/JVMHtmlFormatTest.kt new file mode 100644 index 00000000..1696ffb2 --- /dev/null +++ b/core/src/test/kotlin/format/JVMHtmlFormatTest.kt @@ -0,0 +1,54 @@ +package org.jetbrains.dokka.tests.format + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseHtmlFormatTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.verifyOutput +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.junit.Test +import java.io.File + +class JVMHtmlFormatTest: BaseHtmlFormatTest(Platform.jvm) { + @Test + fun javaSeeTag() { + verifyJavaHtmlNode("javaSeeTag", defaultModelConfig) + } + + @Test fun javaDeprecated() { + verifyJavaHtmlNodes("javaDeprecated", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } + } + } + + @Test fun crossLanguageKotlinExtendsJava() { + verifyOutput( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), + JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null) + ), + analysisPlatform = analysisPlatform + ), ".html") { model, output -> + buildPagesAndReadInto( + model.members.single().members.filter { it.name == "Bar" }, + output + ) + } + } + + @Test fun javaLinkTag() { + verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) + } + + @Test fun javaLinkTagWithLabel() { + verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) + } + + @Test fun javaSupertypeLink() { + verifyJavaHtmlNodes("JavaSupertype", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } + } + } + +} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt b/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt new file mode 100644 index 00000000..ee8169af --- /dev/null +++ b/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt @@ -0,0 +1,117 @@ +package org.jetbrains.dokka.tests.format + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.contentRootFromPath +import org.jetbrains.dokka.tests.BaseMarkdownFormatTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.verifyOutput +import org.junit.Test + +class JVMMarkdownFormatTest: BaseMarkdownFormatTest(Platform.jvm) { + + @Test + fun enumRef() { + verifyMarkdownNode("enumRef", defaultModelConfig) + } + + @Test + fun javaCodeLiteralTags() { + verifyJavaMarkdownNode("javaCodeLiteralTags", defaultModelConfig) + } + + @Test + fun nullability() { + verifyMarkdownNode("nullability", defaultModelConfig) + } + + @Test + fun exceptionClass() { + verifyMarkdownNode( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + verifyMarkdownPackage( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + } + + @Test + fun operatorOverloading() { + verifyMarkdownNodes("operatorOverloading", defaultModelConfig) { model-> + model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } + } + } + + @Test + fun extensions() { + verifyOutput("testdata/format/extensions.kt", ".package.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/extensions.kt", ".class.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test + fun summarizeSignaturesProperty() { + verifyMarkdownNodes("summarizeSignaturesProperty", defaultModelConfig) { model -> model.members } + } + + @Test + fun javaSpaceInAuthor() { + verifyJavaMarkdownNode("javaSpaceInAuthor", defaultModelConfig) + } + + @Test + fun javaCodeInParam() { + verifyJavaMarkdownNode("javaCodeInParam", defaultModelConfig) + } + + @Test + fun annotationParams() { + verifyMarkdownNode("annotationParams", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedLink() { + val filePath = "testdata/format/inheritedLink" + verifyOutput( + filePath, + ".md", + ModelConfig( + roots = arrayOf( + contentRootFromPath("$filePath.kt"), + contentRootFromPath("$filePath.1.kt") + ), + withJdk = true, + withKotlinRuntime = true, + includeNonPublic = false, + analysisPlatform = analysisPlatform + + ) + ) { model, output -> + buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) + } + } + + @Test + fun javadocOrderedList() { + verifyJavaMarkdownNodes("javadocOrderedList", defaultModelConfig) { model -> + model.members.single().members.filter { it.name == "Bar" } + } + } + + @Test + fun jdkLinks() { + verifyMarkdownNode("jdkLinks", ModelConfig(withKotlinRuntime = true, analysisPlatform = analysisPlatform)) + } + + @Test + fun javadocHtml() { + verifyJavaMarkdownNode("javadocHtml", defaultModelConfig) + } +} diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index b971b54d..224769e6 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -1,7 +1,6 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* -import org.junit.Before import org.junit.Ignore import org.junit.Test @@ -39,7 +38,7 @@ class KotlinWebSiteFormatTest: FileGeneratorTestCase() { } private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website/$fileName.kt", ".md", format = "kotlin-website") { model, output -> + verifyOutput("testdata/format/website/$fileName.kt", ".md", ModelConfig(format = "kotlin-website")) { model, output -> buildPagesAndReadInto( model.members.single().members.filter { it.name == name }, output @@ -57,9 +56,27 @@ class KotlinWebSiteFormatTest: FileGeneratorTestCase() { languageVersion = null, apiVersion = null ) - appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website/$path/jvm.kt")), + defaultPlatforms = listOf("JVM") + ) + + ) + + + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website/$path/jre7.kt")), + defaultPlatforms = listOf("JVM", "JRE7") + ) + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website/$path/js.kt")), + defaultPlatforms = listOf("JS") + ) + ) return module } diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index 49fa6d2f..c02d3ad4 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -1,7 +1,6 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* -import org.junit.Before import org.junit.Test class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { @@ -53,7 +52,7 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { } private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website-html/$fileName.kt", ".html", format = "kotlin-website-html") { model, output -> + verifyOutput("testdata/format/website-html/$fileName.kt", ".html", ModelConfig(format = "kotlin-website-html")) { model, output -> buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) } } @@ -68,9 +67,25 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { languageVersion = null, apiVersion = null ) - appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/jvm.kt")), + defaultPlatforms = listOf("JVM") + ) + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/jre7.kt")), + defaultPlatforms = listOf("JVM", "JRE7") + ) + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/js.kt")), + defaultPlatforms = listOf("JS") + ) + ) + return module } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt deleted file mode 100644 index 9e4c831d..00000000 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ /dev/null @@ -1,527 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.junit.Before -import org.junit.Test - -class MarkdownFormatTest: FileGeneratorTestCase() { - override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - - @Test fun emptyDescription() { - verifyMarkdownNode("emptyDescription") - } - - @Test fun classWithCompanionObject() { - verifyMarkdownNode("classWithCompanionObject") - } - - @Test fun annotations() { - verifyMarkdownNode("annotations") - } - - @Test fun annotationClass() { - verifyMarkdownNode("annotationClass", withKotlinRuntime = true) - verifyMarkdownPackage("annotationClass", withKotlinRuntime = true) - } - - @Test fun exceptionClass() { - verifyMarkdownNode("exceptionClass", withKotlinRuntime = true) - verifyMarkdownPackage("exceptionClass", withKotlinRuntime = true) - } - - @Test fun annotationParams() { - verifyMarkdownNode("annotationParams", withKotlinRuntime = true) - } - - @Test fun extensions() { - verifyOutput("testdata/format/extensions.kt", ".package.md") { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun enumClass() { - verifyOutput("testdata/format/enumClass.kt", ".md") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - verifyOutput("testdata/format/enumClass.kt", ".value.md") { model, output -> - val enumClassNode = model.members.single().members[0] - buildPagesAndReadInto( - enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, - output - ) - } - } - - @Test fun varargsFunction() { - verifyMarkdownNode("varargsFunction") - } - - @Test fun overridingFunction() { - verifyMarkdownNodes("overridingFunction") { model-> - val classMembers = model.members.single().members.first { it.name == "D" }.members - classMembers.filter { it.name == "f" } - } - } - - @Test fun propertyVar() { - verifyMarkdownNode("propertyVar") - } - - @Test fun functionWithDefaultParameter() { - verifyMarkdownNode("functionWithDefaultParameter") - } - - @Test fun accessor() { - verifyMarkdownNodes("accessor") { model -> - model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } - } - } - - @Test fun paramTag() { - verifyMarkdownNode("paramTag") - } - - @Test fun throwsTag() { - verifyMarkdownNode("throwsTag") - } - - @Test fun typeParameterBounds() { - verifyMarkdownNode("typeParameterBounds") - } - - @Test fun typeParameterVariance() { - verifyMarkdownNode("typeParameterVariance") - } - - @Test fun typeProjectionVariance() { - verifyMarkdownNode("typeProjectionVariance") - } - - @Test fun javadocHtml() { - verifyJavaMarkdownNode("javadocHtml") - } - - @Test fun javaCodeLiteralTags() { - verifyJavaMarkdownNode("javaCodeLiteralTags") - } - - @Test fun javaCodeInParam() { - verifyJavaMarkdownNode("javaCodeInParam") - } - - @Test fun javaSpaceInAuthor() { - verifyJavaMarkdownNode("javaSpaceInAuthor") - } - - @Test fun nullability() { - verifyMarkdownNode("nullability") - } - - @Test fun operatorOverloading() { - verifyMarkdownNodes("operatorOverloading") { model-> - model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } - } - } - - @Test fun javadocOrderedList() { - verifyJavaMarkdownNodes("javadocOrderedList") { model -> - model.members.single().members.filter { it.name == "Bar" } - } - } - - @Test fun codeBlockNoHtmlEscape() { - verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic") - } - - @Test fun companionObjectExtension() { - verifyMarkdownNodeByName("companionObjectExtension", "Foo") - } - - @Test fun starProjection() { - verifyMarkdownNode("starProjection") - } - - @Test fun extensionFunctionParameter() { - verifyMarkdownNode("extensionFunctionParameter") - } - - @Test fun summarizeSignatures() { - verifyMarkdownNodes("summarizeSignatures") { model -> model.members } - } - - @Test fun summarizeSignaturesProperty() { - verifyMarkdownNodes("summarizeSignaturesProperty") { model -> model.members } - } - - @Test fun reifiedTypeParameter() { - verifyMarkdownNode("reifiedTypeParameter", withKotlinRuntime = true) - } - - @Test fun annotatedTypeParameter() { - verifyMarkdownNode("annotatedTypeParameter", withKotlinRuntime = true) - } - - @Test fun inheritedMembers() { - verifyMarkdownNodeByName("inheritedMembers", "Bar") - } - - @Test fun inheritedExtensions() { - verifyMarkdownNodeByName("inheritedExtensions", "Bar") - } - - @Test fun genericInheritedExtensions() { - verifyMarkdownNodeByName("genericInheritedExtensions", "Bar") - } - - @Test fun arrayAverage() { - verifyMarkdownNodeByName("arrayAverage", "XArray") - } - - @Test fun multipleTypeParameterConstraints() { - verifyMarkdownNode("multipleTypeParameterConstraints", withKotlinRuntime = true) - } - - @Test fun inheritedCompanionObjectProperties() { - verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C") - } - - @Test fun shadowedExtensionFunctions() { - verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar") - } - - @Test fun inapplicableExtensionFunctions() { - verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar") - } - - @Test fun receiverParameterTypeBound() { - verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo") - } - - @Test fun extensionWithDocumentedReceiver() { - verifyMarkdownNodes("extensionWithDocumentedReceiver") { model -> - model.members.single().members.single().members.filter { it.name == "fn" } - } - } - - @Test fun jdkLinks() { - verifyMarkdownNode("jdkLinks", withKotlinRuntime = true) - } - - @Test fun codeBlock() { - verifyMarkdownNode("codeBlock") - } - - @Test fun exclInCodeBlock() { - verifyMarkdownNodeByName("exclInCodeBlock", "foo") - } - - @Test fun backtickInCodeBlock() { - verifyMarkdownNodeByName("backtickInCodeBlock", "foo") - } - - @Test fun qualifiedNameLink() { - verifyMarkdownNodeByName("qualifiedNameLink", "foo", withKotlinRuntime = true) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyMarkdownNode("functionalTypeWithNamedParameters") - } - - @Test fun typeAliases() { - verifyMarkdownNode("typeAliases") - verifyMarkdownPackage("typeAliases") - } - - @Test fun sampleByFQName() { - verifyMarkdownNode("sampleByFQName") - } - - @Test fun sampleByShortName() { - verifyMarkdownNode("sampleByShortName") - } - - - @Test fun suspendParam() { - verifyMarkdownNode("suspendParam") - verifyMarkdownPackage("suspendParam") - } - - @Test fun sinceKotlin() { - verifyMarkdownNode("sinceKotlin") - verifyMarkdownPackage("sinceKotlin") - } - - @Test fun sinceKotlinWide() { - verifyMarkdownPackage("sinceKotlinWide") - } - - @Test fun dynamicType() { - verifyMarkdownNode("dynamicType") - } - - @Test fun dynamicExtension() { - verifyMarkdownNodes("dynamicExtension") { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun memberExtension() { - verifyMarkdownNodes("memberExtension") { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { - verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver") - } - - @Test fun multiplePlatforms() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") - } - - @Test fun multiplePlatformsMerge() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") - } - - @Test fun multiplePlatformsMergeMembers() { - val module = buildMultiplePlatforms("multiplatform/mergeMembers") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsOmitRedundant() { - val module = buildMultiplePlatforms("multiplatform/omitRedundant") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsImplied() { - val module = buildMultiplePlatforms("multiplatform/implied") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) - fileGenerator.formatService = service - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun packagePlatformsWithExtExtensions() { - val path = "multiplatform/packagePlatformsWithExtExtensions" - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), withKotlinRuntime = true, options = options) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsPackagePlatformFromMembers() { - val path = "multiplatform/packagePlatformsFromMembers" - val module = buildMultiplePlatforms(path) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsGroupNode() { - val path = "multiplatform/groupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), - output - ) - } - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { - val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), - output - ) - } - } - - @Test fun linksInEmphasis() { - verifyMarkdownNode("linksInEmphasis") - } - - @Test fun linksInStrong() { - verifyMarkdownNode("linksInStrong") - } - - @Test fun linksInHeaders() { - verifyMarkdownNode("linksInHeaders") - } - - @Test fun tokensInEmphasis() { - verifyMarkdownNode("tokensInEmphasis") - } - - @Test fun tokensInStrong() { - verifyMarkdownNode("tokensInStrong") - } - - @Test fun tokensInHeaders() { - verifyMarkdownNode("tokensInHeaders") - } - - @Test fun unorderedLists() { - verifyMarkdownNode("unorderedLists") - } - - @Test fun nestedLists() { - verifyMarkdownNode("nestedLists") - } - - @Test fun referenceLink() { - verifyMarkdownNode("referenceLink") - } - - @Test fun externalReferenceLink() { - verifyMarkdownNode("externalReferenceLink") - } - - @Test fun newlineInTableCell() { - verifyMarkdownPackage("newlineInTableCell") - } - - @Test fun indentedCodeBlock() { - verifyMarkdownNode("indentedCodeBlock") - } - - @Test fun receiverReference() { - verifyMarkdownNode("receiverReference") - } - - @Test fun extensionScope() { - verifyMarkdownNodeByName("extensionScope", "test") - } - - @Test fun typeParameterReference() { - verifyMarkdownNode("typeParameterReference") - } - - @Test fun notPublishedTypeAliasAutoExpansion() { - verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", includeNonPublic = false) - } - - @Test fun companionImplements() { - verifyMarkdownNodeByName("companionImplements", "Foo") - } - - @Test fun enumRef() { - verifyMarkdownNode("enumRef") - } - - @Test fun inheritedLink() { - val filePath = "testdata/format/inheritedLink" - verifyOutput( - arrayOf( - contentRootFromPath("$filePath.kt"), - contentRootFromPath("$filePath.1.kt") - ), - ".md", - withJdk = true, - withKotlinRuntime = true, - includeNonPublic = false - ) { model, output -> - buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) - } - } - - - private fun buildMultiplePlatforms(path: String): DocumentationModule { - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) - return module - } - - private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { - model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - fileGenerator.formatService = service - buildPagesAndReadInto(listOf(model), output) - } - } - - @Test fun blankLineInsideCodeBlock() { - verifyMarkdownNode("blankLineInsideCodeBlock") - } - - private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { - verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - private fun verifyMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } - } - - private fun verifyMarkdownNodes( - fileName: String, - withKotlinRuntime: Boolean = false, - includeNonPublic: Boolean = true, - nodeFilter: (DocumentationModule) -> List - ) { - verifyOutput( - "testdata/format/$fileName.kt", - ".md", - withKotlinRuntime = withKotlinRuntime, - includeNonPublic = includeNonPublic - ) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - private fun verifyJavaMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyJavaMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } - } - - private fun verifyJavaMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".md", withKotlinRuntime = withKotlinRuntime) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - private fun verifyMarkdownNodeByName( - fileName: String, - name: String, - withKotlinRuntime: Boolean = false, - includeNonPublic: Boolean = true - ) { - verifyMarkdownNodes(fileName, withKotlinRuntime, includeNonPublic) { model-> - val nodesWithName = model.members.single().members.filter { it.name == name } - if (nodesWithName.isEmpty()) { - throw IllegalArgumentException("Found no nodes named $name") - } - nodesWithName - } - } -} diff --git a/core/src/test/kotlin/issues/IssuesTest.kt b/core/src/test/kotlin/issues/IssuesTest.kt index 625d7e46..58b3a2d2 100644 --- a/core/src/test/kotlin/issues/IssuesTest.kt +++ b/core/src/test/kotlin/issues/IssuesTest.kt @@ -2,8 +2,8 @@ package issues import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.tests.toTestString -import org.jetbrains.dokka.tests.verifyModel +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel import org.junit.Test import kotlin.test.assertEquals @@ -12,7 +12,8 @@ class IssuesTest { @Test fun errorClasses() { - verifyModel("testdata/issues/errorClasses.kt", withJdk = true, withKotlinRuntime = true) { model -> + checkSourceExistsAndVerifyModel("testdata/issues/errorClasses.kt", + modelConfig = ModelConfig(withJdk = true, withKotlinRuntime = true)) { model -> val cls = model.members.single().members.single() fun DocumentationNode.returnType() = this.details.find { it.kind == NodeKind.Type }?.name diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt index 45c45aa4..dc576b61 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -3,14 +3,16 @@ package org.jetbrains.dokka.javadoc import com.sun.javadoc.Tag import com.sun.javadoc.Type import org.jetbrains.dokka.DokkaConsoleLogger +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.ModelConfig import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators -import org.jetbrains.dokka.tests.verifyModel +import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel import org.junit.Assert.* import org.junit.Test class JavadocTest { @Test fun testTypes() { - verifyJavadoc("testdata/javadoc/types.kt", withJdk = true) { doc -> + verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(withJdk = true)) { doc -> val classDoc = doc.classNamed("foo.TypesKt")!! val method = classDoc.methods().find { it.name() == "foo" }!! @@ -39,7 +41,7 @@ class JavadocTest { } @Test fun testException() { - verifyJavadoc("testdata/javadoc/exception.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/exception.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.MyException")!! val member = classDoc.methods().find { it.name() == "foo" } assertEquals(classDoc, member!!.containingClass()) @@ -47,7 +49,7 @@ class JavadocTest { } @Test fun testByteArray() { - verifyJavadoc("testdata/javadoc/bytearr.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/bytearr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.ByteArray")!! assertNotNull(classDoc.asClassDoc()) @@ -57,7 +59,7 @@ class JavadocTest { } @Test fun testStringArray() { - verifyJavadoc("testdata/javadoc/stringarr.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/stringarr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.Foo")!! assertNotNull(classDoc.asClassDoc()) @@ -70,7 +72,7 @@ class JavadocTest { } @Test fun testJvmName() { - verifyJavadoc("testdata/javadoc/jvmname.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/jvmname.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.Apple")!! assertNotNull(classDoc.asClassDoc()) @@ -80,7 +82,7 @@ class JavadocTest { } @Test fun testLinkWithParam() { - verifyJavadoc("testdata/javadoc/paramlink.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/paramlink.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("demo.Apple")!! assertNotNull(classDoc.asClassDoc()) val tags = classDoc.inlineTags().filterIsInstance() @@ -91,7 +93,7 @@ class JavadocTest { } @Test fun testInternalVisibility() { - verifyJavadoc("testdata/javadoc/internal.kt", withKotlinRuntime = true, includeNonPublic = false) { doc -> + verifyJavadoc("testdata/javadoc/internal.kt", ModelConfig(withKotlinRuntime = true, includeNonPublic = false)) { doc -> val classDoc = doc.classNamed("foo.Person")!! val constructors = classDoc.constructors() assertEquals(1, constructors.size) @@ -100,7 +102,7 @@ class JavadocTest { } @Test fun testSuppress() { - verifyJavadoc("testdata/javadoc/suppress.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/suppress.kt", ModelConfig(withKotlinRuntime = true)) { doc -> assertNull(doc.classNamed("Some")) assertNull(doc.classNamed("SomeAgain")) assertNull(doc.classNamed("Interface")) @@ -111,7 +113,7 @@ class JavadocTest { } @Test fun testTypeAliases() { - verifyJavadoc("testdata/javadoc/typealiases.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/typealiases.kt", ModelConfig(withKotlinRuntime = true)) { doc -> assertNull(doc.classNamed("B")) assertNull(doc.classNamed("D")) @@ -126,7 +128,7 @@ class JavadocTest { } @Test fun testKDocKeywordsOnMethod() { - verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val method = doc.classNamed("KdocKeywordsOnMethodKt")!!.methods()[0] assertEquals("@return [ContentText(text=value of a)]", method.tags("return").first().text()) assertEquals("@param a [ContentText(text=Some string)]", method.paramTags().first().text()) @@ -136,7 +138,7 @@ class JavadocTest { @Test fun testBlankLineInsideCodeBlock() { - verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val method = doc.classNamed("BlankLineInsideCodeBlockKt")!!.methods()[0] val text = method.inlineTags().joinToString(separator = "", transform = Tag::text) assertEqualsIgnoringSeparators(""" @@ -162,12 +164,17 @@ class JavadocTest { } private fun verifyJavadoc(name: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - includeNonPublic: Boolean = true, + modelConfig: ModelConfig = ModelConfig(), callback: (ModuleNodeAdapter) -> Unit) { - verifyModel(name, format = "javadoc", withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, includeNonPublic = includeNonPublic) { model -> + checkSourceExistsAndVerifyModel(name, + ModelConfig( + analysisPlatform = Platform.jvm, + format = "javadoc", + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + includeNonPublic = modelConfig.includeNonPublic + )) { model -> val doc = ModuleNodeAdapter(model, StandardReporter(DokkaConsoleLogger), "") callback(doc) } diff --git a/core/src/test/kotlin/model/BaseClassTest.kt b/core/src/test/kotlin/model/BaseClassTest.kt new file mode 100644 index 00000000..d48ecb48 --- /dev/null +++ b/core/src/test/kotlin/model/BaseClassTest.kt @@ -0,0 +1,269 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.RefKind +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BaseClassTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun emptyClass() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertEquals("", members.single().name) + assertTrue(links.none()) + } + } + } + + @Test fun emptyObject() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Object, kind) + assertEquals("Obj", name) + assertEquals(Content.Empty, content) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun classWithConstructor() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> + with (model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(1, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(3, details.count()) + assertEquals("public", details.elementAt(0).name) + with(details.elementAt(2)) { + assertEquals("name", name) + assertEquals(NodeKind.Parameter, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithFunction() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + with(members.elementAt(1)) { + assertEquals("fn", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Function, kind) + assertEquals("Unit", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithProperty() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(1)) { + assertEquals("name", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Property, kind) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun classWithCompanionObject() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(3, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + } + with(members.elementAt(1)) { + assertEquals("x", name) + assertEquals(NodeKind.CompanionObjectProperty, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(2)) { + assertEquals("foo", name) + assertEquals(NodeKind.CompanionObjectFunction, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun dataClass() { + verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertTrue("data" in modifiers) + } + } + + @Test fun sealedClass() { + verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertEquals(1, modifiers.count { it == "sealed" }) + } + } + + @Test fun annotatedClassWithAnnotationParameters() { + checkSourceExistsAndVerifyModel( + "testdata/classes/annotatedClassWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + with(deprecation!!) { + assertEquals("Deprecated", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Annotation, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Parameter, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Value, kind) + assertEquals("\"should no longer be used\"", name) + } + } + } + } + } + } + + @Test fun notOpenClass() { + checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun indirectOverride() { + checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun innerClass() { + verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> + val innerClass = cls.members.single { it.name == "D" } + val modifiers = innerClass.details(NodeKind.Modifier) + assertEquals(3, modifiers.size) + assertEquals("inner", modifiers[2].name) + } + } + + @Test fun companionObjectExtension() { + checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> + val pkg = model.members.single() + val cls = pkg.members.single { it.name == "Foo" } + val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } + assertEquals(1, extensions.size) + } + } + + @Test fun secondaryConstructor() { + verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> + val constructors = cls.members(NodeKind.Constructor) + assertEquals(2, constructors.size) + with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { + assertEquals("", name) + assertEquals("This is a secondary constructor.", summary.toTestString()) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } + + @Test fun privateCompanionObject() { + checkSourceExistsAndVerifyModel( + "testdata/classes/privateCompanionObject.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) + ) { model -> + with(model.members.single().members.single()) { + assertEquals(0, members(NodeKind.CompanionObjectFunction).size) + assertEquals(0, members(NodeKind.CompanionObjectProperty).size) + } + } + } + +} diff --git a/core/src/test/kotlin/model/BasePropertyTest.kt b/core/src/test/kotlin/model/BasePropertyTest.kt new file mode 100644 index 00000000..c88fe702 --- /dev/null +++ b/core/src/test/kotlin/model/BasePropertyTest.kt @@ -0,0 +1,101 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BasePropertyTest(val analysisPlatform: Platform) { + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun valueProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun variableProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun valuePropertyWithGetter() { + checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun variablePropertyWithAccessors() { + checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + val modifiers = details(NodeKind.Modifier).map { it.name } + assertTrue("final" in modifiers) + assertTrue("public" in modifiers) + assertTrue("var" in modifiers) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun propertyWithReceiver() { + checkSourceExistsAndVerifyModel( + "testdata/properties/propertyWithReceiver.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + assertEquals("kotlin.String", name) + assertEquals(NodeKind.ExternalClass, kind) + with(members.single()) { + assertEquals("foobar", name) + assertEquals(NodeKind.Property, kind) + } + } + } + } + + @Test fun propertyOverride() { + checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { + assertEquals("xyzzy", name) + val override = references(RefKind.Override).single().to + assertEquals("xyzzy", override.name) + assertEquals("Foo", override.owner!!.name) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } +} diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt deleted file mode 100644 index ea586041..00000000 --- a/core/src/test/kotlin/model/ClassTest.kt +++ /dev/null @@ -1,293 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.RefKind -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -class ClassTest { - @Test fun emptyClass() { - verifyModel("testdata/classes/emptyClass.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertEquals("", members.single().name) - assertTrue(links.none()) - } - } - } - - @Test fun emptyObject() { - verifyModel("testdata/classes/emptyObject.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Object, kind) - assertEquals("Obj", name) - assertEquals(Content.Empty, content) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun classWithConstructor() { - verifyModel("testdata/classes/classWithConstructor.kt") { model -> - with (model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(1, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(3, details.count()) - assertEquals("public", details.elementAt(0).name) - with(details.elementAt(2)) { - assertEquals("name", name) - assertEquals(NodeKind.Parameter, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithFunction() { - verifyModel("testdata/classes/classWithFunction.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - with(members.elementAt(1)) { - assertEquals("fn", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Function, kind) - assertEquals("Unit", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithProperty() { - verifyModel("testdata/classes/classWithProperty.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(1)) { - assertEquals("name", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Property, kind) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun classWithCompanionObject() { - verifyModel("testdata/classes/classWithCompanionObject.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(3, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - } - with(members.elementAt(1)) { - assertEquals("x", name) - assertEquals(NodeKind.CompanionObjectProperty, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(2)) { - assertEquals("foo", name) - assertEquals(NodeKind.CompanionObjectFunction, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun annotatedClass() { - verifyPackageMember("testdata/classes/annotatedClass.kt", withKotlinRuntime = true) { cls -> - assertEquals(1, cls.annotations.count()) - with(cls.annotations[0]) { - assertEquals("Strictfp", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - - @Test fun dataClass() { - verifyPackageMember("testdata/classes/dataClass.kt") { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertTrue("data" in modifiers) - } - } - - @Test fun sealedClass() { - verifyPackageMember("testdata/classes/sealedClass.kt") { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertEquals(1, modifiers.count { it == "sealed" }) - } - } - - @Test fun annotatedClassWithAnnotationParameters() { - verifyModel("testdata/classes/annotatedClassWithAnnotationParameters.kt") { model -> - with(model.members.single().members.single()) { - with(deprecation!!) { - assertEquals("Deprecated", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("\"should no longer be used\"", name) - } - } - } - } - } - } - - @Test fun javaAnnotationClass() { - verifyModel("testdata/classes/javaAnnotationClass.kt", withJdk = true) { model -> - with(model.members.single().members.single()) { - assertEquals(1, annotations.count()) - with(annotations[0]) { - assertEquals("Retention", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("RetentionPolicy.SOURCE", name) - } - } - } - } - } - } - - @Test fun notOpenClass() { - verifyModel("testdata/classes/notOpenClass.kt") { model -> - with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun indirectOverride() { - verifyModel("testdata/classes/indirectOverride.kt") { model -> - with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun innerClass() { - verifyPackageMember("testdata/classes/innerClass.kt") { cls -> - val innerClass = cls.members.single { it.name == "D" } - val modifiers = innerClass.details(NodeKind.Modifier) - assertEquals(3, modifiers.size) - assertEquals("inner", modifiers[2].name) - } - } - - @Test fun companionObjectExtension() { - verifyModel("testdata/classes/companionObjectExtension.kt") { model -> - val pkg = model.members.single() - val cls = pkg.members.single { it.name == "Foo" } - val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } - assertEquals(1, extensions.size) - } - } - - @Test fun secondaryConstructor() { - verifyPackageMember("testdata/classes/secondaryConstructor.kt") { cls -> - val constructors = cls.members(NodeKind.Constructor) - assertEquals(2, constructors.size) - with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { - assertEquals("", name) - assertEquals("This is a secondary constructor.", summary.toTestString()) - } - } - } - - @Test fun sinceKotlin() { - verifyModel("testdata/classes/sinceKotlin.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } - - @Test fun privateCompanionObject() { - verifyModel("testdata/classes/privateCompanionObject.kt", includeNonPublic = false) { model -> - with(model.members.single().members.single()) { - assertEquals(0, members(NodeKind.CompanionObjectFunction).size) - assertEquals(0, members(NodeKind.CompanionObjectProperty).size) - } - } - } - -} diff --git a/core/src/test/kotlin/model/CommentTest.kt b/core/src/test/kotlin/model/CommentTest.kt index 3752bb8c..a97c55eb 100644 --- a/core/src/test/kotlin/model/CommentTest.kt +++ b/core/src/test/kotlin/model/CommentTest.kt @@ -7,7 +7,7 @@ import org.jetbrains.dokka.* public class CommentTest { @Test fun codeBlockComment() { - verifyModel("testdata/comments/codeBlockComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt") { model -> with(model.members.single().members.first()) { assertEqualsIgnoringSeparators("""[code lang=brainfuck] | @@ -30,7 +30,7 @@ public class CommentTest { } @Test fun emptyDoc() { - verifyModel("testdata/comments/emptyDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt") { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -38,7 +38,7 @@ public class CommentTest { } @Test fun emptyDocButComment() { - verifyModel("testdata/comments/emptyDocButComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt") { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -46,7 +46,7 @@ public class CommentTest { } @Test fun multilineDoc() { - verifyModel("testdata/comments/multilineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -55,7 +55,7 @@ public class CommentTest { } @Test fun multilineDocWithComment() { - verifyModel("testdata/comments/multilineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -64,7 +64,7 @@ public class CommentTest { } @Test fun oneLineDoc() { - verifyModel("testdata/comments/oneLineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -72,7 +72,7 @@ public class CommentTest { } @Test fun oneLineDocWithComment() { - verifyModel("testdata/comments/oneLineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -80,7 +80,7 @@ public class CommentTest { } @Test fun oneLineDocWithEmptyLine() { - verifyModel("testdata/comments/oneLineDocWithEmptyLine.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -88,7 +88,7 @@ public class CommentTest { } @Test fun emptySection() { - verifyModel("testdata/comments/emptySection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -101,7 +101,7 @@ public class CommentTest { } @Test fun quotes() { - verifyModel("testdata/comments/quotes.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt") { model -> with(model.members.single().members.single()) { assertEquals("it's \"useful\"", content.summary.toTestString()) } @@ -109,7 +109,7 @@ public class CommentTest { } @Test fun section1() { - verifyModel("testdata/comments/section1.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section1.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -122,7 +122,7 @@ public class CommentTest { } @Test fun section2() { - verifyModel("testdata/comments/section2.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section2.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(2, content.sections.count()) @@ -139,7 +139,7 @@ public class CommentTest { } @Test fun multilineSection() { - verifyModel("testdata/comments/multilineSection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -153,7 +153,7 @@ line two""", toTestString()) } @Test fun directive() { - verifyModel("testdata/comments/directive.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/directive.kt") { model -> with(model.members.single().members.first()) { assertEquals("Summary", content.summary.toTestString()) with (content.description) { diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt index 32910682..2704bf65 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -2,14 +2,16 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test -import kotlin.test.assertNotNull -class FunctionTest { +abstract class BaseFunctionTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun function() { - verifyModel("testdata/functions/function.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/function.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("fn", name) assertEquals(NodeKind.Function, kind) @@ -22,7 +24,7 @@ class FunctionTest { } @Test fun functionWithReceiver() { - verifyModel("testdata/functions/functionWithReceiver.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithReceiver.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("kotlin.String", name) assertEquals(NodeKind.ExternalClass, kind) @@ -54,7 +56,7 @@ class FunctionTest { } @Test fun genericFunction() { - verifyModel("testdata/functions/genericFunction.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/genericFunction.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("generic", name) assertEquals(NodeKind.Function, kind) @@ -78,7 +80,7 @@ class FunctionTest { } } @Test fun genericFunctionWithConstraints() { - verifyModel("testdata/functions/genericFunctionWithConstraints.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/genericFunctionWithConstraints.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("generic", name) assertEquals(NodeKind.Function, kind) @@ -118,7 +120,7 @@ class FunctionTest { } @Test fun functionWithParams() { - verifyModel("testdata/functions/functionWithParams.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithParams.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("function", name) assertEquals(NodeKind.Function, kind) @@ -143,32 +145,21 @@ Documentation""", content.description.toTestString()) } } - @Test fun annotatedFunction() { - verifyPackageMember("testdata/functions/annotatedFunction.kt", withKotlinRuntime = true) { func -> - assertEquals(1, func.annotations.count()) - with(func.annotations[0]) { - assertEquals("Strictfp", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - @Test fun functionWithNotDocumentedAnnotation() { - verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt") { func -> + verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt", defaultModelConfig) { func -> assertEquals(0, func.annotations.count()) } } @Test fun inlineFunction() { - verifyPackageMember("testdata/functions/inlineFunction.kt") { func -> + verifyPackageMember("testdata/functions/inlineFunction.kt", defaultModelConfig) { func -> val modifiers = func.details(NodeKind.Modifier).map { it.name } assertTrue("inline" in modifiers) } } @Test fun functionWithAnnotatedParam() { - verifyModel("testdata/functions/functionWithAnnotatedParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithAnnotatedParam.kt", defaultModelConfig) { model -> with(model.members.single().members.single { it.name == "function" }) { with(details(NodeKind.Parameter).first()) { assertEquals(1, annotations.count()) @@ -183,7 +174,7 @@ Documentation""", content.description.toTestString()) } @Test fun functionWithNoinlineParam() { - verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt") { func -> + verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt", defaultModelConfig) { func -> with(func.details(NodeKind.Parameter).first()) { val modifiers = details(NodeKind.Modifier).map { it.name } assertTrue("noinline" in modifiers) @@ -192,7 +183,10 @@ Documentation""", content.description.toTestString()) } @Test fun annotatedFunctionWithAnnotationParameters() { - verifyModel("testdata/functions/annotatedFunctionWithAnnotationParameters.kt") { model -> + checkSourceExistsAndVerifyModel( + "testdata/functions/annotatedFunctionWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> with(model.members.single().members.single { it.name == "f" }) { assertEquals(1, annotations.count()) with(annotations[0]) { @@ -214,7 +208,7 @@ Documentation""", content.description.toTestString()) } @Test fun functionWithDefaultParameter() { - verifyModel("testdata/functions/functionWithDefaultParameter.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithDefaultParameter.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { with(details.elementAt(3)) { val value = details(NodeKind.Value) @@ -228,7 +222,7 @@ Documentation""", content.description.toTestString()) } @Test fun sinceKotlin() { - verifyModel("testdata/functions/sinceKotlin.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/sinceKotlin.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(listOf("Kotlin 1.1"), platforms) } diff --git a/core/src/test/kotlin/model/JSClassTest.kt b/core/src/test/kotlin/model/JSClassTest.kt new file mode 100644 index 00000000..e39b95cc --- /dev/null +++ b/core/src/test/kotlin/model/JSClassTest.kt @@ -0,0 +1,6 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseClassTest + +class JSClassTest: BaseClassTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSFunctionTest.kt b/core/src/test/kotlin/model/JSFunctionTest.kt new file mode 100644 index 00000000..f6b987a9 --- /dev/null +++ b/core/src/test/kotlin/model/JSFunctionTest.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseFunctionTest + +class JSFunctionTest: BaseFunctionTest(Platform.js) { + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSPropertyTest.kt b/core/src/test/kotlin/model/JSPropertyTest.kt new file mode 100644 index 00000000..0193d899 --- /dev/null +++ b/core/src/test/kotlin/model/JSPropertyTest.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BasePropertyTest + +class JSPropertyTest: BasePropertyTest(Platform.js) { + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMClassTest.kt b/core/src/test/kotlin/model/JVMClassTest.kt new file mode 100644 index 00000000..22e23722 --- /dev/null +++ b/core/src/test/kotlin/model/JVMClassTest.kt @@ -0,0 +1,55 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseClassTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.tests.verifyPackageMember +import org.junit.Assert +import org.junit.Test + +class JVMClassTest: BaseClassTest(Platform.jvm) { + @Test + fun annotatedClass() { + verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { cls -> + Assert.assertEquals(1, cls.annotations.count()) + with(cls.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + + + @Test fun javaAnnotationClass() { + checkSourceExistsAndVerifyModel( + "testdata/classes/javaAnnotationClass.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Retention", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + with(details[0]) { + Assert.assertEquals(NodeKind.Parameter, kind) + Assert.assertEquals(1, details.count()) + with(details[0]) { + Assert.assertEquals(NodeKind.Value, kind) + Assert.assertEquals("RetentionPolicy.SOURCE", name) + } + } + } + } + } + } + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMFunctionTest.kt b/core/src/test/kotlin/model/JVMFunctionTest.kt new file mode 100644 index 00000000..a2fb0d2a --- /dev/null +++ b/core/src/test/kotlin/model/JVMFunctionTest.kt @@ -0,0 +1,29 @@ +package org.jetbrains.dokka.tests.model + +import com.sun.tools.javac.util.BaseFileManager +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseFunctionTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.verifyPackageMember +import org.junit.Assert +import org.junit.Test + +class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { + @Test + fun annotatedFunction() { + verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( + analysisPlatform = Platform.jvm, + withKotlinRuntime = true + )) { func -> + Assert.assertEquals(1, func.annotations.count()) + with(func.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMPropertyTest.kt b/core/src/test/kotlin/model/JVMPropertyTest.kt new file mode 100644 index 00000000..182dedbe --- /dev/null +++ b/core/src/test/kotlin/model/JVMPropertyTest.kt @@ -0,0 +1,33 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BasePropertyTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.junit.Assert +import org.junit.Test + +class JVMPropertyTest : BasePropertyTest(Platform.jvm) { + @Test + fun annotatedProperty() { + checkSourceExistsAndVerifyModel( + "testdata/properties/annotatedProperty.kt", + modelConfig = ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Volatile", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + } + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index e6c22ee4..946abcad 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -1,14 +1,16 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.RefKind import org.junit.Assert.* import org.junit.Ignore import org.junit.Test public class JavaTest { + private val defaultModelConfig = ModelConfig(analysisPlatform = Platform.jvm) @Test fun function() { - verifyJavaPackageMember("testdata/java/member.java") { cls -> + verifyJavaPackageMember("testdata/java/member.java", defaultModelConfig) { cls -> assertEquals("Test", cls.name) assertEquals(NodeKind.Class, cls.kind) with(cls.members(NodeKind.Function).single()) { @@ -45,7 +47,7 @@ public class JavaTest { } @Test fun memberWithModifiers() { - verifyJavaPackageMember("testdata/java/memberWithModifiers.java") { cls -> + verifyJavaPackageMember("testdata/java/memberWithModifiers.java", defaultModelConfig) { cls -> val modifiers = cls.details(NodeKind.Modifier).map { it.name } assertTrue("abstract" in modifiers) with(cls.members.single { it.name == "fn" }) { @@ -58,7 +60,7 @@ public class JavaTest { } @Test fun superClass() { - verifyJavaPackageMember("testdata/java/superClass.java") { cls -> + verifyJavaPackageMember("testdata/java/superClass.java", defaultModelConfig) { cls -> val superTypes = cls.details(NodeKind.Supertype) assertEquals(2, superTypes.size) assertEquals("Exception", superTypes[0].name) @@ -67,7 +69,7 @@ public class JavaTest { } @Test fun arrayType() { - verifyJavaPackageMember("testdata/java/arrayType.java") { cls -> + verifyJavaPackageMember("testdata/java/arrayType.java", defaultModelConfig) { cls -> with(cls.members(NodeKind.Function).single()) { val type = detail(NodeKind.Type) assertEquals("Array", type.name) @@ -81,7 +83,7 @@ public class JavaTest { } @Test fun typeParameter() { - verifyJavaPackageMember("testdata/java/typeParameter.java") { cls -> + verifyJavaPackageMember("testdata/java/typeParameter.java", defaultModelConfig) { cls -> val typeParameters = cls.details(NodeKind.TypeParameter) with(typeParameters.single()) { assertEquals("T", name) @@ -100,7 +102,7 @@ public class JavaTest { } @Test fun constructors() { - verifyJavaPackageMember("testdata/java/constructors.java") { cls -> + verifyJavaPackageMember("testdata/java/constructors.java", defaultModelConfig) { cls -> val constructors = cls.members(NodeKind.Constructor) assertEquals(2, constructors.size) with(constructors[0]) { @@ -110,14 +112,14 @@ public class JavaTest { } @Test fun innerClass() { - verifyJavaPackageMember("testdata/java/InnerClass.java") { cls -> + verifyJavaPackageMember("testdata/java/InnerClass.java", defaultModelConfig) { cls -> val innerClass = cls.members(NodeKind.Class).single() assertEquals("D", innerClass.name) } } @Test fun varargs() { - verifyJavaPackageMember("testdata/java/varargs.java") { cls -> + verifyJavaPackageMember("testdata/java/varargs.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() val param = fn.detail(NodeKind.Parameter) assertEquals("vararg", param.details(NodeKind.Modifier).first().name) @@ -128,7 +130,7 @@ public class JavaTest { } @Test fun fields() { - verifyJavaPackageMember("testdata/java/field.java") { cls -> + verifyJavaPackageMember("testdata/java/field.java", defaultModelConfig) { cls -> val i = cls.members(NodeKind.Property).single { it.name == "i" } assertEquals("Int", i.detail(NodeKind.Type).name) assertTrue("var" in i.details(NodeKind.Modifier).map { it.name }) @@ -141,7 +143,7 @@ public class JavaTest { } @Test fun staticMethod() { - verifyJavaPackageMember("testdata/java/staticMethod.java") { cls -> + verifyJavaPackageMember("testdata/java/staticMethod.java", defaultModelConfig) { cls -> val m = cls.members(NodeKind.Function).single { it.name == "foo" } assertTrue("static" in m.details(NodeKind.Modifier).map { it.name }) } @@ -154,13 +156,13 @@ public class JavaTest { * Proposed tag `@exclude` for it, but not supported yet */ @Ignore("@suppress not supported in Java!") @Test fun suppressTag() { - verifyJavaPackageMember("testdata/java/suppressTag.java") { cls -> + verifyJavaPackageMember("testdata/java/suppressTag.java", defaultModelConfig) { cls -> assertEquals(1, cls.members(NodeKind.Function).size) } } @Test fun annotatedAnnotation() { - verifyJavaPackageMember("testdata/java/annotatedAnnotation.java") { cls -> + verifyJavaPackageMember("testdata/java/annotatedAnnotation.java", defaultModelConfig) { cls -> assertEquals(1, cls.annotations.size) with(cls.annotations[0]) { assertEquals(1, details.count()) @@ -177,21 +179,21 @@ public class JavaTest { } @Test fun deprecation() { - verifyJavaPackageMember("testdata/java/deprecation.java") { cls -> + verifyJavaPackageMember("testdata/java/deprecation.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() assertEquals("This should no longer be used", fn.deprecation!!.content.toTestString()) } } @Test fun javaLangObject() { - verifyJavaPackageMember("testdata/java/javaLangObject.java") { cls -> + verifyJavaPackageMember("testdata/java/javaLangObject.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() assertEquals("Any", fn.detail(NodeKind.Type).name) } } @Test fun enumValues() { - verifyJavaPackageMember("testdata/java/enumValues.java") { cls -> + verifyJavaPackageMember("testdata/java/enumValues.java", defaultModelConfig) { cls -> val superTypes = cls.details(NodeKind.Supertype) assertEquals(0, superTypes.size) assertEquals(1, cls.members(NodeKind.EnumItem).size) @@ -199,7 +201,7 @@ public class JavaTest { } @Test fun inheritorLinks() { - verifyJavaPackageMember("testdata/java/InheritorLinks.java") { cls -> + verifyJavaPackageMember("testdata/java/InheritorLinks.java", defaultModelConfig) { cls -> val fooClass = cls.members.single { it.name == "Foo" } val inheritors = fooClass.references(RefKind.Inheritor) assertEquals(1, inheritors.size) diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index d24d8bdd..1d95556f 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -2,10 +2,13 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.DocumentationModule import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.junit.Test import org.junit.Assert.assertEquals class KotlinAsJavaTest { + private val defaultModelConfig = ModelConfig (analysisPlatform = Platform.jvm) + @Test fun function() { verifyModelAsJava("testdata/functions/function.kt") { model -> val pkg = model.members.single() @@ -33,8 +36,13 @@ fun verifyModelAsJava(source: String, withJdk: Boolean = false, withKotlinRuntime: Boolean = false, verifier: (DocumentationModule) -> Unit) { - verifyModel(source, - withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, + checkSourceExistsAndVerifyModel( + source, + modelConfig = ModelConfig( + withJdk = withJdk, + withKotlinRuntime = withKotlinRuntime, format = "html-as-java", - verifier = verifier) + analysisPlatform = Platform.jvm), + verifier = verifier + ) } diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt index 6b72525f..d7283bae 100644 --- a/core/src/test/kotlin/model/LinkTest.kt +++ b/core/src/test/kotlin/model/LinkTest.kt @@ -8,7 +8,7 @@ import org.junit.Test class LinkTest { @Test fun linkToSelf() { - verifyModel("testdata/links/linkToSelf.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -18,7 +18,7 @@ class LinkTest { } @Test fun linkToMember() { - verifyModel("testdata/links/linkToMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -28,7 +28,7 @@ class LinkTest { } @Test fun linkToConstantWithUnderscores() { - verifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -38,7 +38,7 @@ class LinkTest { } @Test fun linkToQualifiedMember() { - verifyModel("testdata/links/linkToQualifiedMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -48,7 +48,7 @@ class LinkTest { } @Test fun linkToParam() { - verifyModel("testdata/links/linkToParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Function, kind) @@ -58,7 +58,7 @@ class LinkTest { } @Test fun linkToPackage() { - verifyModel("testdata/links/linkToPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt") { model -> val packageNode = model.members.single() with(packageNode) { assertEquals(this.name, "test.magic") diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt index 052f0d28..bc8a0e0d 100644 --- a/core/src/test/kotlin/model/PackageTest.kt +++ b/core/src/test/kotlin/model/PackageTest.kt @@ -9,7 +9,7 @@ import org.junit.Test public class PackageTest { @Test fun rootPackage() { - verifyModel("testdata/packages/rootPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt") { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("", name) @@ -22,7 +22,7 @@ public class PackageTest { } @Test fun simpleNamePackage() { - verifyModel("testdata/packages/simpleNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt") { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("simple", name) @@ -35,7 +35,7 @@ public class PackageTest { } @Test fun dottedNamePackage() { - verifyModel("testdata/packages/dottedNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt") { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("dot.name", name) @@ -48,8 +48,14 @@ public class PackageTest { } @Test fun multipleFiles() { - verifyModel(KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), - KotlinSourceRoot("testdata/packages/simpleNamePackage.kt")) { model -> + verifyModel( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), + KotlinSourceRoot("testdata/packages/simpleNamePackage.kt") + ) + ) + ) { model -> assertEquals(2, model.members.count()) with(model.members.single { it.name == "simple" }) { assertEquals(NodeKind.Package, kind) @@ -70,8 +76,14 @@ public class PackageTest { } @Test fun multipleFilesSamePackage() { - verifyModel(KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), - KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt")) { model -> + verifyModel( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), + KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt") + ) + ) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) @@ -85,7 +97,9 @@ public class PackageTest { } @Test fun classAtPackageLevel() { - verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt")) { model -> + verifyModel( + ModelConfig(roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt"))) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) @@ -99,8 +113,14 @@ public class PackageTest { } @Test fun suppressAtPackageLevel() { - verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt"), - perPackageOptions = listOf(PackageOptionsImpl(prefix = "simple.name", suppress = true))) { model -> + verifyModel( + ModelConfig( + roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), + perPackageOptions = listOf( + PackageOptionsImpl(prefix = "simple.name", suppress = true) + ) + ) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) diff --git a/core/src/test/kotlin/model/PropertyTest.kt b/core/src/test/kotlin/model/PropertyTest.kt deleted file mode 100644 index 0ee0e0f5..00000000 --- a/core/src/test/kotlin/model/PropertyTest.kt +++ /dev/null @@ -1,111 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.RefKind -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -class PropertyTest { - @Test fun valueProperty() { - verifyModel("testdata/properties/valueProperty.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun variableProperty() { - verifyModel("testdata/properties/variableProperty.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun valuePropertyWithGetter() { - verifyModel("testdata/properties/valuePropertyWithGetter.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun variablePropertyWithAccessors() { - verifyModel("testdata/properties/variablePropertyWithAccessors.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - val modifiers = details(NodeKind.Modifier).map { it.name } - assertTrue("final" in modifiers) - assertTrue("public" in modifiers) - assertTrue("var" in modifiers) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun annotatedProperty() { - verifyModel("testdata/properties/annotatedProperty.kt", withKotlinRuntime = true) { model -> - with(model.members.single().members.single()) { - assertEquals(1, annotations.count()) - with(annotations[0]) { - assertEquals("Volatile", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - } - - @Test fun propertyWithReceiver() { - verifyModel("testdata/properties/propertyWithReceiver.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("kotlin.String", name) - assertEquals(NodeKind.ExternalClass, kind) - with(members.single()) { - assertEquals("foobar", name) - assertEquals(NodeKind.Property, kind) - } - } - } - } - - @Test fun propertyOverride() { - verifyModel("testdata/properties/propertyOverride.kt") { model -> - with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { - assertEquals("xyzzy", name) - val override = references(RefKind.Override).single().to - assertEquals("xyzzy", override.name) - assertEquals("Foo", override.owner!!.name) - } - } - } - - @Test fun sinceKotlin() { - verifyModel("testdata/properties/sinceKotlin.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } -} diff --git a/core/src/test/kotlin/model/TypeAliasTest.kt b/core/src/test/kotlin/model/TypeAliasTest.kt index c653ac83..a011b44f 100644 --- a/core/src/test/kotlin/model/TypeAliasTest.kt +++ b/core/src/test/kotlin/model/TypeAliasTest.kt @@ -8,7 +8,7 @@ import org.junit.Test class TypeAliasTest { @Test fun testSimple() { - verifyModel("testdata/typealias/simple.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/simple.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -20,7 +20,7 @@ class TypeAliasTest { @Test fun testInheritanceFromTypeAlias() { - verifyModel("testdata/typealias/inheritanceFromTypeAlias.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/inheritanceFromTypeAlias.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -36,7 +36,7 @@ class TypeAliasTest { @Test fun testChain() { - verifyModel("testdata/typealias/chain.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/chain.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) { assertEquals(Content.Empty, content) @@ -51,7 +51,7 @@ class TypeAliasTest { @Test fun testDocumented() { - verifyModel("testdata/typealias/documented.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/documented.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals("Just typealias", content.summary.toTestString()) @@ -61,7 +61,7 @@ class TypeAliasTest { @Test fun testDeprecated() { - verifyModel("testdata/typealias/deprecated.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/deprecated.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -73,7 +73,7 @@ class TypeAliasTest { @Test fun testGeneric() { - verifyModel("testdata/typealias/generic.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/generic.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) { assertEquals("Any", detail(NodeKind.TypeAliasUnderlyingType).detail(NodeKind.Type).name) @@ -88,7 +88,7 @@ class TypeAliasTest { @Test fun testFunctional() { - verifyModel("testdata/typealias/functional.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/functional.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals("Function1", detail(NodeKind.TypeAliasUnderlyingType).name) @@ -105,7 +105,7 @@ class TypeAliasTest { @Test fun testAsTypeBoundWithVariance() { - verifyModel("testdata/typealias/asTypeBoundWithVariance.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/asTypeBoundWithVariance.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.Class).find { it.name == "C" }!!) { val tParam = detail(NodeKind.TypeParameter) @@ -123,7 +123,7 @@ class TypeAliasTest { @Test fun sinceKotlin() { - verifyModel("testdata/typealias/sinceKotlin.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/typealias/sinceKotlin.kt") { model -> with(model.members.single().members.single()) { assertEquals(listOf("Kotlin 1.1"), platforms) } -- cgit From 742be4ef7c024a5ea6023fb684cd24d1898f37e4 Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Thu, 12 Jul 2018 20:23:02 +0300 Subject: Test refactoring, add common platform tests --- core/src/test/kotlin/TestAPI.kt | 15 +- core/src/test/kotlin/format/BaseHtmlFormatTest.kt | 146 ------ .../test/kotlin/format/BaseMarkdownFormatTest.kt | 467 ----------------- core/src/test/kotlin/format/GFMFormatTest.kt | 18 +- core/src/test/kotlin/format/HtmlFormatTest.kt | 193 +++++++ core/src/test/kotlin/format/JSHtmlFormatTest.kt | 6 - .../src/test/kotlin/format/JSMarkdownFormatTest.kt | 7 - core/src/test/kotlin/format/JVMHtmlFormatTest.kt | 54 -- .../test/kotlin/format/JVMMarkdownFormatTest.kt | 117 ----- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 29 +- core/src/test/kotlin/format/MarkdownFormatTest.kt | 580 +++++++++++++++++++++ core/src/test/kotlin/issues/IssuesTest.kt | 11 +- core/src/test/kotlin/javadoc/JavadocTest.kt | 58 ++- core/src/test/kotlin/model/BaseClassTest.kt | 269 ---------- core/src/test/kotlin/model/BasePropertyTest.kt | 101 ---- core/src/test/kotlin/model/ClassTest.kt | 318 +++++++++++ core/src/test/kotlin/model/CommentTest.kt | 36 +- core/src/test/kotlin/model/FunctionTest.kt | 23 + core/src/test/kotlin/model/JSClassTest.kt | 6 - core/src/test/kotlin/model/JSFunctionTest.kt | 8 - core/src/test/kotlin/model/JSPropertyTest.kt | 8 - core/src/test/kotlin/model/JVMClassTest.kt | 55 -- core/src/test/kotlin/model/JVMFunctionTest.kt | 29 -- core/src/test/kotlin/model/JVMPropertyTest.kt | 33 -- core/src/test/kotlin/model/KotlinAsJavaTest.kt | 9 +- core/src/test/kotlin/model/LinkTest.kt | 22 +- core/src/test/kotlin/model/PackageTest.kt | 31 +- core/src/test/kotlin/model/PropertyTest.kt | 129 +++++ 28 files changed, 1395 insertions(+), 1383 deletions(-) delete mode 100644 core/src/test/kotlin/format/BaseHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/BaseMarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/format/HtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JSHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JSMarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JVMHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JVMMarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/format/MarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/model/BaseClassTest.kt delete mode 100644 core/src/test/kotlin/model/BasePropertyTest.kt create mode 100644 core/src/test/kotlin/model/ClassTest.kt delete mode 100644 core/src/test/kotlin/model/JSClassTest.kt delete mode 100644 core/src/test/kotlin/model/JSFunctionTest.kt delete mode 100644 core/src/test/kotlin/model/JSPropertyTest.kt delete mode 100644 core/src/test/kotlin/model/JVMClassTest.kt delete mode 100644 core/src/test/kotlin/model/JVMFunctionTest.kt delete mode 100644 core/src/test/kotlin/model/JVMPropertyTest.kt create mode 100644 core/src/test/kotlin/model/PropertyTest.kt (limited to 'core/src/test') diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index bcbbf2fc..7042f41b 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.config.ContentRoot import org.jetbrains.kotlin.config.KotlinSourceRoot 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 @@ -24,7 +25,7 @@ data class ModelConfig( val format: String = "html", val includeNonPublic: Boolean = true, val perPackageOptions: List = emptyList(), - val analysisPlatform: Platform = Platform.js, + val analysisPlatform: Platform = Platform.DEFAULT, val defaultPlatforms: List = emptyList() ) @@ -84,18 +85,22 @@ fun appendDocumentation(documentation: DocumentationModule, val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) environment.apply { if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { - val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class") - addClasspath(File(stringRoot)) + addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } if (modelConfig.withKotlinRuntime) { - val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") - addClasspath(File(kotlinStrictfpRoot)) + if (analysisPlatform == Platform.jvm) { + val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") + addClasspath(File(kotlinStrictfpRoot)) + } // TODO: Fix concrete path to correct gradle path providing if (analysisPlatform == Platform.js) { addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-jslib.jar")) addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js.jar")) addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js-sources.jar")) } + if (analysisPlatform == Platform.common) { + addClasspath(File("/home/jetbrains/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.51/e4a9d4b13ab19ed1e6531fce6df98e8cfa7f7301/kotlin-stdlib-common-1.2.51.jar")) + } } addRoots(modelConfig.roots.toList()) diff --git a/core/src/test/kotlin/format/BaseHtmlFormatTest.kt b/core/src/test/kotlin/format/BaseHtmlFormatTest.kt deleted file mode 100644 index 7fd331cf..00000000 --- a/core/src/test/kotlin/format/BaseHtmlFormatTest.kt +++ /dev/null @@ -1,146 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.junit.Before -import org.junit.Test -import java.io.File - -abstract class BaseHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) - - @Test fun classWithCompanionObject() { - verifyHtmlNode("classWithCompanionObject", defaultModelConfig) - } - - @Test fun htmlEscaping() { - verifyHtmlNode("htmlEscaping", defaultModelConfig) - } - - @Test fun overloads() { - verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } - } - - @Test fun overloadsWithDescription() { - verifyHtmlNode("overloadsWithDescription", defaultModelConfig) - } - - @Test fun overloadsWithDifferentDescriptions() { - verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) - } - - @Test fun deprecated() { - verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun brokenLink() { - verifyHtmlNode("brokenLink", defaultModelConfig) - } - - @Test fun codeSpan() { - verifyHtmlNode("codeSpan", defaultModelConfig) - } - - @Test fun parenthesis() { - verifyHtmlNode("parenthesis", defaultModelConfig) - } - - @Test fun bracket() { - verifyHtmlNode("bracket", defaultModelConfig) - } - - @Test fun see() { - verifyHtmlNode("see", defaultModelConfig) - } - - @Test fun tripleBackticks() { - verifyHtmlNode("tripleBackticks", defaultModelConfig) - } - - @Test fun typeLink() { - verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun parameterAnchor() { - verifyHtmlNode("parameterAnchor", defaultModelConfig) - } - - @Test fun codeBlock() { - verifyHtmlNode("codeBlock", defaultModelConfig) - } - @Test fun orderedList() { - verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun linkWithLabel() { - verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun entity() { - verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun uninterpretedEmphasisCharacters() { - verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) - } - - @Test fun markdownInLinks() { - verifyHtmlNode("markdownInLinks", defaultModelConfig) - } - - @Test fun returnWithLink() { - verifyHtmlNode("returnWithLink", defaultModelConfig) - } - - @Test fun linkWithStarProjection() { - verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) - } - - @Test fun sinceKotlin() { - verifyHtmlNode("sinceKotlin", defaultModelConfig) - } - - @Test fun blankLineInsideCodeBlock() { - verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) - } - - @Test fun indentedCodeBlock() { - verifyHtmlNode("indentedCodeBlock", defaultModelConfig) - } - - private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - private fun verifyHtmlNodes(fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List) { - verifyOutput("testdata/format/$fileName.kt", ".html", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyJavaHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyJavaHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyJavaHtmlNodes(fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".html", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } -} - diff --git a/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt b/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt deleted file mode 100644 index 5612b1fd..00000000 --- a/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt +++ /dev/null @@ -1,467 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.junit.Before -import org.junit.Test - -abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { - override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - - @Test fun emptyDescription() { - verifyMarkdownNode("emptyDescription", defaultModelConfig) - } - - @Test fun classWithCompanionObject() { - verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) - } - - @Test fun annotations() { - verifyMarkdownNode("annotations", defaultModelConfig) - } - - @Test fun annotationClass() { - verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun enumClass() { - verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> - val enumClassNode = model.members.single().members[0] - buildPagesAndReadInto( - enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, - output - ) - } - } - - @Test fun varargsFunction() { - verifyMarkdownNode("varargsFunction", defaultModelConfig) - } - - @Test fun overridingFunction() { - verifyMarkdownNodes("overridingFunction", defaultModelConfig) { model-> - val classMembers = model.members.single().members.first { it.name == "D" }.members - classMembers.filter { it.name == "f" } - } - } - - @Test fun propertyVar() { - verifyMarkdownNode("propertyVar", defaultModelConfig) - } - - @Test fun functionWithDefaultParameter() { - verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) - } - - @Test fun accessor() { - verifyMarkdownNodes("accessor", defaultModelConfig) { model -> - model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } - } - } - - @Test fun paramTag() { - verifyMarkdownNode("paramTag", defaultModelConfig) - } - - @Test fun throwsTag() { - verifyMarkdownNode("throwsTag", defaultModelConfig) - } - - @Test fun typeParameterBounds() { - verifyMarkdownNode("typeParameterBounds", defaultModelConfig) - } - - @Test fun typeParameterVariance() { - verifyMarkdownNode("typeParameterVariance", defaultModelConfig) - } - - @Test fun typeProjectionVariance() { - verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) - } - - @Test fun codeBlockNoHtmlEscape() { - verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) - } - - @Test fun companionObjectExtension() { - verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) - } - - @Test fun starProjection() { - verifyMarkdownNode("starProjection", defaultModelConfig) - } - - @Test fun extensionFunctionParameter() { - verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) - } - - @Test fun summarizeSignatures() { - verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } - } - - @Test fun reifiedTypeParameter() { - verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun annotatedTypeParameter() { - verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedMembers() { - verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) - } - - @Test fun inheritedExtensions() { - verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) - } - - @Test fun genericInheritedExtensions() { - verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) - } - - @Test fun arrayAverage() { - verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) - } - - @Test fun multipleTypeParameterConstraints() { - verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedCompanionObjectProperties() { - verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) - } - - @Test fun shadowedExtensionFunctions() { - verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) - } - - @Test fun inapplicableExtensionFunctions() { - verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) - } - - @Test fun receiverParameterTypeBound() { - verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) - } - - @Test fun extensionWithDocumentedReceiver() { - verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> - model.members.single().members.single().members.filter { it.name == "fn" } - } - } - - @Test fun codeBlock() { - verifyMarkdownNode("codeBlock", defaultModelConfig) - } - - @Test fun exclInCodeBlock() { - verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) - } - - @Test fun backtickInCodeBlock() { - verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) - } - - @Test fun qualifiedNameLink() { - verifyMarkdownNodeByName("qualifiedNameLink", "foo", - ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) - } - - @Test fun typeAliases() { - verifyMarkdownNode("typeAliases", defaultModelConfig) - verifyMarkdownPackage("typeAliases", defaultModelConfig) - } - - @Test fun sampleByShortName() { - verifyMarkdownNode("sampleByShortName", defaultModelConfig) - } - - - @Test fun suspendParam() { - verifyMarkdownNode("suspendParam", defaultModelConfig) - verifyMarkdownPackage("suspendParam", defaultModelConfig) - } - - @Test fun sinceKotlin() { - verifyMarkdownNode("sinceKotlin", defaultModelConfig) - verifyMarkdownPackage("sinceKotlin", defaultModelConfig) - } - - @Test fun sinceKotlinWide() { - verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) - } - - @Test fun dynamicType() { - verifyMarkdownNode("dynamicType", defaultModelConfig) - } - - @Test fun dynamicExtension() { - verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun memberExtension() { - verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { - verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) - } - - @Test fun multiplePlatforms() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") - } - - @Test fun multiplePlatformsMerge() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") - } - - @Test fun multiplePlatformsMergeMembers() { - val module = buildMultiplePlatforms("multiplatform/mergeMembers") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsOmitRedundant() { - val module = buildMultiplePlatforms("multiplatform/omitRedundant") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsImplied() { - val module = buildMultiplePlatforms("multiplatform/implied") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) - fileGenerator.formatService = service - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun packagePlatformsWithExtExtensions() { - val path = "multiplatform/packagePlatformsWithExtExtensions" - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation(module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), - defaultPlatforms = listOf("JVM"), - withKotlinRuntime = true, - analysisPlatform = analysisPlatform - ) - ) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsPackagePlatformFromMembers() { - val path = "multiplatform/packagePlatformsFromMembers" - val module = buildMultiplePlatforms(path) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsGroupNode() { - val path = "multiplatform/groupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), - output - ) - } - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { - val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), - output - ) - } - } - - @Test fun linksInEmphasis() { - verifyMarkdownNode("linksInEmphasis", defaultModelConfig) - } - - @Test fun linksInStrong() { - verifyMarkdownNode("linksInStrong", defaultModelConfig) - } - - @Test fun linksInHeaders() { - verifyMarkdownNode("linksInHeaders", defaultModelConfig) - } - - @Test fun tokensInEmphasis() { - verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) - } - - @Test fun tokensInStrong() { - verifyMarkdownNode("tokensInStrong", defaultModelConfig) - } - - @Test fun tokensInHeaders() { - verifyMarkdownNode("tokensInHeaders", defaultModelConfig) - } - - @Test fun unorderedLists() { - verifyMarkdownNode("unorderedLists", defaultModelConfig) - } - - @Test fun nestedLists() { - verifyMarkdownNode("nestedLists", defaultModelConfig) - } - - @Test fun referenceLink() { - verifyMarkdownNode("referenceLink", defaultModelConfig) - } - - @Test fun externalReferenceLink() { - verifyMarkdownNode("externalReferenceLink", defaultModelConfig) - } - - @Test fun newlineInTableCell() { - verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) - } - - @Test fun indentedCodeBlock() { - verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) - } - - @Test fun receiverReference() { - verifyMarkdownNode("receiverReference", defaultModelConfig) - } - - @Test fun extensionScope() { - verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) - } - - @Test fun typeParameterReference() { - verifyMarkdownNode("typeParameterReference", defaultModelConfig) - } - - @Test fun notPublishedTypeAliasAutoExpansion() { - verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( - analysisPlatform = analysisPlatform, - includeNonPublic = false - )) - } - - @Test fun companionImplements() { - verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) - } - - - private fun buildMultiplePlatforms(path: String): DocumentationModule { - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation( - module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), - defaultPlatforms = listOf("JVM"), - analysisPlatform = Platform.jvm - ) - ) - appendDocumentation( - module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), - defaultPlatforms = listOf("JS"), - analysisPlatform = Platform.js - ) - ) - - return module - } - - private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { - model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - fileGenerator.formatService = service - buildPagesAndReadInto(listOf(model), output) - } - } - - @Test fun blankLineInsideCodeBlock() { - verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) - } - - protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyMarkdownNodes( - fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List - ) { - verifyOutput( - "testdata/format/$fileName.kt", - ".md", - modelConfig - ) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyMarkdownNodeByName( - fileName: String, - name: String, - modelConfig: ModelConfig = ModelConfig() - ) { - verifyMarkdownNodes(fileName, modelConfig) { model-> - val nodesWithName = model.members.single().members.filter { it.name == name } - if (nodesWithName.isEmpty()) { - throw IllegalArgumentException("Found no nodes named $name") - } - nodesWithName - } - } -} diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt index b90ab2bf..60de7d29 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -2,23 +2,26 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.GFMFormatService import org.jetbrains.dokka.KotlinLanguageService +import org.jetbrains.dokka.Platform import org.junit.Test -class GFMFormatTest : FileGeneratorTestCase() { +abstract class BaseGFMFormatTest(val analysisPlatform: Platform) : FileGeneratorTestCase() { override val formatService = GFMFormatService(fileGenerator, KotlinLanguageService(), listOf()) + private val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun sample() { - verifyGFMNodeByName("sample", "Foo") + verifyGFMNodeByName("sample", "Foo", defaultModelConfig) } @Test fun listInTableCell() { - verifyGFMNodeByName("listInTableCell", "Foo") + verifyGFMNodeByName("listInTableCell", "Foo", defaultModelConfig) } - private fun verifyGFMNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> + private fun verifyGFMNodeByName(fileName: String, name: String, modelConfig: ModelConfig) { + verifyOutput("testdata/format/gfm/$fileName.kt", ".md", modelConfig) { model, output -> buildPagesAndReadInto( model.members.single().members.filter { it.name == name }, output @@ -26,3 +29,8 @@ class GFMFormatTest : FileGeneratorTestCase() { } } } + + +class JsGFMFormatTest : BaseGFMFormatTest(Platform.js) +class JvmGFMFormatTest : BaseGFMFormatTest(Platform.jvm) +class CommonGFMFormatTest : BaseGFMFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt new file mode 100644 index 00000000..20891963 --- /dev/null +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -0,0 +1,193 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.junit.Before +import org.junit.Test +import java.io.File + +abstract class BaseHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) + + @Test fun classWithCompanionObject() { + verifyHtmlNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun htmlEscaping() { + verifyHtmlNode("htmlEscaping", defaultModelConfig) + } + + @Test fun overloads() { + verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } + } + + @Test fun overloadsWithDescription() { + verifyHtmlNode("overloadsWithDescription", defaultModelConfig) + } + + @Test fun overloadsWithDifferentDescriptions() { + verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) + } + + @Test fun deprecated() { + verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun brokenLink() { + verifyHtmlNode("brokenLink", defaultModelConfig) + } + + @Test fun codeSpan() { + verifyHtmlNode("codeSpan", defaultModelConfig) + } + + @Test fun parenthesis() { + verifyHtmlNode("parenthesis", defaultModelConfig) + } + + @Test fun bracket() { + verifyHtmlNode("bracket", defaultModelConfig) + } + + @Test fun see() { + verifyHtmlNode("see", defaultModelConfig) + } + + @Test fun tripleBackticks() { + verifyHtmlNode("tripleBackticks", defaultModelConfig) + } + + @Test fun typeLink() { + verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun parameterAnchor() { + verifyHtmlNode("parameterAnchor", defaultModelConfig) + } + + @Test fun codeBlock() { + verifyHtmlNode("codeBlock", defaultModelConfig) + } + @Test fun orderedList() { + verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun linkWithLabel() { + verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun entity() { + verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun uninterpretedEmphasisCharacters() { + verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) + } + + @Test fun markdownInLinks() { + verifyHtmlNode("markdownInLinks", defaultModelConfig) + } + + @Test fun returnWithLink() { + verifyHtmlNode("returnWithLink", defaultModelConfig) + } + + @Test fun linkWithStarProjection() { + verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyHtmlNode("sinceKotlin", defaultModelConfig) + } + + @Test fun blankLineInsideCodeBlock() { + verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyHtmlNode("indentedCodeBlock", defaultModelConfig) + } + + private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + private fun verifyHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyOutput("testdata/format/$fileName.kt", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } +} + +class JSHtmlFormatTest: BaseHtmlFormatTest(Platform.js) + +class JVMHtmlFormatTest: BaseHtmlFormatTest(Platform.jvm) { + @Test + fun javaSeeTag() { + verifyJavaHtmlNode("javaSeeTag", defaultModelConfig) + } + + @Test fun javaDeprecated() { + verifyJavaHtmlNodes("javaDeprecated", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } + } + } + + @Test fun crossLanguageKotlinExtendsJava() { + verifyOutput( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), + JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null) + ), + analysisPlatform = analysisPlatform + ), ".html") { model, output -> + buildPagesAndReadInto( + model.members.single().members.filter { it.name == "Bar" }, + output + ) + } + } + + @Test fun javaLinkTag() { + verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) + } + + @Test fun javaLinkTagWithLabel() { + verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) + } + + @Test fun javaSupertypeLink() { + verifyJavaHtmlNodes("JavaSupertype", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } + } + } + +} + +class CommonHtmlFormatTest: BaseHtmlFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/JSHtmlFormatTest.kt b/core/src/test/kotlin/format/JSHtmlFormatTest.kt deleted file mode 100644 index afa0ce0a..00000000 --- a/core/src/test/kotlin/format/JSHtmlFormatTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseHtmlFormatTest - -class JSHtmlFormatTest: BaseHtmlFormatTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JSMarkdownFormatTest.kt b/core/src/test/kotlin/format/JSMarkdownFormatTest.kt deleted file mode 100644 index ca92d9f6..00000000 --- a/core/src/test/kotlin/format/JSMarkdownFormatTest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseMarkdownFormatTest - -class JSMarkdownFormatTest: BaseMarkdownFormatTest(Platform.js) { -} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMHtmlFormatTest.kt b/core/src/test/kotlin/format/JVMHtmlFormatTest.kt deleted file mode 100644 index 1696ffb2..00000000 --- a/core/src/test/kotlin/format/JVMHtmlFormatTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseHtmlFormatTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyOutput -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.junit.Test -import java.io.File - -class JVMHtmlFormatTest: BaseHtmlFormatTest(Platform.jvm) { - @Test - fun javaSeeTag() { - verifyJavaHtmlNode("javaSeeTag", defaultModelConfig) - } - - @Test fun javaDeprecated() { - verifyJavaHtmlNodes("javaDeprecated", defaultModelConfig) { model -> - model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } - } - } - - @Test fun crossLanguageKotlinExtendsJava() { - verifyOutput( - ModelConfig( - roots = arrayOf( - KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), - JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null) - ), - analysisPlatform = analysisPlatform - ), ".html") { model, output -> - buildPagesAndReadInto( - model.members.single().members.filter { it.name == "Bar" }, - output - ) - } - } - - @Test fun javaLinkTag() { - verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) - } - - @Test fun javaLinkTagWithLabel() { - verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) - } - - @Test fun javaSupertypeLink() { - verifyJavaHtmlNodes("JavaSupertype", defaultModelConfig) { model -> - model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt b/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt deleted file mode 100644 index ee8169af..00000000 --- a/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt +++ /dev/null @@ -1,117 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.contentRootFromPath -import org.jetbrains.dokka.tests.BaseMarkdownFormatTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyOutput -import org.junit.Test - -class JVMMarkdownFormatTest: BaseMarkdownFormatTest(Platform.jvm) { - - @Test - fun enumRef() { - verifyMarkdownNode("enumRef", defaultModelConfig) - } - - @Test - fun javaCodeLiteralTags() { - verifyJavaMarkdownNode("javaCodeLiteralTags", defaultModelConfig) - } - - @Test - fun nullability() { - verifyMarkdownNode("nullability", defaultModelConfig) - } - - @Test - fun exceptionClass() { - verifyMarkdownNode( - "exceptionClass", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) - verifyMarkdownPackage( - "exceptionClass", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) - } - - @Test - fun operatorOverloading() { - verifyMarkdownNodes("operatorOverloading", defaultModelConfig) { model-> - model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } - } - } - - @Test - fun extensions() { - verifyOutput("testdata/format/extensions.kt", ".package.md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/extensions.kt", ".class.md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test - fun summarizeSignaturesProperty() { - verifyMarkdownNodes("summarizeSignaturesProperty", defaultModelConfig) { model -> model.members } - } - - @Test - fun javaSpaceInAuthor() { - verifyJavaMarkdownNode("javaSpaceInAuthor", defaultModelConfig) - } - - @Test - fun javaCodeInParam() { - verifyJavaMarkdownNode("javaCodeInParam", defaultModelConfig) - } - - @Test - fun annotationParams() { - verifyMarkdownNode("annotationParams", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedLink() { - val filePath = "testdata/format/inheritedLink" - verifyOutput( - filePath, - ".md", - ModelConfig( - roots = arrayOf( - contentRootFromPath("$filePath.kt"), - contentRootFromPath("$filePath.1.kt") - ), - withJdk = true, - withKotlinRuntime = true, - includeNonPublic = false, - analysisPlatform = analysisPlatform - - ) - ) { model, output -> - buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) - } - } - - @Test - fun javadocOrderedList() { - verifyJavaMarkdownNodes("javadocOrderedList", defaultModelConfig) { model -> - model.members.single().members.filter { it.name == "Bar" } - } - } - - @Test - fun jdkLinks() { - verifyMarkdownNode("jdkLinks", ModelConfig(withKotlinRuntime = true, analysisPlatform = analysisPlatform)) - } - - @Test - fun javadocHtml() { - verifyJavaMarkdownNode("javadocHtml", defaultModelConfig) - } -} diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index c02d3ad4..5df43017 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -3,35 +3,36 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.junit.Test -class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { +abstract class BaseKotlinWebSiteHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) override val formatService = KotlinWebsiteHtmlFormatService(fileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) @Test fun dropImport() { - verifyKWSNodeByName("dropImport", "foo") + verifyKWSNodeByName("dropImport", "foo", defaultModelConfig) } @Test fun sample() { - verifyKWSNodeByName("sample", "foo") + verifyKWSNodeByName("sample", "foo", defaultModelConfig) } @Test fun sampleWithAsserts() { - verifyKWSNodeByName("sampleWithAsserts", "a") + verifyKWSNodeByName("sampleWithAsserts", "a", defaultModelConfig) } @Test fun newLinesInSamples() { - verifyKWSNodeByName("newLinesInSamples", "foo") + verifyKWSNodeByName("newLinesInSamples", "foo", defaultModelConfig) } @Test fun newLinesInImportList() { - verifyKWSNodeByName("newLinesInImportList", "foo") + verifyKWSNodeByName("newLinesInImportList", "foo", defaultModelConfig) } @Test fun returnTag() { - verifyKWSNodeByName("returnTag", "indexOf") + verifyKWSNodeByName("returnTag", "indexOf", defaultModelConfig) } @Test fun overloadGroup() { - verifyKWSNodeByName("overloadGroup", "magic") + verifyKWSNodeByName("overloadGroup", "magic", defaultModelConfig) } @Test fun dataTags() { @@ -51,8 +52,12 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { verifyMultiplatformPackage(module, path) } - private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website-html/$fileName.kt", ".html", ModelConfig(format = "kotlin-website-html")) { model, output -> + private fun verifyKWSNodeByName(fileName: String, name: String, modelConfig: ModelConfig) { + verifyOutput( + "testdata/format/website-html/$fileName.kt", + ".html", + ModelConfig(analysisPlatform = modelConfig.analysisPlatform, format = "kotlin-website-html") + ) { model, output -> buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) } } @@ -96,3 +101,7 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { } } + +class JsKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.js) +class JvmKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.jvm) +class CommonKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt new file mode 100644 index 00000000..6c62587b --- /dev/null +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -0,0 +1,580 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Test + +abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + + @Test fun emptyDescription() { + verifyMarkdownNode("emptyDescription", defaultModelConfig) + } + + @Test fun classWithCompanionObject() { + verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun annotations() { + verifyMarkdownNode("annotations", defaultModelConfig) + } + + @Test fun annotationClass() { + verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun enumClass() { + verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> + val enumClassNode = model.members.single().members[0] + buildPagesAndReadInto( + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, + output + ) + } + } + + @Test fun varargsFunction() { + verifyMarkdownNode("varargsFunction", defaultModelConfig) + } + + @Test fun overridingFunction() { + verifyMarkdownNodes("overridingFunction", defaultModelConfig) { model-> + val classMembers = model.members.single().members.first { it.name == "D" }.members + classMembers.filter { it.name == "f" } + } + } + + @Test fun propertyVar() { + verifyMarkdownNode("propertyVar", defaultModelConfig) + } + + @Test fun functionWithDefaultParameter() { + verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) + } + + @Test fun accessor() { + verifyMarkdownNodes("accessor", defaultModelConfig) { model -> + model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } + } + } + + @Test fun paramTag() { + verifyMarkdownNode("paramTag", defaultModelConfig) + } + + @Test fun throwsTag() { + verifyMarkdownNode("throwsTag", defaultModelConfig) + } + + @Test fun typeParameterBounds() { + verifyMarkdownNode("typeParameterBounds", defaultModelConfig) + } + + @Test fun typeParameterVariance() { + verifyMarkdownNode("typeParameterVariance", defaultModelConfig) + } + + @Test fun typeProjectionVariance() { + verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) + } + + @Test fun codeBlockNoHtmlEscape() { + verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) + } + + @Test fun companionObjectExtension() { + verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) + } + + @Test fun starProjection() { + verifyMarkdownNode("starProjection", defaultModelConfig) + } + + @Test fun extensionFunctionParameter() { + verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) + } + + @Test fun summarizeSignatures() { + verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } + } + + @Test fun reifiedTypeParameter() { + verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun annotatedTypeParameter() { + verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedMembers() { + verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) + } + + @Test fun inheritedExtensions() { + verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun genericInheritedExtensions() { + verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun arrayAverage() { + verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) + } + + @Test fun multipleTypeParameterConstraints() { + verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedCompanionObjectProperties() { + verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) + } + + @Test fun shadowedExtensionFunctions() { + verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun inapplicableExtensionFunctions() { + verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun receiverParameterTypeBound() { + verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) + } + + @Test fun extensionWithDocumentedReceiver() { + verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> + model.members.single().members.single().members.filter { it.name == "fn" } + } + } + + @Test fun codeBlock() { + verifyMarkdownNode("codeBlock", defaultModelConfig) + } + + @Test fun exclInCodeBlock() { + verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun backtickInCodeBlock() { + verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun qualifiedNameLink() { + verifyMarkdownNodeByName("qualifiedNameLink", "foo", + ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun typeAliases() { + verifyMarkdownNode("typeAliases", defaultModelConfig) + verifyMarkdownPackage("typeAliases", defaultModelConfig) + } + + @Test fun sampleByShortName() { + verifyMarkdownNode("sampleByShortName", defaultModelConfig) + } + + + @Test fun suspendParam() { + verifyMarkdownNode("suspendParam", defaultModelConfig) + verifyMarkdownPackage("suspendParam", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyMarkdownNode("sinceKotlin", defaultModelConfig) + verifyMarkdownPackage("sinceKotlin", defaultModelConfig) + } + + @Test fun sinceKotlinWide() { + verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) + } + + @Test fun dynamicType() { + verifyMarkdownNode("dynamicType", defaultModelConfig) + } + + @Test fun dynamicExtension() { + verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun memberExtension() { + verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { + verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) + } + + @Test fun multiplePlatforms() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") + } + + @Test fun multiplePlatformsMerge() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") + } + + @Test fun multiplePlatformsMergeMembers() { + val module = buildMultiplePlatforms("multiplatform/mergeMembers") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsOmitRedundant() { + val module = buildMultiplePlatforms("multiplatform/omitRedundant") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsImplied() { + val module = buildMultiplePlatforms("multiplatform/implied") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) + fileGenerator.formatService = service + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun packagePlatformsWithExtExtensions() { + val path = "multiplatform/packagePlatformsWithExtExtensions" + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation(module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + withKotlinRuntime = true, + analysisPlatform = analysisPlatform + ) + ) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsPackagePlatformFromMembers() { + val path = "multiplatform/packagePlatformsFromMembers" + val module = buildMultiplePlatforms(path) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsGroupNode() { + val path = "multiplatform/groupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) + } + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { + val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), + output + ) + } + } + + @Test fun linksInEmphasis() { + verifyMarkdownNode("linksInEmphasis", defaultModelConfig) + } + + @Test fun linksInStrong() { + verifyMarkdownNode("linksInStrong", defaultModelConfig) + } + + @Test fun linksInHeaders() { + verifyMarkdownNode("linksInHeaders", defaultModelConfig) + } + + @Test fun tokensInEmphasis() { + verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) + } + + @Test fun tokensInStrong() { + verifyMarkdownNode("tokensInStrong", defaultModelConfig) + } + + @Test fun tokensInHeaders() { + verifyMarkdownNode("tokensInHeaders", defaultModelConfig) + } + + @Test fun unorderedLists() { + verifyMarkdownNode("unorderedLists", defaultModelConfig) + } + + @Test fun nestedLists() { + verifyMarkdownNode("nestedLists", defaultModelConfig) + } + + @Test fun referenceLink() { + verifyMarkdownNode("referenceLink", defaultModelConfig) + } + + @Test fun externalReferenceLink() { + verifyMarkdownNode("externalReferenceLink", defaultModelConfig) + } + + @Test fun newlineInTableCell() { + verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) + } + + @Test fun receiverReference() { + verifyMarkdownNode("receiverReference", defaultModelConfig) + } + + @Test fun extensionScope() { + verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) + } + + @Test fun typeParameterReference() { + verifyMarkdownNode("typeParameterReference", defaultModelConfig) + } + + @Test fun notPublishedTypeAliasAutoExpansion() { + verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( + analysisPlatform = analysisPlatform, + includeNonPublic = false + )) + } + + @Test fun companionImplements() { + verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) + } + + + private fun buildMultiplePlatforms(path: String): DocumentationModule { + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + analysisPlatform = Platform.jvm + ) + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), + defaultPlatforms = listOf("JS"), + analysisPlatform = Platform.js + ) + ) + + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { + model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + fileGenerator.formatService = service + buildPagesAndReadInto(listOf(model), output) + } + } + + @Test fun blankLineInsideCodeBlock() { + verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyMarkdownNodes( + fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List + ) { + verifyOutput( + "testdata/format/$fileName.kt", + ".md", + modelConfig + ) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyMarkdownNodeByName( + fileName: String, + name: String, + modelConfig: ModelConfig = ModelConfig() + ) { + verifyMarkdownNodes(fileName, modelConfig) { model-> + val nodesWithName = model.members.single().members.filter { it.name == name } + if (nodesWithName.isEmpty()) { + throw IllegalArgumentException("Found no nodes named $name") + } + nodesWithName + } + } +} + +class JSMarkdownFormatTest: BaseMarkdownFormatTest(Platform.js) + +class JVMMarkdownFormatTest: BaseMarkdownFormatTest(Platform.jvm) { + + @Test + fun enumRef() { + verifyMarkdownNode("enumRef", defaultModelConfig) + } + + @Test + fun javaCodeLiteralTags() { + verifyJavaMarkdownNode("javaCodeLiteralTags", defaultModelConfig) + } + + @Test + fun nullability() { + verifyMarkdownNode("nullability", defaultModelConfig) + } + + @Test + fun exceptionClass() { + verifyMarkdownNode( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + verifyMarkdownPackage( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + } + + @Test + fun operatorOverloading() { + verifyMarkdownNodes("operatorOverloading", defaultModelConfig) { model-> + model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } + } + } + + @Test + fun extensions() { + verifyOutput("testdata/format/extensions.kt", ".package.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/extensions.kt", ".class.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test + fun summarizeSignaturesProperty() { + verifyMarkdownNodes("summarizeSignaturesProperty", defaultModelConfig) { model -> model.members } + } + + @Test + fun javaSpaceInAuthor() { + verifyJavaMarkdownNode("javaSpaceInAuthor", defaultModelConfig) + } + + @Test + fun javaCodeInParam() { + verifyJavaMarkdownNode("javaCodeInParam", defaultModelConfig) + } + + @Test + fun annotationParams() { + verifyMarkdownNode("annotationParams", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedLink() { + val filePath = "testdata/format/inheritedLink" + verifyOutput( + filePath, + ".md", + ModelConfig( + roots = arrayOf( + contentRootFromPath("$filePath.kt"), + contentRootFromPath("$filePath.1.kt") + ), + withJdk = true, + withKotlinRuntime = true, + includeNonPublic = false, + analysisPlatform = analysisPlatform + + ) + ) { model, output -> + buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) + } + } + + @Test + fun javadocOrderedList() { + verifyJavaMarkdownNodes("javadocOrderedList", defaultModelConfig) { model -> + model.members.single().members.filter { it.name == "Bar" } + } + } + + @Test + fun jdkLinks() { + verifyMarkdownNode("jdkLinks", ModelConfig(withKotlinRuntime = true, analysisPlatform = analysisPlatform)) + } + + @Test + fun javadocHtml() { + verifyJavaMarkdownNode("javadocHtml", defaultModelConfig) + } +} + +class CommonMarkdownFormatTest: BaseMarkdownFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/issues/IssuesTest.kt b/core/src/test/kotlin/issues/IssuesTest.kt index 58b3a2d2..da5acd6e 100644 --- a/core/src/test/kotlin/issues/IssuesTest.kt +++ b/core/src/test/kotlin/issues/IssuesTest.kt @@ -2,18 +2,19 @@ package issues import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.tests.ModelConfig import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel import org.junit.Test import kotlin.test.assertEquals - -class IssuesTest { +abstract class BaseIssuesTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun errorClasses() { checkSourceExistsAndVerifyModel("testdata/issues/errorClasses.kt", - modelConfig = ModelConfig(withJdk = true, withKotlinRuntime = true)) { model -> + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true, withKotlinRuntime = true)) { model -> val cls = model.members.single().members.single() fun DocumentationNode.returnType() = this.details.find { it.kind == NodeKind.Type }?.name @@ -27,3 +28,7 @@ class IssuesTest { } } } + +class JSIssuesTest: BaseIssuesTest(Platform.js) +class JVMIssuesTest: BaseIssuesTest(Platform.jvm) +class CommonIssuesTest: BaseIssuesTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt index dc576b61..7976fccc 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -11,8 +11,10 @@ import org.junit.Assert.* import org.junit.Test class JavadocTest { + val defaultModelConfig = ModelConfig(analysisPlatform = Platform.jvm) + @Test fun testTypes() { - verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(withJdk = true)) { doc -> + verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(analysisPlatform = Platform.jvm, withJdk = true)) { doc -> val classDoc = doc.classNamed("foo.TypesKt")!! val method = classDoc.methods().find { it.name() == "foo" }!! @@ -28,7 +30,7 @@ class JavadocTest { } @Test fun testObject() { - verifyJavadoc("testdata/javadoc/obj.kt") { doc -> + verifyJavadoc("testdata/javadoc/obj.kt", defaultModelConfig) { doc -> val classDoc = doc.classNamed("foo.O") assertNotNull(classDoc) @@ -41,7 +43,10 @@ class JavadocTest { } @Test fun testException() { - verifyJavadoc("testdata/javadoc/exception.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/exception.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.MyException")!! val member = classDoc.methods().find { it.name() == "foo" } assertEquals(classDoc, member!!.containingClass()) @@ -49,7 +54,10 @@ class JavadocTest { } @Test fun testByteArray() { - verifyJavadoc("testdata/javadoc/bytearr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/bytearr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.ByteArray")!! assertNotNull(classDoc.asClassDoc()) @@ -59,7 +67,10 @@ class JavadocTest { } @Test fun testStringArray() { - verifyJavadoc("testdata/javadoc/stringarr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/stringarr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Foo")!! assertNotNull(classDoc.asClassDoc()) @@ -72,7 +83,10 @@ class JavadocTest { } @Test fun testJvmName() { - verifyJavadoc("testdata/javadoc/jvmname.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/jvmname.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Apple")!! assertNotNull(classDoc.asClassDoc()) @@ -82,7 +96,10 @@ class JavadocTest { } @Test fun testLinkWithParam() { - verifyJavadoc("testdata/javadoc/paramlink.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/paramlink.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("demo.Apple")!! assertNotNull(classDoc.asClassDoc()) val tags = classDoc.inlineTags().filterIsInstance() @@ -93,7 +110,10 @@ class JavadocTest { } @Test fun testInternalVisibility() { - verifyJavadoc("testdata/javadoc/internal.kt", ModelConfig(withKotlinRuntime = true, includeNonPublic = false)) { doc -> + verifyJavadoc( + "testdata/javadoc/internal.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true, includeNonPublic = false) + ) { doc -> val classDoc = doc.classNamed("foo.Person")!! val constructors = classDoc.constructors() assertEquals(1, constructors.size) @@ -102,7 +122,10 @@ class JavadocTest { } @Test fun testSuppress() { - verifyJavadoc("testdata/javadoc/suppress.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/suppress.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> assertNull(doc.classNamed("Some")) assertNull(doc.classNamed("SomeAgain")) assertNull(doc.classNamed("Interface")) @@ -113,7 +136,10 @@ class JavadocTest { } @Test fun testTypeAliases() { - verifyJavadoc("testdata/javadoc/typealiases.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/typealiases.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> assertNull(doc.classNamed("B")) assertNull(doc.classNamed("D")) @@ -128,7 +154,10 @@ class JavadocTest { } @Test fun testKDocKeywordsOnMethod() { - verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/kdocKeywordsOnMethod.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val method = doc.classNamed("KdocKeywordsOnMethodKt")!!.methods()[0] assertEquals("@return [ContentText(text=value of a)]", method.tags("return").first().text()) assertEquals("@param a [ContentText(text=Some string)]", method.paramTags().first().text()) @@ -138,7 +167,10 @@ class JavadocTest { @Test fun testBlankLineInsideCodeBlock() { - verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/blankLineInsideCodeBlock.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val method = doc.classNamed("BlankLineInsideCodeBlockKt")!!.methods()[0] val text = method.inlineTags().joinToString(separator = "", transform = Tag::text) assertEqualsIgnoringSeparators(""" @@ -155,7 +187,7 @@ class JavadocTest { @Test fun testCompanionMethodReference() { - verifyJavadoc("testdata/javadoc/companionMethodReference.kt") { doc -> + verifyJavadoc("testdata/javadoc/companionMethodReference.kt", defaultModelConfig) { doc -> val classDoc = doc.classNamed("foo.TestClass")!! val tag = classDoc.inlineTags().filterIsInstance().first() assertEquals("TestClass.Companion", tag.referencedClassName()) diff --git a/core/src/test/kotlin/model/BaseClassTest.kt b/core/src/test/kotlin/model/BaseClassTest.kt deleted file mode 100644 index d48ecb48..00000000 --- a/core/src/test/kotlin/model/BaseClassTest.kt +++ /dev/null @@ -1,269 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.RefKind -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -abstract class BaseClassTest(val analysisPlatform: Platform) { - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - @Test fun emptyClass() { - checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertEquals("", members.single().name) - assertTrue(links.none()) - } - } - } - - @Test fun emptyObject() { - checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Object, kind) - assertEquals("Obj", name) - assertEquals(Content.Empty, content) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun classWithConstructor() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> - with (model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(1, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(3, details.count()) - assertEquals("public", details.elementAt(0).name) - with(details.elementAt(2)) { - assertEquals("name", name) - assertEquals(NodeKind.Parameter, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithFunction() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - with(members.elementAt(1)) { - assertEquals("fn", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Function, kind) - assertEquals("Unit", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithProperty() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(1)) { - assertEquals("name", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Property, kind) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun classWithCompanionObject() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(3, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - } - with(members.elementAt(1)) { - assertEquals("x", name) - assertEquals(NodeKind.CompanionObjectProperty, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(2)) { - assertEquals("foo", name) - assertEquals(NodeKind.CompanionObjectFunction, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun dataClass() { - verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertTrue("data" in modifiers) - } - } - - @Test fun sealedClass() { - verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertEquals(1, modifiers.count { it == "sealed" }) - } - } - - @Test fun annotatedClassWithAnnotationParameters() { - checkSourceExistsAndVerifyModel( - "testdata/classes/annotatedClassWithAnnotationParameters.kt", - defaultModelConfig - ) { model -> - with(model.members.single().members.single()) { - with(deprecation!!) { - assertEquals("Deprecated", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("\"should no longer be used\"", name) - } - } - } - } - } - } - - @Test fun notOpenClass() { - checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> - with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun indirectOverride() { - checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> - with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun innerClass() { - verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> - val innerClass = cls.members.single { it.name == "D" } - val modifiers = innerClass.details(NodeKind.Modifier) - assertEquals(3, modifiers.size) - assertEquals("inner", modifiers[2].name) - } - } - - @Test fun companionObjectExtension() { - checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> - val pkg = model.members.single() - val cls = pkg.members.single { it.name == "Foo" } - val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } - assertEquals(1, extensions.size) - } - } - - @Test fun secondaryConstructor() { - verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> - val constructors = cls.members(NodeKind.Constructor) - assertEquals(2, constructors.size) - with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { - assertEquals("", name) - assertEquals("This is a secondary constructor.", summary.toTestString()) - } - } - } - - @Test fun sinceKotlin() { - checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } - - @Test fun privateCompanionObject() { - checkSourceExistsAndVerifyModel( - "testdata/classes/privateCompanionObject.kt", - modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) - ) { model -> - with(model.members.single().members.single()) { - assertEquals(0, members(NodeKind.CompanionObjectFunction).size) - assertEquals(0, members(NodeKind.CompanionObjectProperty).size) - } - } - } - -} diff --git a/core/src/test/kotlin/model/BasePropertyTest.kt b/core/src/test/kotlin/model/BasePropertyTest.kt deleted file mode 100644 index c88fe702..00000000 --- a/core/src/test/kotlin/model/BasePropertyTest.kt +++ /dev/null @@ -1,101 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -abstract class BasePropertyTest(val analysisPlatform: Platform) { - - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - @Test fun valueProperty() { - checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun variableProperty() { - checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun valuePropertyWithGetter() { - checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun variablePropertyWithAccessors() { - checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - val modifiers = details(NodeKind.Modifier).map { it.name } - assertTrue("final" in modifiers) - assertTrue("public" in modifiers) - assertTrue("var" in modifiers) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun propertyWithReceiver() { - checkSourceExistsAndVerifyModel( - "testdata/properties/propertyWithReceiver.kt", - defaultModelConfig - ) { model -> - with(model.members.single().members.single()) { - assertEquals("kotlin.String", name) - assertEquals(NodeKind.ExternalClass, kind) - with(members.single()) { - assertEquals("foobar", name) - assertEquals(NodeKind.Property, kind) - } - } - } - } - - @Test fun propertyOverride() { - checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> - with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { - assertEquals("xyzzy", name) - val override = references(RefKind.Override).single().to - assertEquals("xyzzy", override.name) - assertEquals("Foo", override.owner!!.name) - } - } - } - - @Test fun sinceKotlin() { - checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } -} diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt new file mode 100644 index 00000000..b8e58a62 --- /dev/null +++ b/core/src/test/kotlin/model/ClassTest.kt @@ -0,0 +1,318 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.RefKind +import org.junit.Assert +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BaseClassTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun emptyClass() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertEquals("", members.single().name) + assertTrue(links.none()) + } + } + } + + @Test fun emptyObject() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Object, kind) + assertEquals("Obj", name) + assertEquals(Content.Empty, content) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun classWithConstructor() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> + with (model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(1, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(3, details.count()) + assertEquals("public", details.elementAt(0).name) + with(details.elementAt(2)) { + assertEquals("name", name) + assertEquals(NodeKind.Parameter, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithFunction() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + with(members.elementAt(1)) { + assertEquals("fn", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Function, kind) + assertEquals("Unit", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithProperty() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(1)) { + assertEquals("name", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Property, kind) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun classWithCompanionObject() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(3, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + } + with(members.elementAt(1)) { + assertEquals("x", name) + assertEquals(NodeKind.CompanionObjectProperty, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(2)) { + assertEquals("foo", name) + assertEquals(NodeKind.CompanionObjectFunction, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun dataClass() { + verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertTrue("data" in modifiers) + } + } + + @Test fun sealedClass() { + verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertEquals(1, modifiers.count { it == "sealed" }) + } + } + + @Test fun annotatedClassWithAnnotationParameters() { + checkSourceExistsAndVerifyModel( + "testdata/classes/annotatedClassWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + with(deprecation!!) { + assertEquals("Deprecated", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Annotation, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Parameter, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Value, kind) + assertEquals("\"should no longer be used\"", name) + } + } + } + } + } + } + + @Test fun notOpenClass() { + checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun indirectOverride() { + checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun innerClass() { + verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> + val innerClass = cls.members.single { it.name == "D" } + val modifiers = innerClass.details(NodeKind.Modifier) + assertEquals(3, modifiers.size) + assertEquals("inner", modifiers[2].name) + } + } + + @Test fun companionObjectExtension() { + checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> + val pkg = model.members.single() + val cls = pkg.members.single { it.name == "Foo" } + val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } + assertEquals(1, extensions.size) + } + } + + @Test fun secondaryConstructor() { + verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> + val constructors = cls.members(NodeKind.Constructor) + assertEquals(2, constructors.size) + with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { + assertEquals("", name) + assertEquals("This is a secondary constructor.", summary.toTestString()) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } + + @Test fun privateCompanionObject() { + checkSourceExistsAndVerifyModel( + "testdata/classes/privateCompanionObject.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) + ) { model -> + with(model.members.single().members.single()) { + assertEquals(0, members(NodeKind.CompanionObjectFunction).size) + assertEquals(0, members(NodeKind.CompanionObjectProperty).size) + } + } + } + +} + +class JSClassTest: BaseClassTest(Platform.js) {} + +class JVMClassTest: BaseClassTest(Platform.jvm) { + @Test + fun annotatedClass() { + verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { cls -> + Assert.assertEquals(1, cls.annotations.count()) + with(cls.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + + + @Test fun javaAnnotationClass() { + checkSourceExistsAndVerifyModel( + "testdata/classes/javaAnnotationClass.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Retention", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + with(details[0]) { + Assert.assertEquals(NodeKind.Parameter, kind) + Assert.assertEquals(1, details.count()) + with(details[0]) { + Assert.assertEquals(NodeKind.Value, kind) + Assert.assertEquals("RetentionPolicy.SOURCE", name) + } + } + } + } + } + } + +} + +class CommonClassTest: BaseClassTest(Platform.common) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/CommentTest.kt b/core/src/test/kotlin/model/CommentTest.kt index a97c55eb..08aa3572 100644 --- a/core/src/test/kotlin/model/CommentTest.kt +++ b/core/src/test/kotlin/model/CommentTest.kt @@ -4,10 +4,10 @@ import org.junit.Test import org.junit.Assert.* import org.jetbrains.dokka.* -public class CommentTest { - +abstract class BaseCommentTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun codeBlockComment() { - checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt", defaultModelConfig) { model -> with(model.members.single().members.first()) { assertEqualsIgnoringSeparators("""[code lang=brainfuck] | @@ -30,7 +30,7 @@ public class CommentTest { } @Test fun emptyDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -38,7 +38,7 @@ public class CommentTest { } @Test fun emptyDocButComment() { - checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -46,7 +46,7 @@ public class CommentTest { } @Test fun multilineDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -55,7 +55,7 @@ public class CommentTest { } @Test fun multilineDocWithComment() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -64,7 +64,7 @@ public class CommentTest { } @Test fun oneLineDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -72,7 +72,7 @@ public class CommentTest { } @Test fun oneLineDocWithComment() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -80,7 +80,7 @@ public class CommentTest { } @Test fun oneLineDocWithEmptyLine() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -88,7 +88,7 @@ public class CommentTest { } @Test fun emptySection() { - checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -101,7 +101,7 @@ public class CommentTest { } @Test fun quotes() { - checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("it's \"useful\"", content.summary.toTestString()) } @@ -109,7 +109,7 @@ public class CommentTest { } @Test fun section1() { - checkSourceExistsAndVerifyModel("testdata/comments/section1.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section1.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -122,7 +122,7 @@ public class CommentTest { } @Test fun section2() { - checkSourceExistsAndVerifyModel("testdata/comments/section2.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section2.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(2, content.sections.count()) @@ -139,7 +139,7 @@ public class CommentTest { } @Test fun multilineSection() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -153,7 +153,7 @@ line two""", toTestString()) } @Test fun directive() { - checkSourceExistsAndVerifyModel("testdata/comments/directive.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/directive.kt", defaultModelConfig) { model -> with(model.members.single().members.first()) { assertEquals("Summary", content.summary.toTestString()) with (content.description) { @@ -184,3 +184,7 @@ line two""", toTestString()) } } } + +class JSCommentTest: BaseCommentTest(Platform.js) +class JVMCommentTest: BaseCommentTest(Platform.jvm) +class CommonCommentTest: BaseCommentTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt index 2704bf65..47685df2 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters +import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test @@ -229,3 +230,25 @@ Documentation""", content.description.toTestString()) } } } + +class JSFunctionTest: BaseFunctionTest(Platform.js) + +class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { + @Test + fun annotatedFunction() { + verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( + analysisPlatform = Platform.jvm, + withKotlinRuntime = true + )) { func -> + Assert.assertEquals(1, func.annotations.count()) + with(func.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + +} + +class CommonFunctionTest: BaseFunctionTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSClassTest.kt b/core/src/test/kotlin/model/JSClassTest.kt deleted file mode 100644 index e39b95cc..00000000 --- a/core/src/test/kotlin/model/JSClassTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseClassTest - -class JSClassTest: BaseClassTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSFunctionTest.kt b/core/src/test/kotlin/model/JSFunctionTest.kt deleted file mode 100644 index f6b987a9..00000000 --- a/core/src/test/kotlin/model/JSFunctionTest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseFunctionTest - -class JSFunctionTest: BaseFunctionTest(Platform.js) { - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSPropertyTest.kt b/core/src/test/kotlin/model/JSPropertyTest.kt deleted file mode 100644 index 0193d899..00000000 --- a/core/src/test/kotlin/model/JSPropertyTest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BasePropertyTest - -class JSPropertyTest: BasePropertyTest(Platform.js) { - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMClassTest.kt b/core/src/test/kotlin/model/JVMClassTest.kt deleted file mode 100644 index 22e23722..00000000 --- a/core/src/test/kotlin/model/JVMClassTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseClassTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel -import org.jetbrains.dokka.tests.verifyPackageMember -import org.junit.Assert -import org.junit.Test - -class JVMClassTest: BaseClassTest(Platform.jvm) { - @Test - fun annotatedClass() { - verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) { cls -> - Assert.assertEquals(1, cls.annotations.count()) - with(cls.annotations[0]) { - Assert.assertEquals("Strictfp", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - - - @Test fun javaAnnotationClass() { - checkSourceExistsAndVerifyModel( - "testdata/classes/javaAnnotationClass.kt", - modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) - ) { model -> - with(model.members.single().members.single()) { - Assert.assertEquals(1, annotations.count()) - with(annotations[0]) { - Assert.assertEquals("Retention", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - with(details[0]) { - Assert.assertEquals(NodeKind.Parameter, kind) - Assert.assertEquals(1, details.count()) - with(details[0]) { - Assert.assertEquals(NodeKind.Value, kind) - Assert.assertEquals("RetentionPolicy.SOURCE", name) - } - } - } - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMFunctionTest.kt b/core/src/test/kotlin/model/JVMFunctionTest.kt deleted file mode 100644 index a2fb0d2a..00000000 --- a/core/src/test/kotlin/model/JVMFunctionTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import com.sun.tools.javac.util.BaseFileManager -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseFunctionTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyPackageMember -import org.junit.Assert -import org.junit.Test - -class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { - @Test - fun annotatedFunction() { - verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( - analysisPlatform = Platform.jvm, - withKotlinRuntime = true - )) { func -> - Assert.assertEquals(1, func.annotations.count()) - with(func.annotations[0]) { - Assert.assertEquals("Strictfp", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMPropertyTest.kt b/core/src/test/kotlin/model/JVMPropertyTest.kt deleted file mode 100644 index 182dedbe..00000000 --- a/core/src/test/kotlin/model/JVMPropertyTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BasePropertyTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel -import org.junit.Assert -import org.junit.Test - -class JVMPropertyTest : BasePropertyTest(Platform.jvm) { - @Test - fun annotatedProperty() { - checkSourceExistsAndVerifyModel( - "testdata/properties/annotatedProperty.kt", - modelConfig = ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) { model -> - with(model.members.single().members.single()) { - Assert.assertEquals(1, annotations.count()) - with(annotations[0]) { - Assert.assertEquals("Volatile", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index 1d95556f..f6f0aa20 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -7,8 +7,6 @@ import org.junit.Test import org.junit.Assert.assertEquals class KotlinAsJavaTest { - private val defaultModelConfig = ModelConfig (analysisPlatform = Platform.jvm) - @Test fun function() { verifyModelAsJava("testdata/functions/function.kt") { model -> val pkg = model.members.single() @@ -33,14 +31,13 @@ class KotlinAsJavaTest { } fun verifyModelAsJava(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationModule) -> Unit) { checkSourceExistsAndVerifyModel( source, modelConfig = ModelConfig( - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, format = "html-as-java", analysisPlatform = Platform.jvm), verifier = verifier diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt index d7283bae..9b2f9f0d 100644 --- a/core/src/test/kotlin/model/LinkTest.kt +++ b/core/src/test/kotlin/model/LinkTest.kt @@ -3,12 +3,14 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.ContentBlock import org.jetbrains.dokka.ContentNodeLazyLink import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.junit.Assert.assertEquals import org.junit.Test -class LinkTest { +abstract class BaseLinkTest(val analysisPlatform: Platform) { + private val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun linkToSelf() { - checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -18,7 +20,7 @@ class LinkTest { } @Test fun linkToMember() { - checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -28,7 +30,7 @@ class LinkTest { } @Test fun linkToConstantWithUnderscores() { - checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -38,7 +40,7 @@ class LinkTest { } @Test fun linkToQualifiedMember() { - checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -48,7 +50,7 @@ class LinkTest { } @Test fun linkToParam() { - checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Function, kind) @@ -58,7 +60,7 @@ class LinkTest { } @Test fun linkToPackage() { - checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt", defaultModelConfig) { model -> val packageNode = model.members.single() with(packageNode) { assertEquals(this.name, "test.magic") @@ -72,4 +74,8 @@ class LinkTest { } } -} \ No newline at end of file +} + +class JSLinkTest: BaseLinkTest(Platform.js) +class JVMLinkTest: BaseLinkTest(Platform.jvm) +class CommonLinkTest: BaseLinkTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt index bc8a0e0d..80a2fd56 100644 --- a/core/src/test/kotlin/model/PackageTest.kt +++ b/core/src/test/kotlin/model/PackageTest.kt @@ -1,15 +1,14 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.PackageOptionsImpl +import org.jetbrains.dokka.* import org.jetbrains.kotlin.config.KotlinSourceRoot import org.junit.Assert.* import org.junit.Test -public class PackageTest { +abstract class BasePackageTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun rootPackage() { - checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("", name) @@ -22,7 +21,7 @@ public class PackageTest { } @Test fun simpleNamePackage() { - checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("simple", name) @@ -35,7 +34,7 @@ public class PackageTest { } @Test fun dottedNamePackage() { - checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("dot.name", name) @@ -53,7 +52,8 @@ public class PackageTest { roots = arrayOf( KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), KotlinSourceRoot("testdata/packages/simpleNamePackage.kt") - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(2, model.members.count()) @@ -81,7 +81,8 @@ public class PackageTest { roots = arrayOf( KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt") - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(1, model.members.count()) @@ -98,7 +99,10 @@ public class PackageTest { @Test fun classAtPackageLevel() { verifyModel( - ModelConfig(roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt"))) + ModelConfig( + roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), + analysisPlatform = analysisPlatform + ) ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { @@ -118,7 +122,8 @@ public class PackageTest { roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), perPackageOptions = listOf( PackageOptionsImpl(prefix = "simple.name", suppress = true) - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(1, model.members.count()) @@ -133,3 +138,7 @@ public class PackageTest { } } } + +class JSPackageTest : BasePackageTest(Platform.js) +class JVMPackageTest : BasePackageTest(Platform.jvm) +class CommonPackageTest : BasePackageTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/PropertyTest.kt b/core/src/test/kotlin/model/PropertyTest.kt new file mode 100644 index 00000000..a41ab5a3 --- /dev/null +++ b/core/src/test/kotlin/model/PropertyTest.kt @@ -0,0 +1,129 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Assert +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BasePropertyTest(val analysisPlatform: Platform) { + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun valueProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun variableProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun valuePropertyWithGetter() { + checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun variablePropertyWithAccessors() { + checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + val modifiers = details(NodeKind.Modifier).map { it.name } + assertTrue("final" in modifiers) + assertTrue("public" in modifiers) + assertTrue("var" in modifiers) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun propertyWithReceiver() { + checkSourceExistsAndVerifyModel( + "testdata/properties/propertyWithReceiver.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + assertEquals("kotlin.String", name) + assertEquals(NodeKind.ExternalClass, kind) + with(members.single()) { + assertEquals("foobar", name) + assertEquals(NodeKind.Property, kind) + } + } + } + } + + @Test fun propertyOverride() { + checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { + assertEquals("xyzzy", name) + val override = references(RefKind.Override).single().to + assertEquals("xyzzy", override.name) + assertEquals("Foo", override.owner!!.name) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } +} + +class JSPropertyTest: BasePropertyTest(Platform.js) {} + +class JVMPropertyTest : BasePropertyTest(Platform.jvm) { + @Test + fun annotatedProperty() { + checkSourceExistsAndVerifyModel( + "testdata/properties/annotatedProperty.kt", + modelConfig = ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Volatile", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + } + +} + +class CommonPropertyTest: BasePropertyTest(Platform.common) {} \ No newline at end of file -- cgit From fe20206eecd22cb4bd4de03efc0e9c28e1981bac Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Fri, 13 Jul 2018 15:04:56 +0300 Subject: Minor style fixes --- core/src/main/kotlin/Analysis/AnalysisEnvironment.kt | 3 +-- core/src/test/kotlin/TestAPI.kt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt index f03e9eea..3d70bd84 100644 --- a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt +++ b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt @@ -247,8 +247,7 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl module else library - } - , + }, targetEnvironment = CompilerEnvironment, packagePartProviderFactory = { content -> JvmPackagePartProvider(configuration.languageVersionSettings, content.moduleContentScope).apply { diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 7042f41b..ae69412b 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -117,8 +117,7 @@ fun appendDocumentation(documentation: DocumentationModule, fun checkSourceExistsAndVerifyModel(source: String, modelConfig: ModelConfig = ModelConfig(), - verifier: (DocumentationModule) -> Unit -) { + verifier: (DocumentationModule) -> Unit) { if (!File(source).exists()) { throw IllegalArgumentException("Can't find test data file $source") } -- cgit From c776aaab9af80987e3c073a40f92de748dbd38ca Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 11 Jan 2018 22:22:36 +0300 Subject: [backport] Support deep inheritance with external classes Original: 9e65c3d --- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 70 ++++++++++++++-------- .../main/kotlin/Kotlin/KotlinLanguageService.kt | 2 +- core/src/main/kotlin/Model/DocumentationNode.kt | 19 +++++- .../main/kotlin/Model/DocumentationReference.kt | 3 +- core/src/test/kotlin/TestAPI.kt | 48 ++++++++------- core/src/test/kotlin/model/JavaTest.kt | 2 +- 6 files changed, 92 insertions(+), 52 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 99d4d888..11a36a4f 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -103,6 +103,10 @@ interface DefaultPlatformsProvider { fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List } +val ignoredSupertypes = setOf( + "kotlin.Annotation", "kotlin.Enum", "kotlin.Any" +) + class DocumentationBuilder @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val descriptorDocumentationParser: DescriptorDocumentationParser, @@ -173,7 +177,7 @@ class DocumentationBuilder val unwrappedType = superType.unwrap() if (unwrappedType is AbbreviatedType) { appendSupertype(descriptor, unwrappedType.abbreviation) - } else if (!ignoreSupertype(unwrappedType)) { + } else { appendType(unwrappedType, NodeKind.Supertype) val superclass = unwrappedType.constructor.declarationDescriptor link(superclass, descriptor, RefKind.Inheritor) @@ -181,15 +185,6 @@ class DocumentationBuilder } } - private fun ignoreSupertype(superType: KotlinType): Boolean { - val superClass = superType.constructor.declarationDescriptor as? ClassDescriptor - if (superClass != null) { - val fqName = DescriptorUtils.getFqNameSafe(superClass).asString() - return fqName == "kotlin.Annotation" || fqName == "kotlin.Enum" || fqName == "kotlin.Any" - } - return false - } - fun DocumentationNode.appendProjection(projection: TypeProjection, kind: NodeKind = NodeKind.Type) { if (projection.isStarProjection) { appendTextNode("*", NodeKind.Type) @@ -233,14 +228,25 @@ class DocumentationBuilder if (classifierDescriptor != null) { val externalLink = linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(classifierDescriptor) if (externalLink != null) { + val targetNode = refGraph.lookup(classifierDescriptor.signature()) ?: classifierDescriptor.build(true) node.append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link) - node.append(DocumentationNode(classifierDescriptor.fqNameUnsafe.asString(), Content.Empty, NodeKind.QualifiedName), RefKind.Detail) + node.append(targetNode, RefKind.ExternalType) } else { link(node, classifierDescriptor, if (classifierDescriptor.isBoringBuiltinClass()) RefKind.HiddenLink else RefKind.Link) } + if (classifierDescriptor !is TypeParameterDescriptor) { + node.append( + DocumentationNode( + classifierDescriptor.fqNameUnsafe.asString(), + Content.Empty, + NodeKind.QualifiedName + ), RefKind.Detail + ) + } } + append(node, RefKind.Detail) node.appendAnnotations(kotlinType) for (typeArgument in kotlinType.arguments) { @@ -496,34 +502,42 @@ class DocumentationBuilder } fun DeclarationDescriptor.build(): DocumentationNode = when (this) { - is ClassDescriptor -> build() + is ClassifierDescriptor -> build() is ConstructorDescriptor -> build() is PropertyDescriptor -> build() is FunctionDescriptor -> build() - is TypeParameterDescriptor -> build() is ValueParameterDescriptor -> build() is ReceiverParameterDescriptor -> build() - is TypeAliasDescriptor -> build() else -> throw IllegalStateException("Descriptor $this is not known") } - fun TypeAliasDescriptor.build(): DocumentationNode { + fun ClassifierDescriptor.build(external: Boolean = false): DocumentationNode = when (this) { + is ClassDescriptor -> build(external) + is TypeAliasDescriptor -> build(external) + is TypeParameterDescriptor -> build() + else -> throw IllegalStateException("Descriptor $this is not known") + } + + fun TypeAliasDescriptor.build(external: Boolean = false): DocumentationNode { val node = nodeForDescriptor(this, NodeKind.TypeAlias) - node.appendAnnotations(this) + if (!external) { + node.appendAnnotations(this) + } node.appendModifiers(this) node.appendInPageChildren(typeConstructor.parameters, RefKind.Detail) node.appendType(underlyingType, NodeKind.TypeAliasUnderlyingType) - node.appendSourceLink(source) - node.appendDefaultPlatforms(this) - + if (!external) { + node.appendSourceLink(source) + node.appendDefaultPlatforms(this) + } register(this, node) return node } - fun ClassDescriptor.build(): DocumentationNode { + fun ClassDescriptor.build(external: Boolean = false): DocumentationNode { val kind = when { kind == ClassKind.OBJECT -> NodeKind.Object kind == ClassKind.INTERFACE -> NodeKind.Interface @@ -534,20 +548,24 @@ class DocumentationBuilder else -> NodeKind.Class } val node = nodeForDescriptor(this, kind) + register(this, node) typeConstructor.supertypes.forEach { node.appendSupertype(this, it) } if (getKind() != ClassKind.OBJECT && getKind() != ClassKind.ENUM_ENTRY) { node.appendInPageChildren(typeConstructor.parameters, RefKind.Detail) } - for ((descriptor, inheritedLinkKind, extraModifier) in collectMembersToDocument()) { - node.appendClassMember(descriptor, inheritedLinkKind, extraModifier) + if (!external) { + for ((descriptor, inheritedLinkKind, extraModifier) in collectMembersToDocument()) { + node.appendClassMember(descriptor, inheritedLinkKind, extraModifier) + } + node.appendAnnotations(this) } - node.appendAnnotations(this) node.appendModifiers(this) - node.appendSourceLink(source) - node.appendDefaultPlatforms(this) - register(this, node) + if (!external) { + node.appendSourceLink(source) + node.appendDefaultPlatforms(this) + } return node } diff --git a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt index b6f44716..aa185de7 100644 --- a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt +++ b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt @@ -291,7 +291,7 @@ class KotlinLanguageService : LanguageService { } private fun ContentBlock.renderSupertypesForNode(node: DocumentationNode, renderMode: RenderMode) { - val supertypes = node.details(NodeKind.Supertype) + val supertypes = node.details(NodeKind.Supertype).filterNot { it.qualifiedNameFromType() in ignoredSupertypes } if (supertypes.any()) { nbsp() symbol(":") diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index a145ae8d..a792460f 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -104,12 +104,27 @@ open class DocumentationNode(val name: String, get() = references(RefKind.Deprecation).singleOrNull()?.to val platforms: List get() = references(RefKind.Platform).map { it.to.name } + val externalType: DocumentationNode? + get() = references(RefKind.ExternalType).map { it.to }.firstOrNull() val supertypes: List get() = details(NodeKind.Supertype) - val superclass: DocumentationNode? - get() = supertypes.firstOrNull { it.links.any { it.kind in NodeKind.classLike } } + val superclassType: DocumentationNode? + get() = when (kind) { + NodeKind.Supertype -> (links.firstOrNull { it.kind in NodeKind.classLike } ?: externalType)?.superclassType + NodeKind.Interface -> null + in NodeKind.classLike -> supertypes.firstOrNull { + it.links.any { it.kind in NodeKind.classLike } || + it.externalType != null + } + else -> null + } + + val superclassTypeSequence: Sequence + get() = generateSequence(superclassType) { + it.superclassType + } // TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice fun addReferenceTo(to: DocumentationNode, kind: RefKind) { diff --git a/core/src/main/kotlin/Model/DocumentationReference.kt b/core/src/main/kotlin/Model/DocumentationReference.kt index a968f400..b0f011be 100644 --- a/core/src/main/kotlin/Model/DocumentationReference.kt +++ b/core/src/main/kotlin/Model/DocumentationReference.kt @@ -18,7 +18,8 @@ enum class RefKind { HiddenAnnotation, Deprecation, TopLevelPage, - Platform + Platform, + ExternalType } data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: RefKind) { diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index aa3eff48..559b715e 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -6,7 +6,6 @@ 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.DokkaConfiguration.SourceLinkDefinition import org.jetbrains.dokka.Utilities.DokkaAnalysisModule import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity @@ -25,6 +24,7 @@ fun verifyModel(vararg roots: ContentRoot, format: String = "html", includeNonPublic: Boolean = true, perPackageOptions: List = emptyList(), + noStdlibLink: Boolean = true, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") @@ -37,7 +37,7 @@ fun verifyModel(vararg roots: ContentRoot, sourceLinks = listOf(), perPackageOptions = perPackageOptions, generateIndexPages = false, - noStdlibLink = true, + noStdlibLink = noStdlibLink, cacheRoot = "default", languageVersion = null, apiVersion = null @@ -161,13 +161,15 @@ fun verifyOutput(roots: Array, withKotlinRuntime: Boolean = false, format: String = "html", includeNonPublic: Boolean = true, + noStdlibLink: Boolean = true, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { verifyModel( - *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic + *roots, + withJdk = withJdk, + withKotlinRuntime = withKotlinRuntime, + format = format, + includeNonPublic = includeNonPublic, + noStdlibLink = noStdlibLink ) { verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) } @@ -184,21 +186,25 @@ fun verifyModelOutput(it: DocumentationModule, assertEqualsIgnoringSeparators(expectedFile, output.toString()) } -fun verifyOutput(path: String, - outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { +fun verifyOutput( + path: String, + outputExtension: String, + withJdk: Boolean = false, + withKotlinRuntime: Boolean = false, + format: String = "html", + includeNonPublic: Boolean = true, + noStdlibLink: Boolean = true, + outputGenerator: (DocumentationModule, StringBuilder) -> Unit +) { verifyOutput( - arrayOf(contentRootFromPath(path)), - outputExtension, - withJdk, - withKotlinRuntime, - format, - includeNonPublic, - outputGenerator + arrayOf(contentRootFromPath(path)), + outputExtension, + withJdk, + withKotlinRuntime, + format, + includeNonPublic, + noStdlibLink, + outputGenerator ) } diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index e6c22ee4..c2ede8f0 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -193,7 +193,7 @@ public class JavaTest { @Test fun enumValues() { verifyJavaPackageMember("testdata/java/enumValues.java") { cls -> val superTypes = cls.details(NodeKind.Supertype) - assertEquals(0, superTypes.size) + assertEquals(1, superTypes.size) assertEquals(1, cls.members(NodeKind.EnumItem).size) } } -- cgit From 1391dcca35a871881420c53755fed08bf47e4087 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 17 Jan 2018 20:01:20 +0300 Subject: [backport] Support propagating inherited extensions from libraries Original: bf2945d --- core/src/main/kotlin/DokkaBootstrapImpl.kt | 3 +- core/src/main/kotlin/Generation/DokkaGenerator.kt | 2 + .../main/kotlin/Generation/configurationImpl.kt | 47 ++--- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 200 ++++++++++++++++----- .../Kotlin/ExternalDocumentationLinkResolver.kt | 2 +- core/src/main/kotlin/Model/DocumentationNode.kt | 2 + core/src/test/kotlin/TestAPI.kt | 32 ++-- .../kotlin/org/jetbrains/dokka/configuration.kt | 48 ++--- runners/cli/src/main/kotlin/cli/main.kt | 28 +-- runners/gradle-plugin/src/main/kotlin/main.kt | 51 +++--- 10 files changed, 273 insertions(+), 142 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index aeaca8be..b7787be8 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -69,7 +69,8 @@ class DokkaBootstrapImpl : DokkaBootstrap { languageVersion, apiVersion, cacheRoot, - suppressedFiles.map { File(it) }.toSet() + suppressedFiles.map { File(it) }.toSet(), + collectInheritedExtensionsFromLibraries ) ) } diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 09e5cedf..33170f35 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -160,6 +160,8 @@ fun buildDocumentationModule(injector: Injector, with(injector.getInstance(DocumentationBuilder::class.java)) { documentationModule.appendFragments(fragments, packageDocs.packageContent, injector.getInstance(PackageDocumentationBuilder::class.java)) + + propagateExtensionFunctionsToSubclasses(fragments, resolutionFacade) } val javaFiles = coreEnvironment.getJavaSourceFiles().filter(filesToDocumentFilter) diff --git a/core/src/main/kotlin/Generation/configurationImpl.kt b/core/src/main/kotlin/Generation/configurationImpl.kt index 34d4154e..52e8446f 100644 --- a/core/src/main/kotlin/Generation/configurationImpl.kt +++ b/core/src/main/kotlin/Generation/configurationImpl.kt @@ -36,27 +36,28 @@ data class PackageOptionsImpl(override val prefix: String, override val suppress: Boolean = false) : DokkaConfiguration.PackageOptions data class DokkaConfigurationImpl( - override val moduleName: String, - override val classpath: List, - override val sourceRoots: List, - override val samples: List, - override val includes: List, - override val outputDir: String, - override val format: String, - override val includeNonPublic: Boolean, - override val includeRootPackage: Boolean, - override val reportUndocumented: Boolean, - override val skipEmptyPackages: Boolean, - override val skipDeprecated: Boolean, - override val jdkVersion: Int, - override val generateIndexPages: Boolean, - override val sourceLinks: List, - override val impliedPlatforms: List, - override val perPackageOptions: List, - override val externalDocumentationLinks: List, - override val noStdlibLink: Boolean, - override val cacheRoot: String?, - override val suppressedFiles: List, - override val languageVersion: String?, - override val apiVersion: String? + override val moduleName: String, + override val classpath: List, + override val sourceRoots: List, + override val samples: List, + override val includes: List, + override val outputDir: String, + override val format: String, + override val includeNonPublic: Boolean, + override val includeRootPackage: Boolean, + override val reportUndocumented: Boolean, + override val skipEmptyPackages: Boolean, + override val skipDeprecated: Boolean, + override val jdkVersion: Int, + override val generateIndexPages: Boolean, + override val sourceLinks: List, + override val impliedPlatforms: List, + override val perPackageOptions: List, + override val externalDocumentationLinks: List, + override val noStdlibLink: Boolean, + override val cacheRoot: String?, + override val suppressedFiles: List, + override val languageVersion: String?, + override val apiVersion: String?, + override val collectInheritedExtensionsFromLibraries: Boolean ) : DokkaConfiguration \ No newline at end of file diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 11a36a4f..125f9fd4 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -11,6 +11,9 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotated import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor import org.jetbrains.kotlin.idea.kdoc.findKDoc +import org.jetbrains.kotlin.idea.util.fuzzyExtensionReceiverType +import org.jetbrains.kotlin.idea.util.makeNotNullable +import org.jetbrains.kotlin.idea.util.toFuzzyType import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.lexer.KtTokens @@ -25,10 +28,11 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.resolve.findTopMostOverriddenDescriptors import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver +import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter +import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered import org.jetbrains.kotlin.resolve.source.PsiSourceElement import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.* -import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.types.typeUtil.supertypes import java.io.File import java.nio.file.Path @@ -53,7 +57,8 @@ class DocumentationOptions(val outputDir: String, val languageVersion: String?, val apiVersion: String?, cacheRoot: String? = null, - val suppressedFiles: Set = emptySet()) { + val suppressedFiles: Set = emptySet(), + val collectInheritedExtensionsFromLibraries: Boolean = false) { init { if (perPackageOptions.any { it.prefix == "" }) throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead") @@ -138,8 +143,20 @@ class DocumentationBuilder refGraph.register(descriptor.signature(), node) } - fun nodeForDescriptor(descriptor: T, kind: NodeKind): DocumentationNode where T : DeclarationDescriptor, T : Named { - val (doc, callback) = descriptorDocumentationParser.parseDocumentationAndDetails(descriptor, kind == NodeKind.Parameter) + fun nodeForDescriptor( + descriptor: T, + kind: NodeKind, + external: Boolean = false + ): DocumentationNode where T : DeclarationDescriptor, T : Named { + val (doc, callback) = + if (external) { + Content.Empty to { node -> } + } else { + descriptorDocumentationParser.parseDocumentationAndDetails( + descriptor, + kind == NodeKind.Parameter + ) + } val node = DocumentationNode(descriptor.name.asString(), doc, kind).withModifiers(descriptor) node.appendSignature(descriptor) callback(node) @@ -226,14 +243,20 @@ class DocumentationBuilder node.appendTextNode("?", NodeKind.NullabilityModifier) } if (classifierDescriptor != null) { - val externalLink = linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(classifierDescriptor) + val externalLink = + linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(classifierDescriptor) if (externalLink != null) { - val targetNode = refGraph.lookup(classifierDescriptor.signature()) ?: classifierDescriptor.build(true) - node.append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link) - node.append(targetNode, RefKind.ExternalType) + if (classifierDescriptor !is TypeParameterDescriptor) { + val targetNode = + refGraph.lookup(classifierDescriptor.signature()) ?: classifierDescriptor.build(true) + node.append(targetNode, RefKind.ExternalType) + node.append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link) + } } else { - link(node, classifierDescriptor, - if (classifierDescriptor.isBoringBuiltinClass()) RefKind.HiddenLink else RefKind.Link) + link( + node, classifierDescriptor, + if (classifierDescriptor.isBoringBuiltinClass()) RefKind.HiddenLink else RefKind.Link + ) } if (classifierDescriptor !is TypeParameterDescriptor) { node.append( @@ -280,6 +303,17 @@ class DocumentationBuilder } } + fun DocumentationNode.appendExternalLink(externalLink: String) { + append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link) + } + + fun DocumentationNode.appendExternalLink(descriptor: DeclarationDescriptor) { + val target = linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(descriptor) + if (target != null) { + appendExternalLink(target) + } + } + fun DocumentationNode.appendSinceKotlin(annotation: DocumentationNode) { val kotlinVersion = annotation .detail(NodeKind.Parameter) @@ -426,15 +460,44 @@ class DocumentationBuilder declarations, allFqNames) } - propagateExtensionFunctionsToSubclasses(fragments) } - private fun propagateExtensionFunctionsToSubclasses(fragments: Collection) { - val allDescriptors = fragments.flatMap { it.getMemberScope().getContributedDescriptors() } - val allClasses = allDescriptors.filterIsInstance() - val classHierarchy = buildClassHierarchy(allClasses) + fun propagateExtensionFunctionsToSubclasses( + fragments: Collection, + resolutionFacade: DokkaResolutionFacade + ) { + + val moduleDescriptor = resolutionFacade.moduleDescriptor + + // Wide-collect all view descriptors + val allPackageViewDescriptors = generateSequence(listOf(moduleDescriptor.getPackage(FqName.ROOT))) { packages -> + packages + .flatMap { pkg -> + moduleDescriptor.getSubPackagesOf(pkg.fqName) { true } + }.map { fqName -> + moduleDescriptor.getPackage(fqName) + }.takeUnless { it.isEmpty() } + }.flatten() + + val allDescriptors = + if (options.collectInheritedExtensionsFromLibraries) { + allPackageViewDescriptors.map { it.memberScope } + } else { + fragments.asSequence().map { it.getMemberScope() } + }.flatMap { + it.getDescriptorsFiltered( + DescriptorKindFilter.CALLABLES + ).asSequence() + } + - val allExtensionFunctions = allDescriptors + val documentingDescriptors = fragments.flatMap { it.getMemberScope().getContributedDescriptors() } + val documentingClasses = documentingDescriptors.filterIsInstance() + + val classHierarchy = buildClassHierarchy(documentingClasses) + + val allExtensionFunctions = + allDescriptors .filterIsInstance() .filter { it.extensionReceiverParameter != null } val extensionFunctionsByName = allExtensionFunctions.groupBy { it.name } @@ -442,15 +505,31 @@ class DocumentationBuilder for (extensionFunction in allExtensionFunctions) { if (extensionFunction.dispatchReceiverParameter != null) continue val possiblyShadowingFunctions = extensionFunctionsByName[extensionFunction.name] - ?.filter { fn -> fn.canShadow(extensionFunction) } + ?.filter { fn -> fn.canShadow(extensionFunction) } ?: emptyList() if (extensionFunction.extensionReceiverParameter?.type?.isDynamic() == true) continue - val classDescriptor = extensionFunction.getExtensionClassDescriptor() ?: continue - val subclasses = classHierarchy[classDescriptor] ?: continue - subclasses.forEach { subclass -> + val subclasses = + classHierarchy.filter { (key) -> key.isExtensionApplicable(extensionFunction) } + if (subclasses.isEmpty()) continue + subclasses.values.flatten().forEach { subclass -> if (subclass.isExtensionApplicable(extensionFunction) && - possiblyShadowingFunctions.none { subclass.isExtensionApplicable(it) }) { + possiblyShadowingFunctions.none { subclass.isExtensionApplicable(it) }) { + + val hasExternalLink = + linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink( + extensionFunction + ) != null + if (hasExternalLink) { + val containerDesc = + extensionFunction.containingDeclaration as? PackageFragmentDescriptor + if (containerDesc != null) { + val container = refGraph.lookup(containerDesc.signature()) + ?: containerDesc.buildExternal() + container.append(extensionFunction.buildExternal(), RefKind.Member) + } + } + refGraph.link(subclass.signature(), extensionFunction.signature(), RefKind.Extension) } } @@ -458,12 +537,9 @@ class DocumentationBuilder } private fun ClassDescriptor.isExtensionApplicable(extensionFunction: CallableMemberDescriptor): Boolean { - val receiverType = extensionFunction.extensionReceiverParameter!!.type - if (receiverType.arguments.any { it.type.constructor.declarationDescriptor is TypeParameterDescriptor }) { - val receiverClass = receiverType.constructor.declarationDescriptor - return receiverClass is ClassDescriptor && DescriptorUtils.isSubclass(this, receiverClass) - } - return defaultType.isSubtypeOf(receiverType) + val receiverType = extensionFunction.fuzzyExtensionReceiverType()?.makeNotNullable() + val classType = defaultType.toFuzzyType(declaredTypeParameters) + return receiverType != null && classType.checkIsSubtypeOf(receiverType) != null } private fun buildClassHierarchy(classes: List): Map> { @@ -511,6 +587,24 @@ class DocumentationBuilder else -> throw IllegalStateException("Descriptor $this is not known") } + fun PackageFragmentDescriptor.buildExternal(): DocumentationNode { + val node = DocumentationNode(fqName.asString(), Content.Empty, NodeKind.Package) + + val externalLink = linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(this) + if (externalLink != null) { + node.append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link) + } + register(this, node) + return node + } + + fun CallableDescriptor.buildExternal(): DocumentationNode = when(this) { + is FunctionDescriptor -> build(true) + is PropertyDescriptor -> build(true) + else -> throw IllegalStateException("Descriptor $this is not known") + } + + fun ClassifierDescriptor.build(external: Boolean = false): DocumentationNode = when (this) { is ClassDescriptor -> build(external) is TypeAliasDescriptor -> build(external) @@ -547,7 +641,7 @@ class DocumentationBuilder isSubclassOfThrowable() -> NodeKind.Exception else -> NodeKind.Class } - val node = nodeForDescriptor(this, kind) + val node = nodeForDescriptor(this, kind, external) register(this, node) typeConstructor.supertypes.forEach { node.appendSupertype(this, it) @@ -632,12 +726,12 @@ class DocumentationBuilder return (receiver?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.isCompanionObject ?: false } - fun FunctionDescriptor.build(): DocumentationNode { + fun FunctionDescriptor.build(external: Boolean = false): DocumentationNode { if (ErrorUtils.containsErrorType(this)) { logger.warn("Found an unresolved type in ${signatureWithSourceLocation()}") } - val node = nodeForDescriptor(this, if (inCompanionObject()) NodeKind.CompanionObjectFunction else NodeKind.Function) + val node = nodeForDescriptor(this, if (inCompanionObject()) NodeKind.CompanionObjectFunction else NodeKind.Function, external) node.appendInPageChildren(typeParameters, RefKind.Detail) extensionReceiverParameter?.let { node.appendChild(it, RefKind.Detail) } @@ -645,8 +739,12 @@ class DocumentationBuilder node.appendType(returnType) node.appendAnnotations(this) node.appendModifiers(this) - node.appendSourceLink(source) - node.appendDefaultPlatforms(this) + if (!external) { + node.appendSourceLink(source) + node.appendDefaultPlatforms(this) + } else { + node.appendExternalLink(this) + } overriddenDescriptors.forEach { addOverrideLink(it, this) @@ -667,32 +765,42 @@ class DocumentationBuilder } } - fun PropertyDescriptor.build(): DocumentationNode { - val node = nodeForDescriptor(this, if (inCompanionObject()) NodeKind.CompanionObjectProperty else NodeKind.Property) + fun PropertyDescriptor.build(external: Boolean = false): DocumentationNode { + val node = nodeForDescriptor( + this, + if (inCompanionObject()) NodeKind.CompanionObjectProperty else NodeKind.Property, + external + ) node.appendInPageChildren(typeParameters, RefKind.Detail) extensionReceiverParameter?.let { node.appendChild(it, RefKind.Detail) } node.appendType(returnType) node.appendAnnotations(this) node.appendModifiers(this) - node.appendSourceLink(source) - if (isVar) { - node.appendTextNode("var", NodeKind.Modifier) - } - getter?.let { - if (!it.isDefault) { - node.addAccessorDocumentation(descriptorDocumentationParser.parseDocumentation(it), "Getter") + if (!external) { + node.appendSourceLink(source) + if (isVar) { + node.appendTextNode("var", NodeKind.Modifier) } - } - setter?.let { - if (!it.isDefault) { - node.addAccessorDocumentation(descriptorDocumentationParser.parseDocumentation(it), "Setter") + + getter?.let { + if (!it.isDefault) { + node.addAccessorDocumentation(descriptorDocumentationParser.parseDocumentation(it), "Getter") + } } + setter?.let { + if (!it.isDefault) { + node.addAccessorDocumentation(descriptorDocumentationParser.parseDocumentation(it), "Setter") + } + } + node.appendDefaultPlatforms(this) + } + if (external) { + node.appendExternalLink(this) } overriddenDescriptors.forEach { addOverrideLink(it, this) } - node.appendDefaultPlatforms(this) register(this, node) return node diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt index e19ecf76..400326d2 100644 --- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt @@ -155,8 +155,8 @@ class ExternalDocumentationLinkResolver @Inject constructor( fun buildExternalDocumentationLink(symbol: DeclarationDescriptor): String? { val packageFqName: FqName = when (symbol) { - is DeclarationDescriptorNonRoot -> symbol.parents.firstOrNull { it is PackageFragmentDescriptor }?.fqNameSafe ?: return null is PackageFragmentDescriptor -> symbol.fqName + is DeclarationDescriptorNonRoot -> symbol.parents.firstOrNull { it is PackageFragmentDescriptor }?.fqNameSafe ?: return null else -> return null } diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index a792460f..85ecdf87 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -209,6 +209,8 @@ fun DocumentationNode.appendTextNode(text: String, fun DocumentationNode.qualifiedName(): String { if (kind == NodeKind.Type) { return qualifiedNameFromType() + } else if (kind == NodeKind.Package) { + return name } return path.drop(1).map { it.name }.filter { it.length > 0 }.joinToString(".") } diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 559b715e..aeff9284 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -25,22 +25,24 @@ fun verifyModel(vararg roots: ContentRoot, includeNonPublic: Boolean = true, perPackageOptions: List = emptyList(), noStdlibLink: Boolean = true, + collectInheritedExtensionsFromLibraries: Boolean = false, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") val options = DocumentationOptions( - "", - format, - includeNonPublic = includeNonPublic, - skipEmptyPackages = false, - includeRootPackage = true, - sourceLinks = listOf(), - perPackageOptions = perPackageOptions, - generateIndexPages = false, - noStdlibLink = noStdlibLink, - cacheRoot = "default", - languageVersion = null, - apiVersion = null + "", + format, + includeNonPublic = includeNonPublic, + skipEmptyPackages = false, + includeRootPackage = true, + sourceLinks = listOf(), + perPackageOptions = perPackageOptions, + generateIndexPages = false, + noStdlibLink = noStdlibLink, + cacheRoot = "default", + languageVersion = null, + apiVersion = null, + collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries ) appendDocumentation(documentation, *roots, @@ -162,6 +164,7 @@ fun verifyOutput(roots: Array, format: String = "html", includeNonPublic: Boolean = true, noStdlibLink: Boolean = true, + collectInheritedExtensionsFromLibraries: Boolean = false, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { verifyModel( *roots, @@ -169,7 +172,8 @@ fun verifyOutput(roots: Array, withKotlinRuntime = withKotlinRuntime, format = format, includeNonPublic = includeNonPublic, - noStdlibLink = noStdlibLink + noStdlibLink = noStdlibLink, + collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries ) { verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) } @@ -194,6 +198,7 @@ fun verifyOutput( format: String = "html", includeNonPublic: Boolean = true, noStdlibLink: Boolean = true, + collectInheritedExtensionsFromLibraries: Boolean = false, outputGenerator: (DocumentationModule, StringBuilder) -> Unit ) { verifyOutput( @@ -204,6 +209,7 @@ fun verifyOutput( format, includeNonPublic, noStdlibLink, + collectInheritedExtensionsFromLibraries, outputGenerator ) } diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt index 90e5b5fc..46a57278 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -41,6 +41,7 @@ interface DokkaConfiguration { val noStdlibLink: Boolean val cacheRoot: String? val suppressedFiles: List + val collectInheritedExtensionsFromLibraries: Boolean interface SourceRoot { val path: String @@ -82,29 +83,30 @@ interface DokkaConfiguration { } data class SerializeOnlyDokkaConfiguration( - override val moduleName: String, - override val classpath: List, - override val sourceRoots: List, - override val samples: List, - override val includes: List, - override val outputDir: String, - override val format: String, - override val includeNonPublic: Boolean, - override val includeRootPackage: Boolean, - override val reportUndocumented: Boolean, - override val skipEmptyPackages: Boolean, - override val skipDeprecated: Boolean, - override val jdkVersion: Int, - override val generateIndexPages: Boolean, - override val sourceLinks: List, - override val impliedPlatforms: List, - override val perPackageOptions: List, - override val externalDocumentationLinks: List, - override val noStdlibLink: Boolean, - override val cacheRoot: String?, - override val suppressedFiles: List, - override val languageVersion: String?, - override val apiVersion: String? + override val moduleName: String, + override val classpath: List, + override val sourceRoots: List, + override val samples: List, + override val includes: List, + override val outputDir: String, + override val format: String, + override val includeNonPublic: Boolean, + override val includeRootPackage: Boolean, + override val reportUndocumented: Boolean, + override val skipEmptyPackages: Boolean, + override val skipDeprecated: Boolean, + override val jdkVersion: Int, + override val generateIndexPages: Boolean, + override val sourceLinks: List, + override val impliedPlatforms: List, + override val perPackageOptions: List, + override val externalDocumentationLinks: List, + override val noStdlibLink: Boolean, + override val cacheRoot: String?, + override val suppressedFiles: List, + override val languageVersion: String?, + override val apiVersion: String?, + override val collectInheritedExtensionsFromLibraries: Boolean ) : DokkaConfiguration diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index fe945ed3..111e1420 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -62,6 +62,9 @@ class DokkaArguments { @set:Argument(value = "apiVersion", description = "Kotlin Api Version to pass to Kotlin Analysis") var apiVersion: String? = null + @set:Argument(value = "collectInheritedExtensionsFromLibraries", description = "Search for applicable extensions in libraries") + var collectInheritedExtensionsFromLibraries: Boolean = false + } @@ -106,18 +109,19 @@ object MainKt { val classPath = arguments.classpath.split(File.pathSeparatorChar).toList() val documentationOptions = DocumentationOptions( - arguments.outputDir.let { if (it.endsWith('/')) it else it + '/' }, - arguments.outputFormat, - skipDeprecated = arguments.nodeprecated, - sourceLinks = sourceLinks, - impliedPlatforms = arguments.impliedPlatforms.split(','), - perPackageOptions = parsePerPackageOptions(arguments.packageOptions), - jdkVersion = arguments.jdkVersion, - externalDocumentationLinks = parseLinks(arguments.links), - noStdlibLink = arguments.noStdlibLink, - cacheRoot = arguments.cacheRoot, - languageVersion = arguments.languageVersion, - apiVersion = arguments.apiVersion + arguments.outputDir.let { if (it.endsWith('/')) it else it + '/' }, + arguments.outputFormat, + skipDeprecated = arguments.nodeprecated, + sourceLinks = sourceLinks, + impliedPlatforms = arguments.impliedPlatforms.split(','), + perPackageOptions = parsePerPackageOptions(arguments.packageOptions), + jdkVersion = arguments.jdkVersion, + externalDocumentationLinks = parseLinks(arguments.links), + noStdlibLink = arguments.noStdlibLink, + cacheRoot = arguments.cacheRoot, + languageVersion = arguments.languageVersion, + apiVersion = arguments.apiVersion, + collectInheritedExtensionsFromLibraries = arguments.collectInheritedExtensionsFromLibraries ) val generator = DokkaGenerator( diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index 5f02cd0e..4812e217 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -134,6 +134,9 @@ open class DokkaTask : DefaultTask() { @Optional @Input var apiVersion: String? = null + @Input + var collectInheritedExtensionsFromLibraries: Boolean = false + @get:Internal internal val kotlinCompileBasedClasspathAndSourceRoots: ClasspathAndSourceRoots by lazy { extractClasspathAndSourceRootsFromKotlinTasks() } @@ -287,29 +290,31 @@ open class DokkaTask : DefaultTask() { val bootstrapProxy: DokkaBootstrap = automagicTypedProxy(javaClass.classLoader, bootstrapInstance) val configuration = SerializeOnlyDokkaConfiguration( - moduleName, - fullClasspath.map { it.absolutePath }, - sourceRoots, - samples.filterNotNull().map { project.file(it).absolutePath }, - includes.filterNotNull().map { project.file(it).absolutePath }, - outputDirectory, - outputFormat, - includeNonPublic, - false, - reportUndocumented, - skipEmptyPackages, - skipDeprecated, - jdkVersion, - true, - linkMappings, - impliedPlatforms, - perPackageOptions, - externalDocumentationLinks, - noStdlibLink, - cacheRoot, - collectSuppressedFiles(sourceRoots), - languageVersion, - apiVersion) + moduleName, + fullClasspath.map { it.absolutePath }, + sourceRoots, + samples.filterNotNull().map { project.file(it).absolutePath }, + includes.filterNotNull().map { project.file(it).absolutePath }, + outputDirectory, + outputFormat, + includeNonPublic, + false, + reportUndocumented, + skipEmptyPackages, + skipDeprecated, + jdkVersion, + true, + linkMappings, + impliedPlatforms, + perPackageOptions, + externalDocumentationLinks, + noStdlibLink, + cacheRoot, + collectSuppressedFiles(sourceRoots), + languageVersion, + apiVersion, + collectInheritedExtensionsFromLibraries + ) bootstrapProxy.configure( -- cgit From adee5c45d9b9b47a38fa0124b97c85c8733476e8 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 4 Jun 2018 16:11:45 +0300 Subject: Fix package docs parsing test --- core/src/test/kotlin/format/PackageDocsTest.kt | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'core/src/test') diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt index 704f7b99..b7fff1e2 100644 --- a/core/src/test/kotlin/format/PackageDocsTest.kt +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -1,19 +1,46 @@ package org.jetbrains.dokka.tests.format +import com.intellij.openapi.Disposable +import com.intellij.openapi.util.Disposer import com.nhaarman.mockito_kotlin.any import com.nhaarman.mockito_kotlin.doAnswer import com.nhaarman.mockito_kotlin.eq import com.nhaarman.mockito_kotlin.mock import org.jetbrains.dokka.* import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment +import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor +import org.junit.After import org.junit.Assert.assertEquals +import org.junit.Before import org.junit.Test import java.io.File class PackageDocsTest { + + private lateinit var testDisposable: Disposable + + @Before + fun setup() { + testDisposable = Disposer.newDisposable() + } + + @After + fun cleanup() { + Disposer.dispose(testDisposable) + } + + fun createPackageDocs(linkResolver: DeclarationLinkResolver?): PackageDocs { + val environment = KotlinCoreEnvironment.createForTests(testDisposable, CompilerConfiguration.EMPTY, EnvironmentConfigFiles.JVM_CONFIG_FILES) + return PackageDocs(linkResolver, DokkaConsoleLogger, environment, mock(), mock()) + } + @Test fun verifyParse() { - val docs = PackageDocs(null, DokkaConsoleLogger) + + val docs = createPackageDocs(null) docs.parse("testdata/packagedocs/stdlib.md", emptyList()) val packageContent = docs.packageContent["kotlin"]!! val block = (packageContent.children.single() as ContentBlock).children.first() as ContentText @@ -28,7 +55,7 @@ class PackageDocsTest { val mockPackageDescriptor = mock {} - val docs = PackageDocs(mockLinkResolver, DokkaConsoleLogger) + val docs = createPackageDocs(mockLinkResolver) docs.parse("testdata/packagedocs/referenceLinks.md", listOf(mockPackageDescriptor)) checkMarkdownOutput(docs, "testdata/packagedocs/referenceLinks") -- cgit From 23861925232505dbd70344a1d690f2475bb022e8 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 4 Jun 2018 16:23:34 +0300 Subject: [backport] Introduce option to enable/disable jdk linking Original: 8e9e768 --- core/src/main/kotlin/DokkaBootstrapImpl.kt | 39 +++++++++++----------- .../main/kotlin/Generation/configurationImpl.kt | 1 + .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 6 +++- core/src/test/kotlin/TestAPI.kt | 9 +++++ .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 1 + .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 1 + core/src/test/kotlin/format/MarkdownFormatTest.kt | 2 ++ core/src/test/kotlin/model/JavaTest.kt | 4 +-- .../kotlin/org/jetbrains/dokka/configuration.kt | 2 ++ runners/ant/src/main/kotlin/ant/dokka.kt | 2 ++ runners/gradle-plugin/src/main/kotlin/main.kt | 14 +++++--- 11 files changed, 54 insertions(+), 27 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index b7787be8..e18ab6cf 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -52,25 +52,26 @@ class DokkaBootstrapImpl : DokkaBootstrap { includes, moduleName, DocumentationOptions( - outputDir, - format, - includeNonPublic, - includeRootPackage, - reportUndocumented, - skipEmptyPackages, - skipDeprecated, - jdkVersion, - generateIndexPages, - sourceLinks, - impliedPlatforms, - perPackageOptions, - externalDocumentationLinks, - noStdlibLink, - languageVersion, - apiVersion, - cacheRoot, - suppressedFiles.map { File(it) }.toSet(), - collectInheritedExtensionsFromLibraries + outputDir = outputDir, + outputFormat = format, + includeNonPublic = includeNonPublic, + includeRootPackage = includeRootPackage, + reportUndocumented = reportUndocumented, + skipEmptyPackages = skipEmptyPackages, + skipDeprecated = skipDeprecated, + jdkVersion = jdkVersion, + generateIndexPages = generateIndexPages, + sourceLinks = sourceLinks, + impliedPlatforms = impliedPlatforms, + perPackageOptions = perPackageOptions, + externalDocumentationLinks = externalDocumentationLinks, + noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, + languageVersion = languageVersion, + apiVersion = apiVersion, + cacheRoot = cacheRoot, + suppressedFiles = suppressedFiles.map { File(it) }.toSet(), + collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries ) ) } diff --git a/core/src/main/kotlin/Generation/configurationImpl.kt b/core/src/main/kotlin/Generation/configurationImpl.kt index 52e8446f..90e27b4b 100644 --- a/core/src/main/kotlin/Generation/configurationImpl.kt +++ b/core/src/main/kotlin/Generation/configurationImpl.kt @@ -55,6 +55,7 @@ data class DokkaConfigurationImpl( override val perPackageOptions: List, override val externalDocumentationLinks: List, override val noStdlibLink: Boolean, + override val noJdkLink: Boolean, override val cacheRoot: String?, override val suppressedFiles: List, override val languageVersion: String?, diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index e6a75277..58f5e246 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -55,6 +55,7 @@ class DocumentationOptions(val outputDir: String, perPackageOptions: List = emptyList(), externalDocumentationLinks: List = emptyList(), noStdlibLink: Boolean, + noJdkLink: Boolean, val languageVersion: String?, val apiVersion: String?, cacheRoot: String? = null, @@ -72,7 +73,10 @@ class DocumentationOptions(val outputDir: String, fun effectivePackageOptions(pack: FqName): PackageOptions = effectivePackageOptions(pack.asString()) val defaultLinks = run { - val links = mutableListOf(ExternalDocumentationLink.Builder("http://docs.oracle.com/javase/$jdkVersion/docs/api/").build()) + val links = mutableListOf() + if (!noJdkLink) + links += ExternalDocumentationLink.Builder("http://docs.oracle.com/javase/$jdkVersion/docs/api/").build() + if (!noStdlibLink) links += ExternalDocumentationLink.Builder("https://kotlinlang.org/api/latest/jvm/stdlib/").build() links diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index aeff9284..953e3bab 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -39,6 +39,7 @@ fun verifyModel(vararg roots: ContentRoot, perPackageOptions = perPackageOptions, generateIndexPages = false, noStdlibLink = noStdlibLink, + noJdkLink = false, cacheRoot = "default", languageVersion = null, apiVersion = null, @@ -269,6 +270,14 @@ fun StringBuilder.appendNode(node: ContentNode): StringBuilder { 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") } diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index b971b54d..062cf0b5 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -54,6 +54,7 @@ class KotlinWebSiteFormatTest: FileGeneratorTestCase() { outputFormat = "html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index 49fa6d2f..8076fb92 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -65,6 +65,7 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { outputFormat = "kotlin-website-html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 9e4c831d..3723e5ae 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -313,6 +313,7 @@ class MarkdownFormatTest: FileGeneratorTestCase() { outputFormat = "html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) @@ -447,6 +448,7 @@ class MarkdownFormatTest: FileGeneratorTestCase() { outputFormat = "html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index c2ede8f0..66eb84f1 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -18,12 +18,12 @@ public class JavaTest { with(content.sections[0]) { assertEquals("Parameters", tag) assertEquals("name", subjectName) - assertEquals("is String parameter", toTestString()) + assertEquals("render(Type:String,SUMMARY): is String parameter", toTestString()) } with(content.sections[1]) { assertEquals("Parameters", tag) assertEquals("value", subjectName) - assertEquals("is int parameter", toTestString()) + assertEquals("render(Type:String,SUMMARY): is int parameter", toTestString()) } with(content.sections[2]) { assertEquals("Author", tag) diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt index 46a57278..69d19944 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -39,6 +39,7 @@ interface DokkaConfiguration { val languageVersion: String? val apiVersion: String? val noStdlibLink: Boolean + val noJdkLink: Boolean val cacheRoot: String? val suppressedFiles: List val collectInheritedExtensionsFromLibraries: Boolean @@ -102,6 +103,7 @@ data class SerializeOnlyDokkaConfiguration( override val perPackageOptions: List, override val externalDocumentationLinks: List, override val noStdlibLink: Boolean, + override val noJdkLink: Boolean, override val cacheRoot: String?, override val suppressedFiles: List, override val languageVersion: String?, diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index d1b6bef5..79583a1f 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -40,6 +40,7 @@ class DokkaAntTask: Task() { var jdkVersion: Int = 6 var noStdlibLink: Boolean = false + var noJdkLink: Boolean = false var skipDeprecated: Boolean = false @@ -131,6 +132,7 @@ class DokkaAntTask: Task() { perPackageOptions = antPackageOptions, externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() }, noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, cacheRoot = cacheRoot, languageVersion = languageVersion, apiVersion = apiVersion diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index 4812e217..d3a341e0 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -124,6 +124,9 @@ open class DokkaTask : DefaultTask() { @Input var noStdlibLink: Boolean = false + @Input + var noJdkLink: Boolean = false + @Optional @Input var cacheRoot: String? = null @@ -309,11 +312,12 @@ open class DokkaTask : DefaultTask() { perPackageOptions, externalDocumentationLinks, noStdlibLink, - cacheRoot, - collectSuppressedFiles(sourceRoots), - languageVersion, - apiVersion, - collectInheritedExtensionsFromLibraries + noJdkLink, + cacheRoot, + collectSuppressedFiles(sourceRoots), + languageVersion, + apiVersion, + collectInheritedExtensionsFromLibraries ) -- cgit From 052a218dcf8bc565d5e78dc900a9647f0da5350a Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Wed, 1 Aug 2018 19:48:45 +0300 Subject: Refactoring, replace DocumentationOption with PassConfiguration --- core/src/main/kotlin/DokkaBootstrapImpl.kt | 32 +----- core/src/main/kotlin/Generation/DokkaGenerator.kt | 58 +++++------ core/src/main/kotlin/Generation/FileGenerator.kt | 5 +- .../main/kotlin/Generation/configurationImpl.kt | 70 ++++++++----- .../kotlin/Java/JavaPsiDocumentationBuilder.kt | 25 +++-- .../main/kotlin/Kotlin/DeclarationLinkResolver.kt | 4 +- .../kotlin/Kotlin/DescriptorDocumentationParser.kt | 2 +- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 108 ++++++--------------- .../Kotlin/ExternalDocumentationLinkResolver.kt | 13 ++- .../Kotlin/KotlinAsJavaDocumentationBuilder.kt | 2 +- .../Samples/DefaultSampleProcessingService.kt | 2 +- .../KotlinWebsiteSampleProcessingService.kt | 4 +- core/src/main/kotlin/Utilities/DokkaModules.kt | 18 ++-- core/src/main/kotlin/javadoc/dokka-adapters.kt | 9 +- core/src/test/kotlin/TestAPI.kt | 44 +++++---- .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 19 ++-- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 22 +++-- core/src/test/kotlin/format/MarkdownFormatTest.kt | 36 ++++--- .../kotlin/org/jetbrains/dokka/configuration.kt | 71 ++++++-------- runners/ant/src/main/kotlin/ant/dokka.kt | 49 +++++----- runners/cli/src/main/kotlin/cli/main.kt | 36 ++++--- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 47 ++++----- 22 files changed, 323 insertions(+), 353 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index e18ab6cf..ccafcd12 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -2,7 +2,6 @@ package org.jetbrains.dokka import org.jetbrains.dokka.DokkaConfiguration.PackageOptions import ru.yole.jkid.deserialization.deserialize -import java.io.File import java.util.function.BiConsumer @@ -44,36 +43,7 @@ class DokkaBootstrapImpl : DokkaBootstrap { = configure(DokkaProxyLogger(logger), deserialize(serializedConfigurationJSON)) fun configure(logger: DokkaLogger, configuration: DokkaConfiguration) = with(configuration) { - generator = DokkaGenerator( - logger, - classpath, - sourceRoots, - samples, - includes, - moduleName, - DocumentationOptions( - outputDir = outputDir, - outputFormat = format, - includeNonPublic = includeNonPublic, - includeRootPackage = includeRootPackage, - reportUndocumented = reportUndocumented, - skipEmptyPackages = skipEmptyPackages, - skipDeprecated = skipDeprecated, - jdkVersion = jdkVersion, - generateIndexPages = generateIndexPages, - sourceLinks = sourceLinks, - impliedPlatforms = impliedPlatforms, - perPackageOptions = perPackageOptions, - externalDocumentationLinks = externalDocumentationLinks, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, - languageVersion = languageVersion, - apiVersion = apiVersion, - cacheRoot = cacheRoot, - suppressedFiles = suppressedFiles.map { File(it) }.toSet(), - collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries - ) - ) + generator = DokkaGenerator(configuration, logger) } override fun generate() = generator.generate() diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 0c4b3b7e..2e46d908 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -2,13 +2,11 @@ package org.jetbrains.dokka import com.google.inject.Guice import com.google.inject.Injector -import com.intellij.openapi.application.PathManager import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager -import org.jetbrains.dokka.DokkaConfiguration.SourceRoot import org.jetbrains.dokka.Utilities.DokkaAnalysisModule import org.jetbrains.dokka.Utilities.DokkaOutputModule import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation @@ -18,7 +16,6 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.config.JVMConfigurationKeys -import org.jetbrains.kotlin.config.KotlinSourceRoot import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer import org.jetbrains.kotlin.resolve.TopDownAnalysisMode @@ -26,56 +23,49 @@ import org.jetbrains.kotlin.utils.PathUtil import java.io.File import kotlin.system.measureTimeMillis -class DokkaGenerator(val logger: DokkaLogger, - val classpath: List, - val sources: List, - val samples: List, - val includes: List, - val moduleName: String, - val options: DocumentationOptions) { +class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, + val logger: DokkaLogger) { private val documentationModules: MutableList = mutableListOf() - fun generate() { - val sourcesGroupedByPlatform = sources.groupBy { it.platforms.firstOrNull() to it.analysisPlatform } - for ((platformsInfo, roots) in sourcesGroupedByPlatform) { - val (platform, analysisPlatform) = platformsInfo - val documentationModule = DocumentationModule(moduleName) - appendSourceModule(platform, analysisPlatform, roots, documentationModule) + fun generate() = with(dokkaConfiguration) { + + + for (pass in passesConfigurations) { + val documentationModule = DocumentationModule(pass.moduleName) + appendSourceModule(pass, documentationModule) documentationModules.add(documentationModule) } val totalDocumentationModule = DocumentationMerger(documentationModules).merge() - totalDocumentationModule.prepareForGeneration(options) + totalDocumentationModule.prepareForGeneration(dokkaConfiguration) val timeBuild = measureTimeMillis { logger.info("Generating pages... ") - val outputInjector = Guice.createInjector(DokkaOutputModule(options, logger)) + val outputInjector = Guice.createInjector(DokkaOutputModule(dokkaConfiguration, logger)) outputInjector.getInstance(Generator::class.java).buildAll(totalDocumentationModule) } logger.info("done in ${timeBuild / 1000} secs") } private fun appendSourceModule( - defaultPlatform: String?, - analysisPlatform: Platform, - sourceRoots: List, + passConfiguration: DokkaConfiguration.PassConfiguration, documentationModule: DocumentationModule - ) { + ) = with(passConfiguration) { - val sourcePaths = sourceRoots.map { it.path } - val environment = createAnalysisEnvironment(sourcePaths, analysisPlatform) + val sourcePaths = passConfiguration.sourceRoots.map { it.path } + val environment = createAnalysisEnvironment(sourcePaths, passConfiguration) logger.info("Module: $moduleName") - logger.info("Output: ${File(options.outputDir)}") + logger.info("Output: ${File(dokkaConfiguration.outputDir)}") logger.info("Sources: ${sourcePaths.joinToString()}") logger.info("Classpath: ${environment.classpath.joinToString()}") logger.info("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() - val defaultPlatformAsList = defaultPlatform?.let { listOf(it) }.orEmpty() + val defaultPlatformAsList = listOf(passConfiguration.analysisPlatform.key) val defaultPlatformsProvider = object : DefaultPlatformsProvider { override fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List { val containingFilePath = descriptor.sourcePsi()?.containingFile?.virtualFile?.canonicalPath @@ -86,9 +76,9 @@ class DokkaGenerator(val logger: DokkaLogger, } val injector = Guice.createInjector( - DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentationModule.nodeRefGraph, logger)) + DokkaAnalysisModule(environment, dokkaConfiguration, defaultPlatformsProvider, documentationModule.nodeRefGraph, passConfiguration, logger)) - buildDocumentationModule(injector, documentationModule, { isNotSample(it) }, includes) + buildDocumentationModule(injector, documentationModule, { isNotSample(it, passConfiguration.samples) }, includes) documentationModule.nodeRefGraph.nodeMapView.forEach { (_, node) -> node.addReferenceTo( DocumentationNode(analysisPlatform.key, Content.Empty, NodeKind.Platform), @@ -102,28 +92,28 @@ class DokkaGenerator(val logger: DokkaLogger, Disposer.dispose(environment) } - fun createAnalysisEnvironment(sourcePaths: List, analysisPlatform: Platform): AnalysisEnvironment { - val environment = AnalysisEnvironment(DokkaMessageCollector(logger), analysisPlatform) + fun createAnalysisEnvironment(sourcePaths: List, passConfiguration: DokkaConfiguration.PassConfiguration): AnalysisEnvironment { + val environment = AnalysisEnvironment(DokkaMessageCollector(logger), passConfiguration.analysisPlatform) environment.apply { if (analysisPlatform == Platform.jvm) { addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } // addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath()) - for (element in this@DokkaGenerator.classpath) { + for (element in passConfiguration.classpath) { addClasspath(File(element)) } addSources(sourcePaths) - addSources(this@DokkaGenerator.samples) + addSources(passConfiguration.samples) - loadLanguageVersionSettings(options.languageVersion, options.apiVersion) + loadLanguageVersionSettings(passConfiguration.languageVersion, passConfiguration.apiVersion) } return environment } - fun isNotSample(file: PsiFile): Boolean { + fun isNotSample(file: PsiFile, samples: List): Boolean { val sourceFile = File(file.virtualFile!!.path) return samples.none { sample -> val canonicalSample = File(sample).canonicalPath diff --git a/core/src/main/kotlin/Generation/FileGenerator.kt b/core/src/main/kotlin/Generation/FileGenerator.kt index b7c6cf63..eb6800b3 100644 --- a/core/src/main/kotlin/Generation/FileGenerator.kt +++ b/core/src/main/kotlin/Generation/FileGenerator.kt @@ -2,7 +2,6 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.google.inject.name.Named -import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -12,7 +11,7 @@ class FileGenerator @Inject constructor(@Named("outputDir") override val root: F @set:Inject(optional = true) var outlineService: OutlineFormatService? = null @set:Inject(optional = true) lateinit var formatService: FormatService - @set:Inject(optional = true) lateinit var options: DocumentationOptions + @set:Inject(optional = true) lateinit var dokkaConfiguration: DokkaConfiguration @set:Inject(optional = true) var packageListService: PackageListService? = null override fun location(node: DocumentationNode): FileLocation { @@ -74,7 +73,7 @@ class FileGenerator @Inject constructor(@Named("outputDir") override val root: F val moduleRoot = location(module).file.parentFile val packageListFile = File(moduleRoot, "package-list") - packageListFile.writeText("\$dokka.format:${options.outputFormat}\n" + + packageListFile.writeText("\$dokka.format:${dokkaConfiguration.format}\n" + packageListService!!.formatPackageList(module as DocumentationModule)) } diff --git a/core/src/main/kotlin/Generation/configurationImpl.kt b/core/src/main/kotlin/Generation/configurationImpl.kt index 8829682a..3e39b4ed 100644 --- a/core/src/main/kotlin/Generation/configurationImpl.kt +++ b/core/src/main/kotlin/Generation/configurationImpl.kt @@ -45,29 +45,47 @@ data class PackageOptionsImpl(override val prefix: String, override val suppress: Boolean = false) : DokkaConfiguration.PackageOptions data class DokkaConfigurationImpl( - override val moduleName: String, - override val classpath: List, - override val sourceRoots: List, - override val samples: List, - override val includes: List, - override val outputDir: String, - override val format: String, - override val includeNonPublic: Boolean, - override val includeRootPackage: Boolean, - override val reportUndocumented: Boolean, - override val skipEmptyPackages: Boolean, - override val skipDeprecated: Boolean, - override val jdkVersion: Int, - override val generateIndexPages: Boolean, - override val sourceLinks: List, - override val impliedPlatforms: List, - override val perPackageOptions: List, - override val externalDocumentationLinks: List, - override val noStdlibLink: Boolean, - override val noJdkLink: Boolean, - override val cacheRoot: String?, - override val suppressedFiles: List, - override val languageVersion: String?, - override val apiVersion: String?, - override val collectInheritedExtensionsFromLibraries: Boolean -) : DokkaConfiguration \ No newline at end of file + override val outputDir: String = "", + override val format: String = "html", + override val generateIndexPages: Boolean = false, + override val cacheRoot: String? = null, + override val impliedPlatforms: List = listOf(), + override val passesConfigurations: List = listOf() +) : DokkaConfiguration + +class PassConfigurationImpl ( + override val classpath: List = listOf(), + override val moduleName: String = "", + override val sourceRoots: List = listOf(), + override val samples: List = listOf(), + override val includes: List = listOf(), + 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 = listOf(), + override val perPackageOptions: List = listOf(), + externalDocumentationLinks: List = listOf(), + override val languageVersion: String? = null, + override val apiVersion: String? = null, + override val noStdlibLink: Boolean = false, + override val noJdkLink: Boolean = false, + override val suppressedFiles: List = listOf(), + override val collectInheritedExtensionsFromLibraries: Boolean = false, + override val analysisPlatform: Platform = Platform.DEFAULT, + override val targets: List = listOf() +): DokkaConfiguration.PassConfiguration { + private val defaultLinks = run { + val links = mutableListOf() + if (!noJdkLink) + links += DokkaConfiguration.ExternalDocumentationLink.Builder("http://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/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index 332afffb..1fe4d180 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtModifierListOwner -import java.io.File fun getSignature(element: PsiElement?) = when(element) { is PsiPackage -> element.qualifiedName @@ -44,24 +43,24 @@ interface JavaDocumentationBuilder { } class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { - private val options: DocumentationOptions + private val passConfiguration: DokkaConfiguration.PassConfiguration private val refGraph: NodeReferenceGraph private val docParser: JavaDocumentationParser @Inject constructor( - options: DocumentationOptions, - refGraph: NodeReferenceGraph, - logger: DokkaLogger, - signatureProvider: ElementSignatureProvider, - externalDocumentationLinkResolver: ExternalDocumentationLinkResolver + passConfiguration: DokkaConfiguration.PassConfiguration, + refGraph: NodeReferenceGraph, + logger: DokkaLogger, + signatureProvider: ElementSignatureProvider, + externalDocumentationLinkResolver: ExternalDocumentationLinkResolver ) { - this.options = options + this.passConfiguration = passConfiguration this.refGraph = refGraph this.docParser = JavadocParser(refGraph, logger, signatureProvider, externalDocumentationLinkResolver) } - constructor(options: DocumentationOptions, refGraph: NodeReferenceGraph, docParser: JavaDocumentationParser) { - this.options = options + constructor(passConfiguration: DokkaConfiguration.PassConfiguration, refGraph: NodeReferenceGraph, docParser: JavaDocumentationParser) { + this.passConfiguration = passConfiguration this.refGraph = refGraph this.docParser = docParser } @@ -141,7 +140,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { } } - private fun skipFile(javaFile: PsiJavaFile): Boolean = options.effectivePackageOptions(javaFile.packageName).suppress + private fun skipFile(javaFile: PsiJavaFile): Boolean = passConfiguration.effectivePackageOptions(javaFile.packageName).suppress private fun skipElement(element: Any) = skipElementByVisibility(element) || @@ -151,13 +150,13 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { private fun skipElementByVisibility(element: Any): Boolean = element is PsiModifierListOwner && element !is PsiParameter && - !(options.effectivePackageOptions((element.containingFile as? PsiJavaFile)?.packageName ?: "").includeNonPublic) && + !(passConfiguration.effectivePackageOptions((element.containingFile as? PsiJavaFile)?.packageName ?: "").includeNonPublic) && (element.hasModifierProperty(PsiModifier.PRIVATE) || element.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) || element.isInternal()) private fun skipElementBySuppressedFiles(element: Any): Boolean = - element is PsiElement && File(element.containingFile.virtualFile.path).absoluteFile in options.suppressedFiles + element is PsiElement && element.containingFile.virtualFile.path in passConfiguration.suppressedFiles private fun PsiElement.isInternal(): Boolean { val ktElement = (this as? KtLightElement<*, *>)?.kotlinOrigin ?: return false diff --git a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt index d73bef4a..c3a84e57 100644 --- a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt @@ -10,7 +10,7 @@ class DeclarationLinkResolver @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val refGraph: NodeReferenceGraph, val logger: DokkaLogger, - val options: DocumentationOptions, + val passConfiguration: DokkaConfiguration.PassConfiguration, val externalDocumentationLinkResolver: ExternalDocumentationLinkResolver, val elementSignatureProvider: ElementSignatureProvider) { @@ -63,7 +63,7 @@ class DeclarationLinkResolver if (symbol is CallableMemberDescriptor && symbol.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { return symbol.overriddenDescriptors.firstOrNull() } - if (symbol is TypeAliasDescriptor && !symbol.isDocumented(options)) { + if (symbol is TypeAliasDescriptor && !symbol.isDocumented(passConfiguration)) { return symbol.classDescriptor } return symbol diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index 7817da18..d0650d45 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered import org.jetbrains.kotlin.resolve.source.PsiSourceElement class DescriptorDocumentationParser - @Inject constructor(val options: DocumentationOptions, + @Inject constructor(val options: DokkaConfiguration.PassConfiguration, val logger: DokkaLogger, val linkResolver: DeclarationLinkResolver, val resolutionFacade: DokkaResolutionFacade, diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index e3675f9d..fb0b898a 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -4,7 +4,7 @@ import com.google.inject.Inject import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiField import com.intellij.psi.PsiJavaFile -import org.jetbrains.dokka.DokkaConfiguration.* +import org.jetbrains.dokka.DokkaConfiguration.PassConfiguration import org.jetbrains.dokka.Kotlin.DescriptorDocumentationParser import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* @@ -35,62 +35,8 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.supertypes import org.jetbrains.kotlin.util.supertypesWithAny -import java.io.File -import java.nio.file.Path -import java.nio.file.Paths import com.google.inject.name.Named as GuiceNamed -class DocumentationOptions(val outputDir: String, - val outputFormat: String, - includeNonPublic: Boolean = false, - val includeRootPackage: Boolean = false, - reportUndocumented: Boolean = true, - val skipEmptyPackages: Boolean = true, - skipDeprecated: Boolean = false, - jdkVersion: Int = 6, - val generateIndexPages: Boolean = true, - val sourceLinks: List = emptyList(), - val impliedPlatforms: List = emptyList(), - // Sorted by pattern length - perPackageOptions: List = emptyList(), - externalDocumentationLinks: List = emptyList(), - noStdlibLink: Boolean, - noJdkLink: Boolean = false, - val languageVersion: String?, - val apiVersion: String?, - cacheRoot: String? = null, - val suppressedFiles: Set = emptySet(), - val collectInheritedExtensionsFromLibraries: Boolean = false) { - init { - if (perPackageOptions.any { it.prefix == "" }) - throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead") - } - - val perPackageOptions = perPackageOptions.sortedByDescending { it.prefix.length } - val rootPackageOptions = PackageOptionsImpl("", includeNonPublic, reportUndocumented, skipDeprecated) - - fun effectivePackageOptions(pack: String): PackageOptions = perPackageOptions.firstOrNull { pack == it.prefix || pack.startsWith(it.prefix + ".") } ?: rootPackageOptions - fun effectivePackageOptions(pack: FqName): PackageOptions = effectivePackageOptions(pack.asString()) - - val defaultLinks = run { - val links = mutableListOf() - if (!noJdkLink) - links += ExternalDocumentationLink.Builder("http://docs.oracle.com/javase/$jdkVersion/docs/api/").build() - - if (!noStdlibLink) - links += ExternalDocumentationLink.Builder("https://kotlinlang.org/api/latest/jvm/stdlib/").build() - links - } - - val externalDocumentationLinks = defaultLinks + externalDocumentationLinks - - val cacheRoot: Path? = when { - cacheRoot == "default" -> Paths.get(System.getProperty("user.home"), ".cache", "dokka") - cacheRoot != null -> Paths.get(cacheRoot) - else -> null - } -} - private fun isExtensionForExternalClass(extensionFunctionDescriptor: DeclarationDescriptor, extensionReceiverDescriptor: DeclarationDescriptor, allFqNames: Collection): Boolean { @@ -120,7 +66,7 @@ val ignoredSupertypes = setOf( class DocumentationBuilder @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val descriptorDocumentationParser: DescriptorDocumentationParser, - val options: DocumentationOptions, + val passConfiguration: DokkaConfiguration.PassConfiguration, val refGraph: NodeReferenceGraph, val platformNodeRegistry: PlatformNodeRegistry, val logger: DokkaLogger, @@ -352,7 +298,7 @@ class DocumentationBuilder fun DocumentationNode.isSinceKotlin() = name == "SinceKotlin" && kind == NodeKind.Annotation fun DocumentationNode.appendSourceLink(sourceElement: SourceElement) { - appendSourceLink(sourceElement.getPsi(), options.sourceLinks) + appendSourceLink(sourceElement.getPsi(), passConfiguration.sourceLinks) } fun DocumentationNode.appendSignature(descriptor: DeclarationDescriptor) { @@ -360,7 +306,7 @@ class DocumentationBuilder } fun DocumentationNode.appendChild(descriptor: DeclarationDescriptor, kind: RefKind): DocumentationNode? { - if (!descriptor.isGenerated() && descriptor.isDocumented(options)) { + if (!descriptor.isGenerated() && descriptor.isDocumented(passConfiguration)) { val node = descriptor.build() append(node, kind) return node @@ -387,7 +333,7 @@ class DocumentationBuilder fun DocumentationNode.appendOrUpdateMember(descriptor: DeclarationDescriptor) { - if (descriptor.isGenerated() || !descriptor.isDocumented(options)) return + if (descriptor.isGenerated() || !descriptor.isDocumented(passConfiguration)) return val existingNode = refGraph.lookup(descriptor.signature()) if (existingNode != null) { @@ -459,10 +405,10 @@ class DocumentationBuilder val allFqNames = fragments.map { it.fqName }.distinct() for (packageName in allFqNames) { - if (packageName.isRoot && !options.includeRootPackage) continue + if (packageName.isRoot && !passConfiguration.includeRootPackage) continue val declarations = fragments.filter { it.fqName == packageName }.flatMap { it.getMemberScope().getContributedDescriptors() } - if (options.skipEmptyPackages && declarations.none { it.isDocumented(options) }) continue + if (passConfiguration.skipEmptyPackages && declarations.none { it.isDocumented(passConfiguration) }) continue logger.info(" package $packageName: ${declarations.count()} declarations") val packageNode = findOrCreatePackageNode(this, packageName.asString(), packageContent, this@DocumentationBuilder.refGraph) packageDocumentationBuilder.buildPackageDocumentation(this@DocumentationBuilder, packageName, packageNode, @@ -489,7 +435,7 @@ class DocumentationBuilder }.flatten() val allDescriptors = - if (options.collectInheritedExtensionsFromLibraries) { + if (passConfiguration.collectInheritedExtensionsFromLibraries) { allPackageViewDescriptors.map { it.memberScope } } else { fragments.asSequence().map { it.getMemberScope() } @@ -694,7 +640,7 @@ class DocumentationBuilder .mapTo(result) { ClassMember(it, extraModifier = "static") } val companionObjectDescriptor = companionObjectDescriptor - if (companionObjectDescriptor != null && companionObjectDescriptor.isDocumented(options)) { + if (companionObjectDescriptor != null && companionObjectDescriptor.isDocumented(passConfiguration)) { val descriptors = companionObjectDescriptor.defaultType.memberScope.getContributedDescriptors() val descriptorsToDocument = descriptors.filter { it !is CallableDescriptor || !it.isInheritedFromAny() } descriptorsToDocument.mapTo(result) { @@ -967,12 +913,12 @@ class DocumentationBuilder } -fun DeclarationDescriptor.isDocumented(options: DocumentationOptions): Boolean { - return (options.effectivePackageOptions(fqNameSafe).includeNonPublic +fun DeclarationDescriptor.isDocumented(passConfiguration: DokkaConfiguration.PassConfiguration): Boolean { + return (passConfiguration.effectivePackageOptions(fqNameSafe).includeNonPublic || this !is MemberDescriptor || this.visibility.isPublicAPI) - && !isDocumentationSuppressed(options) - && (!options.effectivePackageOptions(fqNameSafe).skipDeprecated || !isDeprecated()) + && !isDocumentationSuppressed(passConfiguration) + && (!passConfiguration.effectivePackageOptions(fqNameSafe).skipDeprecated || !isDeprecated()) } private fun DeclarationDescriptor.isGenerated() = this is CallableMemberDescriptor && kind != CallableMemberDescriptor.Kind.DECLARATION @@ -986,7 +932,7 @@ class KotlinPackageDocumentationBuilder : PackageDocumentationBuilder { val externalClassNodes = hashMapOf() declarations.forEach { descriptor -> with(documentationBuilder) { - if (descriptor.isDocumented(options)) { + if (descriptor.isDocumented(passConfiguration)) { val parent = packageNode.getParentForPackageMember(descriptor, externalClassNodes, allFqNames) parent.appendOrUpdateMember(descriptor) } @@ -998,14 +944,14 @@ class KotlinPackageDocumentationBuilder : PackageDocumentationBuilder { class KotlinJavaDocumentationBuilder @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val documentationBuilder: DocumentationBuilder, - val options: DocumentationOptions, + val passConfiguration: DokkaConfiguration.PassConfiguration, val logger: DokkaLogger) : JavaDocumentationBuilder { override fun appendFile(file: PsiJavaFile, module: DocumentationModule, packageContent: Map) { val classDescriptors = file.classes.map { it.getJavaClassDescriptor(resolutionFacade) } - if (classDescriptors.any { it != null && it.isDocumented(options) }) { + if (classDescriptors.any { it != null && it.isDocumented(passConfiguration) }) { val packageNode = findOrCreatePackageNode(module, file.packageName, packageContent, documentationBuilder.refGraph) for (descriptor in classDescriptors.filterNotNull()) { @@ -1035,13 +981,13 @@ fun AnnotationDescriptor.mustBeDocumented(): Boolean { return annotationClass.isDocumentedAnnotation() } -fun DeclarationDescriptor.isDocumentationSuppressed(options: DocumentationOptions): Boolean { +fun DeclarationDescriptor.isDocumentationSuppressed(passConfiguration: DokkaConfiguration.PassConfiguration): Boolean { - if (options.effectivePackageOptions(fqNameSafe).suppress) return true + if (passConfiguration.effectivePackageOptions(fqNameSafe).suppress) return true val path = this.findPsi()?.containingFile?.virtualFile?.path if (path != null) { - if (File(path).absoluteFile in options.suppressedFiles) return true + if (path in passConfiguration.suppressedFiles) return true } val doc = findKDoc() @@ -1079,7 +1025,7 @@ fun DeclarationDescriptor.signature(): String { is TypeAliasDescriptor -> DescriptorUtils.getFqName(this).asString() is PropertyDescriptor -> containingDeclaration.signature() + "$" + name + receiverSignature() - is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() + ":" + returnType?.signature() + is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() + ":" + returnType?.signature() is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name is ReceiverParameterDescriptor -> containingDeclaration.signature() + "/" + name @@ -1140,8 +1086,8 @@ fun DeclarationDescriptor.sourceLocation(): String? { return null } -fun DocumentationModule.prepareForGeneration(options: DocumentationOptions) { - if (options.generateIndexPages) { +fun DocumentationModule.prepareForGeneration(configuration: DokkaConfiguration) { + if (configuration.generateIndexPages) { generateAllTypesNode() } nodeRefGraph.resolveReferences() @@ -1167,4 +1113,12 @@ fun ClassDescriptor.supertypesWithAnyPrecise(): Collection { return emptyList() } return typeConstructor.supertypesWithAny() -} \ No newline at end of file +} + +fun PassConfiguration.effectivePackageOptions(pack: String): DokkaConfiguration.PackageOptions { + val rootPackageOptions = PackageOptionsImpl("", includeNonPublic, reportUndocumented, skipDeprecated) + return perPackageOptions.firstOrNull { pack == it.prefix || pack.startsWith(it.prefix + ".") } ?: rootPackageOptions +} + +fun PassConfiguration.effectivePackageOptions(pack: FqName): DokkaConfiguration.PackageOptions = effectivePackageOptions(pack.asString()) + diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt index a8129793..2fc207b9 100644 --- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt @@ -22,6 +22,7 @@ import java.net.HttpURLConnection import java.net.URL import java.net.URLConnection import java.nio.file.Path +import java.nio.file.Paths import java.security.MessageDigest import javax.inject.Named import kotlin.reflect.full.findAnnotation @@ -30,7 +31,8 @@ fun ByteArray.toHexString() = this.joinToString(separator = "") { "%02x".format( @Singleton class ExternalDocumentationLinkResolver @Inject constructor( - val options: DocumentationOptions, + val configuration: DokkaConfiguration, + val passConfiguration: DokkaConfiguration.PassConfiguration, @Named("libraryResolutionFacade") val libraryResolutionFacade: DokkaResolutionFacade, val logger: DokkaLogger ) { @@ -42,7 +44,12 @@ class ExternalDocumentationLinkResolver @Inject constructor( override fun toString(): String = rootUrl.toString() } - val cacheDir: Path? = options.cacheRoot?.resolve("packageListCache")?.apply { createDirectories() } + + val cacheDir: Path? = when { + configuration.cacheRoot == "default" -> Paths.get(System.getProperty("user.home"), ".cache", "dokka") + configuration.cacheRoot != null -> Paths.get(configuration.cacheRoot) + else -> null + }?.resolve("packageListCache")?.apply { createDirectories() } val cachedProtocols = setOf("http", "https", "ftp") @@ -157,7 +164,7 @@ class ExternalDocumentationLinkResolver @Inject constructor( } init { - options.externalDocumentationLinks.forEach { + passConfiguration.externalDocumentationLinks.forEach { try { loadPackageList(it) } catch (e: Exception) { diff --git a/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt index c7ed8292..be6dd2e1 100644 --- a/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt @@ -28,7 +28,7 @@ class KotlinAsJavaDocumentationBuilder return } - val javaDocumentationBuilder = JavaPsiDocumentationBuilder(documentationBuilder.options, + val javaDocumentationBuilder = JavaPsiDocumentationBuilder(documentationBuilder.passConfiguration, documentationBuilder.refGraph, kotlinAsJavaDocumentationParser) diff --git a/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt b/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt index 116a5c02..f3f45c3f 100644 --- a/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt +++ b/core/src/main/kotlin/Samples/DefaultSampleProcessingService.kt @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.resolve.scopes.ResolutionScope open class DefaultSampleProcessingService -@Inject constructor(val options: DocumentationOptions, +@Inject constructor(val configuration: DokkaConfiguration, val logger: DokkaLogger, val resolutionFacade: DokkaResolutionFacade) : SampleProcessingService { diff --git a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt index b0988c35..b5801457 100644 --- a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt +++ b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt @@ -12,10 +12,10 @@ import org.jetbrains.kotlin.psi.psiUtil.prevLeaf import org.jetbrains.kotlin.resolve.ImportPath open class KotlinWebsiteSampleProcessingService -@Inject constructor(options: DocumentationOptions, +@Inject constructor(dokkaConfiguration: DokkaConfiguration, logger: DokkaLogger, resolutionFacade: DokkaResolutionFacade) - : DefaultSampleProcessingService(options, logger, resolutionFacade) { + : DefaultSampleProcessingService(dokkaConfiguration, logger, resolutionFacade) { private class SampleBuilder : KtTreeVisitorVoid() { val builder = StringBuilder() diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index 732cbc48..251d5c23 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -14,9 +14,10 @@ import kotlin.reflect.KClass const val impliedPlatformsName = "impliedPlatforms" class DokkaAnalysisModule(val environment: AnalysisEnvironment, - val options: DocumentationOptions, + val configuration: DokkaConfiguration, val defaultPlatformsProvider: DefaultPlatformsProvider, val nodeReferenceGraph: NodeReferenceGraph, + val passConfiguration: DokkaConfiguration.PassConfiguration, val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { binder.bind().toInstance(logger) @@ -28,29 +29,30 @@ class DokkaAnalysisModule(val environment: AnalysisEnvironment, binder.bind().toInstance(dokkaResolutionFacade) binder.bind().annotatedWith(Names.named("libraryResolutionFacade")).toInstance(libraryResolutionFacade) - binder.bind().toInstance(options) + binder.bind().toInstance(configuration) + binder.bind().toInstance(passConfiguration) binder.bind().toInstance(defaultPlatformsProvider) binder.bind().toInstance(nodeReferenceGraph) - val descriptor = ServiceLocator.lookup("format", options.outputFormat) + val descriptor = ServiceLocator.lookup("format", configuration.format) descriptor.configureAnalysis(binder) } } object StringListType : TypeLiteral<@JvmSuppressWildcards List>() -class DokkaOutputModule(val options: DocumentationOptions, +class DokkaOutputModule(val configuration: DokkaConfiguration, val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { - binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(options.outputDir)) + binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(configuration.outputDir)) - binder.bind().toInstance(options) + binder.bind().toInstance(configuration) binder.bind().toInstance(logger) - binder.bind(StringListType).annotatedWith(Names.named(impliedPlatformsName)).toInstance(options.impliedPlatforms) + binder.bind(StringListType).annotatedWith(Names.named(impliedPlatformsName)).toInstance(configuration.impliedPlatforms) - val descriptor = ServiceLocator.lookup("format", options.outputFormat) + val descriptor = ServiceLocator.lookup("format", configuration.format) descriptor.configureOutput(binder) } diff --git a/core/src/main/kotlin/javadoc/dokka-adapters.kt b/core/src/main/kotlin/javadoc/dokka-adapters.kt index 483fb3cd..1329876a 100644 --- a/core/src/main/kotlin/javadoc/dokka-adapters.kt +++ b/core/src/main/kotlin/javadoc/dokka-adapters.kt @@ -4,16 +4,19 @@ import com.google.inject.Binder import com.google.inject.Inject import com.sun.tools.doclets.formats.html.HtmlDoclet import org.jetbrains.dokka.* -import org.jetbrains.dokka.Formats.* +import org.jetbrains.dokka.Formats.DefaultAnalysisComponent +import org.jetbrains.dokka.Formats.DefaultAnalysisComponentServices +import org.jetbrains.dokka.Formats.FormatDescriptor +import org.jetbrains.dokka.Formats.KotlinAsJava import org.jetbrains.dokka.Utilities.bind import org.jetbrains.dokka.Utilities.toType -class JavadocGenerator @Inject constructor(val options: DocumentationOptions, val logger: DokkaLogger) : Generator { +class JavadocGenerator @Inject constructor(val configuration: DokkaConfiguration, val logger: DokkaLogger) : Generator { override fun buildPages(nodes: Iterable) { val module = nodes.single() as DocumentationModule - HtmlDoclet.start(ModuleNodeAdapter(module, StandardReporter(logger), options.outputDir)) + HtmlDoclet.start(ModuleNodeAdapter(module, StandardReporter(logger), configuration.outputDir)) } override fun buildOutlines(nodes: Iterable) { diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 4a755130..b65efbe9 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -35,31 +35,35 @@ fun verifyModel(modelConfig: ModelConfig, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") - val options = DocumentationOptions( - "", - modelConfig.format, - includeNonPublic = modelConfig.includeNonPublic, - skipEmptyPackages = false, - includeRootPackage = true, - sourceLinks = listOf(), - perPackageOptions = modelConfig.perPackageOptions, - generateIndexPages = false, - noStdlibLink = modelConfig.noStdlibLink, - noJdkLink = false, - cacheRoot = "default", - languageVersion = null, - apiVersion = null, - collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries + val passConfiguration = PassConfigurationImpl ( + includeNonPublic = modelConfig.includeNonPublic, + skipEmptyPackages = false, + includeRootPackage = true, + sourceLinks = listOf(), + 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, options, modelConfig) - documentation.prepareForGeneration(options) + appendDocumentation(documentation, configuration, passConfiguration, modelConfig) + documentation.prepareForGeneration(configuration) verifier(documentation) } fun appendDocumentation(documentation: DocumentationModule, - options: DocumentationOptions, + dokkaConfiguration: DokkaConfiguration, + passConfiguration: DokkaConfiguration.PassConfiguration, modelConfig: ModelConfig ) { val messageCollector = object : MessageCollector { @@ -108,13 +112,13 @@ fun appendDocumentation(documentation: DocumentationModule, } addRoots(modelConfig.roots.toList()) - loadLanguageVersionSettings(options.languageVersion, options.apiVersion) + loadLanguageVersionSettings(passConfiguration.languageVersion, passConfiguration.apiVersion) } val defaultPlatformsProvider = object : DefaultPlatformsProvider { override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms } val injector = Guice.createInjector( - DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentation.nodeRefGraph, DokkaConsoleLogger)) + DokkaAnalysisModule(environment, dokkaConfiguration, defaultPlatformsProvider, documentation.nodeRefGraph, passConfiguration, DokkaConsoleLogger)) buildDocumentationModule(injector, documentation) Disposer.dispose(environment) } diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index 643b5b2d..4f292e37 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -48,17 +48,20 @@ class KotlinWebSiteFormatTest: FileGeneratorTestCase() { private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, + val passConfiguration = PassConfigurationImpl(noStdlibLink = true, noJdkLink = true, languageVersion = null, apiVersion = null ) + val configuration = DokkaConfigurationImpl( + outputDir = "", + format = "html", + generateIndexPages = false, + passesConfigurations = listOf(passConfiguration) + ) + appendDocumentation( - module, options, ModelConfig( + module, configuration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/website/$path/jvm.kt")), defaultPlatforms = listOf("JVM") ) @@ -67,13 +70,13 @@ class KotlinWebSiteFormatTest: FileGeneratorTestCase() { appendDocumentation( - module, options, ModelConfig( + module, configuration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/website/$path/jre7.kt")), defaultPlatforms = listOf("JVM", "JRE7") ) ) appendDocumentation( - module, options, ModelConfig( + module, configuration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/website/$path/js.kt")), defaultPlatforms = listOf("JS") ) diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index 3ae0930e..1901154f 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -64,29 +64,37 @@ abstract class BaseKotlinWebSiteHtmlFormatTest(val analysisPlatform: Platform): private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "kotlin-website-html", - generateIndexPages = false, + val passConfiguration = PassConfigurationImpl( noStdlibLink = true, noJdkLink = true, languageVersion = null, apiVersion = null ) + + val dokkaConfiguration = DokkaConfigurationImpl( + outputDir = "", + format = "kotlin-website-html", + generateIndexPages = false, + passesConfigurations = listOf( + passConfiguration + ) + + ) + appendDocumentation( - module, options, ModelConfig( + module, dokkaConfiguration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/jvm.kt")), defaultPlatforms = listOf("JVM") ) ) appendDocumentation( - module, options, ModelConfig( + module, dokkaConfiguration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/jre7.kt")), defaultPlatforms = listOf("JVM", "JRE7") ) ) appendDocumentation( - module, options, ModelConfig( + module, dokkaConfiguration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/js.kt")), defaultPlatforms = listOf("JS") ) diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 4de70751..29d2d20f 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -1,7 +1,6 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* -import org.junit.Before import org.junit.Test abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { @@ -249,16 +248,23 @@ abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGener @Test fun packagePlatformsWithExtExtensions() { val path = "multiplatform/packagePlatformsWithExtExtensions" val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, + val passConfiguration = PassConfigurationImpl( noStdlibLink = true, noJdkLink = true, languageVersion = null, apiVersion = null ) - appendDocumentation(module, options, ModelConfig( + + val dokkaConfiguration = DokkaConfigurationImpl( + outputDir = "", + format = "html", + generateIndexPages = false, + passesConfigurations = listOf( + passConfiguration + ) + ) + + appendDocumentation(module, dokkaConfiguration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), defaultPlatforms = listOf("JVM"), withKotlinRuntime = true, @@ -373,24 +379,30 @@ abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGener private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, + val passConfiguration = PassConfigurationImpl( noStdlibLink = true, noJdkLink = true, languageVersion = null, apiVersion = null ) + val dokkaConfiguration = DokkaConfigurationImpl( + outputDir = "", + format = "html", + generateIndexPages = false, + passesConfigurations = listOf( + passConfiguration + ) + + ) appendDocumentation( - module, options, ModelConfig( + module, dokkaConfiguration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), defaultPlatforms = listOf("JVM"), analysisPlatform = Platform.jvm ) ) appendDocumentation( - module, options, ModelConfig( + module, dokkaConfiguration, passConfiguration, ModelConfig( roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), defaultPlatforms = listOf("JS"), analysisPlatform = Platform.js diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt index 287b628a..e0fa27d1 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -39,31 +39,37 @@ enum class Platform(val key: String) { } interface DokkaConfiguration { - val moduleName: String - val classpath: List - val sourceRoots: List - val samples: List - val includes: List val outputDir: String val format: String - val includeNonPublic: Boolean - val includeRootPackage: Boolean - val reportUndocumented: Boolean - val skipEmptyPackages: Boolean - val skipDeprecated: Boolean - val jdkVersion: Int val generateIndexPages: Boolean - val sourceLinks: List - val impliedPlatforms: List - val perPackageOptions: List - val externalDocumentationLinks: List - val languageVersion: String? - val apiVersion: String? - val noStdlibLink: Boolean - val noJdkLink: Boolean val cacheRoot: String? - val suppressedFiles: List - val collectInheritedExtensionsFromLibraries: Boolean + val passesConfigurations: List + val impliedPlatforms: List + + interface PassConfiguration { + val moduleName: String + val classpath: List + val sourceRoots: List + val samples: List + val includes: List + val includeNonPublic: Boolean + val includeRootPackage: Boolean + val reportUndocumented: Boolean + val skipEmptyPackages: Boolean + val skipDeprecated: Boolean + val jdkVersion: Int + val sourceLinks: List + val perPackageOptions: List + val externalDocumentationLinks: List + val languageVersion: String? + val apiVersion: String? + val noStdlibLink: Boolean + val noJdkLink: Boolean + val suppressedFiles: List + val collectInheritedExtensionsFromLibraries: Boolean + val analysisPlatform: Platform + val targets: List + } interface SourceRoot { val path: String @@ -106,31 +112,12 @@ interface DokkaConfiguration { } data class SerializeOnlyDokkaConfiguration( - override val moduleName: String, - override val classpath: List, - override val sourceRoots: List, - override val samples: List, - override val includes: List, override val outputDir: String, override val format: String, - override val includeNonPublic: Boolean, - override val includeRootPackage: Boolean, - override val reportUndocumented: Boolean, - override val skipEmptyPackages: Boolean, - override val skipDeprecated: Boolean, - override val jdkVersion: Int, override val generateIndexPages: Boolean, - override val sourceLinks: List, - override val impliedPlatforms: List, - override val perPackageOptions: List, - override val externalDocumentationLinks: List, - override val noStdlibLink: Boolean, - override val noJdkLink: Boolean, override val cacheRoot: String?, - override val suppressedFiles: List, - override val languageVersion: String?, - override val apiVersion: String?, - override val collectInheritedExtensionsFromLibraries: Boolean + override val impliedPlatforms: List, + override val passesConfigurations: List ) : DokkaConfiguration diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index 0b1ccc13..4f629198 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -116,29 +116,34 @@ class DokkaAntTask: Task() { SourceLinkDefinitionImpl(File(path).canonicalFile.absolutePath, url, it.lineSuffix) } - val generator = DokkaGenerator( - AntLogger(this), - compileClasspath.list().toList(), - sourcePath.list().map { SourceRootImpl(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() }, - samplesPath.list().toList(), - includesPath.list().toList(), - moduleName!!, - DocumentationOptions( - outputDir!!, - outputFormat, - skipDeprecated = skipDeprecated, - sourceLinks = sourceLinks, - jdkVersion = jdkVersion, - impliedPlatforms = impliedPlatforms.split(','), - perPackageOptions = antPackageOptions, - externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() }, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, - cacheRoot = cacheRoot, - languageVersion = languageVersion, - apiVersion = apiVersion - ) + val passConfiguration = PassConfigurationImpl( + classpath = compileClasspath.list().toList(), + sourceRoots = sourcePath.list().map { SourceRootImpl(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() }, + samples = samplesPath.list().toList(), + includes = includesPath.list().toList(), + moduleName = moduleName!!, + skipDeprecated = skipDeprecated, + sourceLinks = sourceLinks, + jdkVersion = jdkVersion, + perPackageOptions = antPackageOptions, + externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() }, + noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, + languageVersion = languageVersion, + apiVersion = apiVersion ) + + val configuration = DokkaConfigurationImpl( + outputDir = outputDir!!, + format = outputFormat, + impliedPlatforms = impliedPlatforms.split(','), + cacheRoot = cacheRoot, + passesConfigurations = listOf( + passConfiguration + ) + ) + + val generator = DokkaGenerator(configuration, AntLogger(this)) generator.generate() } } \ No newline at end of file diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index f871f406..330de5e1 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -44,7 +44,7 @@ class DokkaArguments { @set:Argument(value = "impliedPlatforms", description = "List of implied platforms (comma-separated)") var impliedPlatforms: String = "" - @set:Argument(value = "packageOptions", description = "List of package options in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" ") + @set:Argument(value = "packageOptions", description = "List of package passConfiguration in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" ") var packageOptions: String = "" @set:Argument(value = "links", description = "External documentation links in format url^packageListUrl^^url2...") @@ -111,31 +111,37 @@ object MainKt { val classPath = arguments.classpath.split(File.pathSeparatorChar).toList() - val documentationOptions = DocumentationOptions( - arguments.outputDir.let { if (it.endsWith('/')) it else it + '/' }, - arguments.outputFormat, + val passConfig = PassConfigurationImpl( skipDeprecated = arguments.nodeprecated, sourceLinks = sourceLinks, - impliedPlatforms = arguments.impliedPlatforms.split(','), perPackageOptions = parsePerPackageOptions(arguments.packageOptions), jdkVersion = arguments.jdkVersion, externalDocumentationLinks = parseLinks(arguments.links), noStdlibLink = arguments.noStdlibLink, - cacheRoot = arguments.cacheRoot, languageVersion = arguments.languageVersion, apiVersion = arguments.apiVersion, collectInheritedExtensionsFromLibraries = arguments.collectInheritedExtensionsFromLibraries, - noJdkLink = arguments.noJdkLink + noJdkLink = arguments.noJdkLink, + sourceRoots = sources.map(SourceRootImpl.Companion::parseSourceRoot), + analysisPlatform = sources.map (SourceRootImpl.Companion::parseSourceRoot).single().analysisPlatform, + samples = samples, + includes = includes, + moduleName = arguments.moduleName, + classpath = classPath + ) + + val config = DokkaConfigurationImpl( + outputDir = arguments.outputDir.let { if (it.endsWith('/')) it else it + '/' }, + format = arguments.outputFormat, + impliedPlatforms = arguments.impliedPlatforms.split(','), + cacheRoot = arguments.cacheRoot, + + passesConfigurations = listOf( + passConfig + ) ) - val generator = DokkaGenerator( - DokkaConsoleLogger, - classPath, - sources.map(SourceRootImpl.Companion::parseSourceRoot), - samples, - includes, - arguments.moduleName, - documentationOptions) + val generator = DokkaGenerator(config, DokkaConsoleLogger) generator.generate() DokkaConsoleLogger.report() diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index ea55c8fe..78fd2d86 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -129,30 +129,33 @@ abstract class AbstractDokkaMojo : AbstractMojo() { return } - val gen = DokkaGenerator( - MavenDokkaLogger(log), - classpath, - sourceDirectories.map { SourceRootImpl(it) } + sourceRoots, - samplesDirs, - includeDirs + includes, - moduleName, - DocumentationOptions(getOutDir(), getOutFormat(), - sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.dir, it.url, it.urlSuffix) }, - jdkVersion = jdkVersion, - skipDeprecated = skipDeprecated, - skipEmptyPackages = skipEmptyPackages, - reportUndocumented = reportNotDocumented, - impliedPlatforms = impliedPlatforms, - perPackageOptions = perPackageOptions, - externalDocumentationLinks = externalDocumentationLinks.map { it.build() }, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, - cacheRoot = cacheRoot, - languageVersion = languageVersion, - apiVersion = apiVersion - ) + val passConfiguration = PassConfigurationImpl( + sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.dir, it.url, it.urlSuffix) }, + jdkVersion = jdkVersion, + skipDeprecated = skipDeprecated, + skipEmptyPackages = skipEmptyPackages, + reportUndocumented = reportNotDocumented, + perPackageOptions = perPackageOptions, + externalDocumentationLinks = externalDocumentationLinks.map { it.build() }, + noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, + languageVersion = languageVersion, + apiVersion = apiVersion + + ) + + val configuration = DokkaConfigurationImpl( + outputDir = getOutDir(), + format = getOutFormat(), + impliedPlatforms = impliedPlatforms, + cacheRoot = cacheRoot, + passesConfigurations = listOf( + passConfiguration + ) ) + val gen = DokkaGenerator(configuration, MavenDokkaLogger(log)) + gen.generate() } } -- cgit From ba09711a1ecbdaede86cab9e76d13ff1047f89b2 Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Thu, 2 Aug 2018 18:59:20 +0300 Subject: ExternalDocumentationLinkResolver refactoring, extract common dependencies from guice modules --- core/src/main/kotlin/Generation/DokkaGenerator.kt | 11 +- .../Kotlin/ExternalDocumentationLinkResolver.kt | 114 ++++++++++++++------- core/src/main/kotlin/Utilities/DokkaModules.kt | 19 ++-- core/src/test/kotlin/TestAPI.kt | 19 +++- 4 files changed, 112 insertions(+), 51 deletions(-) (limited to 'core/src/test') diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 2e46d908..22d1519f 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -9,6 +9,7 @@ import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager import org.jetbrains.dokka.Utilities.DokkaAnalysisModule import org.jetbrains.dokka.Utilities.DokkaOutputModule +import org.jetbrains.dokka.Utilities.DokkaRunModule import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -27,6 +28,7 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, val logger: DokkaLogger) { private val documentationModules: MutableList = mutableListOf() + private val globalInjector = Guice.createInjector(DokkaRunModule(dokkaConfiguration)) fun generate() = with(dokkaConfiguration) { @@ -43,8 +45,9 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, val timeBuild = measureTimeMillis { logger.info("Generating pages... ") - val outputInjector = Guice.createInjector(DokkaOutputModule(dokkaConfiguration, logger)) - outputInjector.getInstance(Generator::class.java).buildAll(totalDocumentationModule) + val outputInjector = globalInjector.createChildInjector(DokkaOutputModule(dokkaConfiguration, logger)) + val instance = outputInjector.getInstance(Generator::class.java) + instance.buildAll(totalDocumentationModule) } logger.info("done in ${timeBuild / 1000} secs") } @@ -75,11 +78,11 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration, } } - val injector = Guice.createInjector( + val injector = globalInjector.createChildInjector( DokkaAnalysisModule(environment, dokkaConfiguration, defaultPlatformsProvider, documentationModule.nodeRefGraph, passConfiguration, logger)) buildDocumentationModule(injector, documentationModule, { isNotSample(it, passConfiguration.samples) }, includes) - documentationModule.nodeRefGraph.nodeMapView.forEach { (_, node) -> + documentationModule.nodeRefGraph.nodeMapView.forEach { (_, node) -> // FIXME: change to full graph visiting node.addReferenceTo( DocumentationNode(analysisPlatform.key, Content.Empty, NodeKind.Platform), RefKind.Platform diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt index 2fc207b9..9d986aee 100644 --- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt @@ -29,21 +29,14 @@ import kotlin.reflect.full.findAnnotation fun ByteArray.toHexString() = this.joinToString(separator = "") { "%02x".format(it) } +typealias PackageFqNameToLocation = MutableMap + @Singleton -class ExternalDocumentationLinkResolver @Inject constructor( - val configuration: DokkaConfiguration, - val passConfiguration: DokkaConfiguration.PassConfiguration, - @Named("libraryResolutionFacade") val libraryResolutionFacade: DokkaResolutionFacade, - val logger: DokkaLogger +class PackageListProvider @Inject constructor( + val configuration: DokkaConfiguration, + val logger: DokkaLogger ) { - - val packageFqNameToLocation = mutableMapOf() - val formats = mutableMapOf() - - class ExternalDocumentationRoot(val rootUrl: URL, val resolver: InboundExternalLinkResolutionService, val locations: Map) { - override fun toString(): String = rootUrl.toString() - } - + val storage = mutableMapOf() val cacheDir: Path? = when { configuration.cacheRoot == "default" -> Paths.get(System.getProperty("user.home"), ".cache", "dokka") @@ -53,6 +46,25 @@ class ExternalDocumentationLinkResolver @Inject constructor( val cachedProtocols = setOf("http", "https", "ftp") + init { + for (conf in configuration.passesConfigurations) { + for (link in conf.externalDocumentationLinks) { + if (link in storage) { + continue + } + + try { + loadPackageList(link) + } catch (e: Exception) { + throw RuntimeException("Exception while loading package-list from $link", e) + } + } + + } + } + + + fun URL.doOpenConnectionToReadContent(timeout: Int = 10000, redirectsAllowed: Int = 16): URLConnection { val connection = this.openConnection() connection.connectTimeout = timeout @@ -127,23 +139,23 @@ class ExternalDocumentationLinkResolver @Inject constructor( val (params, packages) = packageListStream - .bufferedReader() - .useLines { lines -> lines.partition { it.startsWith(DOKKA_PARAM_PREFIX) } } + .bufferedReader() + .useLines { lines -> lines.partition { it.startsWith(ExternalDocumentationLinkResolver.DOKKA_PARAM_PREFIX) } } val paramsMap = params.asSequence() - .map { it.removePrefix(DOKKA_PARAM_PREFIX).split(":", limit = 2) } - .groupBy({ (key, _) -> key }, { (_, value) -> value }) + .map { it.removePrefix(ExternalDocumentationLinkResolver.DOKKA_PARAM_PREFIX).split(":", limit = 2) } + .groupBy({ (key, _) -> key }, { (_, value) -> value }) val format = paramsMap["format"]?.singleOrNull() ?: "javadoc" val locations = paramsMap["location"].orEmpty() - .map { it.split("\u001f", limit = 2) } - .map { (key, value) -> key to value } - .toMap() + .map { it.split("\u001f", limit = 2) } + .map { (key, value) -> key to value } + .toMap() - val defaultResolverDesc = services["dokka-default"]!! - val resolverDesc = services[format] + val defaultResolverDesc = ExternalDocumentationLinkResolver.services["dokka-default"]!! + val resolverDesc = ExternalDocumentationLinkResolver.services[format] ?: defaultResolverDesc.takeIf { format in formatsWithDefaultResolver } ?: defaultResolverDesc.also { logger.warn("Couldn't find InboundExternalLinkResolutionService(format = `$format`) for $link, using Dokka default") @@ -160,16 +172,52 @@ class ExternalDocumentationLinkResolver @Inject constructor( val rootInfo = ExternalDocumentationRoot(link.url, resolver, locations) - packages.map { FqName(it) }.forEach { packageFqNameToLocation[it] = rootInfo } + val packageFqNameToLocation = mutableMapOf() + storage[link] = packageFqNameToLocation + + val fqNames = packages.map { FqName(it) } + for(name in fqNames) { + packageFqNameToLocation[name] = rootInfo + } + } + + + + class ExternalDocumentationRoot(val rootUrl: URL, val resolver: InboundExternalLinkResolutionService, val locations: Map) { + override fun toString(): String = rootUrl.toString() } + companion object { + private val formatsWithDefaultResolver = + ServiceLocator + .allServices("format") + .filter { + val desc = ServiceLocator.lookup(it) as? FileGeneratorBasedFormatDescriptor + desc?.generatorServiceClass == FileGenerator::class + }.map { it.name } + .toSet() + + } + +} + +class ExternalDocumentationLinkResolver @Inject constructor( + val configuration: DokkaConfiguration, + val passConfiguration: DokkaConfiguration.PassConfiguration, + @Named("libraryResolutionFacade") val libraryResolutionFacade: DokkaResolutionFacade, + val logger: DokkaLogger, + val packageListProvider: PackageListProvider +) { + + val formats = mutableMapOf() + val packageFqNameToLocation = mutableMapOf() + init { - passConfiguration.externalDocumentationLinks.forEach { - try { - loadPackageList(it) - } catch (e: Exception) { - throw RuntimeException("Exception while loading package-list from $it", e) - } + val fqNameToLocationMaps = passConfiguration.externalDocumentationLinks + .mapNotNull { packageListProvider.storage[it] } + + for(map in fqNameToLocationMaps) { + packageFqNameToLocation.putAll(map) } } @@ -198,14 +246,6 @@ class ExternalDocumentationLinkResolver @Inject constructor( companion object { const val DOKKA_PARAM_PREFIX = "\$dokka." val services = ServiceLocator.allServices("inbound-link-resolver").associateBy { it.name } - private val formatsWithDefaultResolver = - ServiceLocator - .allServices("format") - .filter { - val desc = ServiceLocator.lookup(it) as? FileGeneratorBasedFormatDescriptor - desc?.generatorServiceClass == FileGenerator::class - }.map { it.name } - .toSet() } } diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index 251d5c23..c2e652b6 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -1,8 +1,6 @@ package org.jetbrains.dokka.Utilities -import com.google.inject.Binder -import com.google.inject.Module -import com.google.inject.TypeLiteral +import com.google.inject.* import com.google.inject.binder.AnnotatedBindingBuilder import com.google.inject.name.Names import org.jetbrains.dokka.* @@ -13,6 +11,16 @@ import kotlin.reflect.KClass const val impliedPlatformsName = "impliedPlatforms" +class DokkaRunModule(val configuration: DokkaConfiguration) : Module { + override fun configure(binder: Binder) { + binder.bind().toInstance(configuration) + binder.bind(StringListType).annotatedWith(Names.named(impliedPlatformsName)).toInstance(configuration.impliedPlatforms) + + binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(configuration.outputDir)) + } + +} + class DokkaAnalysisModule(val environment: AnalysisEnvironment, val configuration: DokkaConfiguration, val defaultPlatformsProvider: DefaultPlatformsProvider, @@ -29,7 +37,6 @@ class DokkaAnalysisModule(val environment: AnalysisEnvironment, binder.bind().toInstance(dokkaResolutionFacade) binder.bind().annotatedWith(Names.named("libraryResolutionFacade")).toInstance(libraryResolutionFacade) - binder.bind().toInstance(configuration) binder.bind().toInstance(passConfiguration) binder.bind().toInstance(defaultPlatformsProvider) @@ -46,11 +53,7 @@ object StringListType : TypeLiteral<@JvmSuppressWildcards List>() class DokkaOutputModule(val configuration: DokkaConfiguration, val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { - binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(configuration.outputDir)) - - binder.bind().toInstance(configuration) binder.bind().toInstance(logger) - binder.bind(StringListType).annotatedWith(Names.named(impliedPlatformsName)).toInstance(configuration.impliedPlatforms) val descriptor = ServiceLocator.lookup("format", configuration.format) diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index b65efbe9..8974bd0b 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -7,6 +7,7 @@ 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.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -117,8 +118,22 @@ fun appendDocumentation(documentation: DocumentationModule, val defaultPlatformsProvider = object : DefaultPlatformsProvider { override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms } - val injector = Guice.createInjector( - DokkaAnalysisModule(environment, dokkaConfiguration, defaultPlatformsProvider, documentation.nodeRefGraph, passConfiguration, DokkaConsoleLogger)) + + val globalInjector = Guice.createInjector( + DokkaRunModule(dokkaConfiguration) + ) + + val injector = globalInjector.createChildInjector( + DokkaAnalysisModule( + environment, + dokkaConfiguration, + defaultPlatformsProvider, + documentation.nodeRefGraph, + passConfiguration, + DokkaConsoleLogger + ) + ) + buildDocumentationModule(injector, documentation) Disposer.dispose(environment) } -- cgit