aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-12-04 18:12:01 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-12-04 18:12:01 +0300
commit3098b8e7665bcda25f8ead2496c161e10512d7b3 (patch)
treedca2dfdf934811d7f865f2fdb215cbcf8e6eaf07 /core/src
parente126ff625eba33d91b3242a4e6e951d1e9f94080 (diff)
downloaddokka-3098b8e7665bcda25f8ead2496c161e10512d7b3.tar.gz
dokka-3098b8e7665bcda25f8ead2496c161e10512d7b3.tar.bz2
dokka-3098b8e7665bcda25f8ead2496c161e10512d7b3.zip
Introduce test case with preset FileGenerator
Diffstat (limited to 'core/src')
-rw-r--r--core/src/test/kotlin/TestAPI.kt11
-rw-r--r--core/src/test/kotlin/format/FileGeneratorTestCase.kt31
-rw-r--r--core/src/test/kotlin/format/GFMFormatTest.kt12
-rw-r--r--core/src/test/kotlin/format/HtmlFormatTest.kt19
-rw-r--r--core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt16
-rw-r--r--core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt15
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt33
-rw-r--r--core/src/test/kotlin/format/PackageDocsTest.kt7
8 files changed, 69 insertions, 75 deletions
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<DocumentationNode>, 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<DocumentationNode>, 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<DocumentationNode>) {
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<DocumentationNode>) {
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<DocumentationNode>) {
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()