aboutsummaryrefslogtreecommitdiff
path: root/test/src/TestAPI.kt
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/TestAPI.kt')
-rw-r--r--test/src/TestAPI.kt48
1 files changed, 35 insertions, 13 deletions
diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt
index 165278f9..59b6495b 100644
--- a/test/src/TestAPI.kt
+++ b/test/src/TestAPI.kt
@@ -9,12 +9,14 @@ 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 roots: ContentRoot, verifier: (DocumentationModule) -> Unit) {
+public fun verifyModel(vararg roots: ContentRoot,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationModule) -> Unit) {
val messageCollector = object : MessageCollector {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
when (severity) {
@@ -33,8 +35,14 @@ public fun verifyModel(vararg roots: ContentRoot, verifier: (DocumentationModule
}
val environment = AnalysisEnvironment(messageCollector) {
- val stringRoot = PathManager.getResourceRoot(javaClass<String>(), "/java/lang/String.class")
- addClasspath(File(stringRoot))
+ if (withJdk || withKotlinRuntime) {
+ val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class")
+ addClasspath(File(stringRoot))
+ }
+ if (withKotlinRuntime) {
+ val kotlinPairRoot = PathManager.getResourceRoot(Pair::class.java, "/kotlin/Pair.class")
+ addClasspath(File(kotlinPairRoot))
+ }
addRoots(roots.toList())
}
val options = DocumentationOptions(includeNonPublic = true, skipEmptyPackages = false, sourceLinks = listOf<SourceLinkDefinition>())
@@ -43,19 +51,29 @@ public fun verifyModel(vararg roots: ContentRoot, verifier: (DocumentationModule
Disposer.dispose(environment)
}
-public fun verifyModel(source: String, verifier: (DocumentationModule) -> Unit) {
- verifyModel(contentRootFromPath(source), verifier = verifier)
+public fun verifyModel(source: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationModule) -> Unit) {
+ verifyModel(contentRootFromPath(source), withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, verifier = verifier)
}
-public fun verifyPackageMember(kotlinSource: String, verifier: (DocumentationNode) -> Unit) {
- verifyModel(kotlinSource) { model ->
+public fun verifyPackageMember(kotlinSource: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationNode) -> Unit) {
+ verifyModel(kotlinSource, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model ->
val pkg = model.members.single()
verifier(pkg.members.single())
}
}
-public fun verifyOutput(roots: Array<ContentRoot>, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
- verifyModel(*roots) {
+public fun verifyOutput(roots: Array<ContentRoot>,
+ outputExtension: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+ verifyModel(*roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) {
val output = StringBuilder()
outputGenerator(it, output)
val ext = outputExtension.removePrefix(".")
@@ -65,8 +83,12 @@ public fun verifyOutput(roots: Array<ContentRoot>, outputExtension: String, outp
}
}
-public fun verifyOutput(path: String, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
- verifyOutput(arrayOf(contentRootFromPath(path)), outputExtension, outputGenerator)
+public fun verifyOutput(path: String,
+ outputExtension: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+ verifyOutput(arrayOf(contentRootFromPath(path)), outputExtension, withJdk, withKotlinRuntime, outputGenerator)
}
public fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) {
@@ -110,7 +132,7 @@ fun StringBuilder.appendNode(node: ContentNode): StringBuilder {
fun ContentNode.toTestString(): String {
val node = this
- return StringBuilder {
+ return StringBuilder().apply {
appendNode(node)
}.toString()
}