diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-05-27 19:26:13 +0200 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-05-27 19:26:13 +0200 |
commit | bc0654e29891fa5e93b8d122518179779aae7e6a (patch) | |
tree | 60dd25e65d1ef19b315c99c06072244f4c37700d /test | |
parent | 70a70ca9dad31477877251b271a329d048f7873f (diff) | |
download | dokka-bc0654e29891fa5e93b8d122518179779aae7e6a.tar.gz dokka-bc0654e29891fa5e93b8d122518179779aae7e6a.tar.bz2 dokka-bc0654e29891fa5e93b8d122518179779aae7e6a.zip |
allow to explicitly specify the type of root for every input path
Diffstat (limited to 'test')
-rw-r--r-- | test/data/format/crossLanguage/kotlinExtendsJava/Bar.html (renamed from test/data/format/crossLanguage/kotlinExtendsJava.html) | 0 | ||||
-rw-r--r-- | test/src/TestAPI.kt | 45 | ||||
-rw-r--r-- | test/src/format/HtmlFormatTest.kt | 10 | ||||
-rw-r--r-- | test/src/model/PackageTest.kt | 13 |
4 files changed, 50 insertions, 18 deletions
diff --git a/test/data/format/crossLanguage/kotlinExtendsJava.html b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html index 5b93d837..5b93d837 100644 --- a/test/data/format/crossLanguage/kotlinExtendsJava.html +++ b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index ebee1290..171b5b9d 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -1,14 +1,20 @@ package org.jetbrains.dokka.tests -import org.jetbrains.kotlin.cli.common.messages.* -import com.intellij.openapi.util.* -import kotlin.test.fail -import org.jetbrains.dokka.* -import java.io.File import com.intellij.openapi.application.PathManager +import com.intellij.openapi.util.Disposer +import org.jetbrains.dokka.* +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.jetbrains.kotlin.config.ContentRoot +import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.junit.Assert +import java.io.File +import kotlin.test.fail -public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> Unit) { +public fun verifyModel(vararg roots: ContentRoot, verifier: (DocumentationModule) -> Unit) { val messageCollector = object : MessageCollector { override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) { when (severity) { @@ -29,8 +35,7 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> val environment = AnalysisEnvironment(messageCollector) { val stringRoot = PathManager.getResourceRoot(javaClass<String>(), "/java/lang/String.class") addClasspath(File(stringRoot)) - addSources(files.toList()) - addClasspath(files.map { File(it)}.filter { it.isDirectory()} ) + addRoots(roots.toList()) } val options = DocumentationOptions(includeNonPublic = true, skipEmptyPackages = false, sourceLinks = listOf<SourceLinkDefinition>()) val documentation = buildDocumentationModule(environment, "test", options, logger = DokkaConsoleLogger) @@ -38,23 +43,32 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> Disposer.dispose(environment) } -public fun verifyPackageMember(vararg files: String, verifier: (DocumentationNode) -> Unit) { - verifyModel(*files) { model -> +public fun verifyModel(source: String, verifier: (DocumentationModule) -> Unit) { + verifyModel(contentRootFromPath(source), verifier = verifier) +} + +public fun verifyPackageMember(kotlinSource: String, verifier: (DocumentationNode) -> Unit) { + verifyModel(kotlinSource) { model -> val pkg = model.members.single() verifier(pkg.members.single()) } } -public fun verifyOutput(path: String, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyModel(path) { +public fun verifyOutput(roots: Array<ContentRoot>, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { + verifyModel(*roots) { val output = StringBuilder() outputGenerator(it, output) val ext = outputExtension.trimLeading(".") + val path = roots.first().path val expectedOutput = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText() assertEqualsIgnoringSeparators(expectedOutput, output.toString()) } } +public fun verifyOutput(path: String, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { + verifyOutput(arrayOf(contentRootFromPath(path)), outputExtension, outputGenerator) +} + public fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) { Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n")) } @@ -112,3 +126,10 @@ object InMemoryLocationService: LocationService { } val tempLocation = InMemoryLocation("") + +val ContentRoot.path: String + get() = when(this) { + is KotlinSourceRoot -> path + is JavaSourceRoot -> file.path + else -> throw UnsupportedOperationException() + } diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index 98b47f06..3d744b95 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -1,8 +1,12 @@ package org.jetbrains.dokka.tests +import org.jetbrains.dokka.HtmlFormatService import org.jetbrains.dokka.KotlinLanguageService +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.jetbrains.kotlin.config.ContentRoot +import org.jetbrains.kotlin.config.KotlinSourceRoot import org.junit.Test -import org.jetbrains.dokka.HtmlFormatService +import java.io.File public class HtmlFormatTest { private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService()) @@ -125,7 +129,9 @@ public class HtmlFormatTest { } Test fun crossLanguageKotlinExtendsJava() { - verifyOutput("test/data/format/crossLanguage/kotlinExtendsJava", ".html") { model, output -> + verifyOutput(arrayOf(KotlinSourceRoot("test/data/format/crossLanguage/kotlinExtendsJava/Bar.kt"), + JavaSourceRoot(File("test/data/format/crossLanguage/kotlinExtendsJava"))), + ".html") { model, output -> htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) } } diff --git a/test/src/model/PackageTest.kt b/test/src/model/PackageTest.kt index 1f1a6ebf..701efbf0 100644 --- a/test/src/model/PackageTest.kt +++ b/test/src/model/PackageTest.kt @@ -1,8 +1,11 @@ package org.jetbrains.dokka.tests +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.DocumentationNode +import org.jetbrains.kotlin.config.KotlinSourceRoot import org.junit.Test -import kotlin.test.* -import org.jetbrains.dokka.* +import kotlin.test.assertEquals +import kotlin.test.assertTrue public class PackageTest { Test fun rootPackage() { @@ -45,7 +48,8 @@ public class PackageTest { } Test fun multipleFiles() { - verifyModel("test/data/packages/dottedNamePackage.kt", "test/data/packages/simpleNamePackage.kt") { model -> + verifyModel(KotlinSourceRoot("test/data/packages/dottedNamePackage.kt"), + KotlinSourceRoot("test/data/packages/simpleNamePackage.kt")) { model -> assertEquals(2, model.members.count()) with(model.members.single { it.name == "simple" }) { assertEquals(DocumentationNode.Kind.Package, kind) @@ -66,7 +70,8 @@ public class PackageTest { } Test fun multipleFilesSamePackage() { - verifyModel("test/data/packages/simpleNamePackage.kt", "test/data/packages/simpleNamePackage2.kt") { model -> + verifyModel(KotlinSourceRoot("test/data/packages/simpleNamePackage.kt"), + KotlinSourceRoot("test/data/packages/simpleNamePackage2.kt")) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(DocumentationNode.Kind.Package, kind) |