From 2a91e15384c1072df1a38ccb3f2a475c5d62cf76 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sat, 16 Jun 2012 00:22:22 +0400 Subject: [PATCH] KDocSmallTest --- .../kotlin/test/kotlin/kdoc/KDocSampleTest.kt | 64 +++++++++++++++++++ libraries/tools/kdoc/src/test/sample/Hello.kt | 6 +- 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt new file mode 100644 index 00000000000..26ea3a9ba1d --- /dev/null +++ b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt @@ -0,0 +1,64 @@ +package test.kotlin.kdoc + +import org.junit.Test +import org.jetbrains.kotlin.doc.KDoc +import org.jetbrains.kotlin.doc.KDocCompiler +import org.jetbrains.kotlin.doc.KDocArguments +import org.jetbrains.jet.cli.common.ExitCode +import org.junit.Assert +import java.io.File +import java.io.IOException + +fun File.rmrf() { + val children = listFiles() + if (children != null) { + for (child in children) { + child!!.rmrf() + } + } + delete() + if (exists()) { + throw IOException("failed to delete $this") + } +} + +fun File.mkdirsProperly() { + mkdirs() + if (!exists()) + throw IOException("failed to crete directory $this") + if (!isDirectory()) { + throw IOException("cannot create directory $this because it exists and it is not a directory") + } +} + + +class KDocSampleTest { + + [Test] + fun generateKDocForSample() { + val compiler = KDocCompiler() + + val args = KDocArguments() + + args.setSourceDirs(arrayList("src/test/sample")) + + val outputDir = File("target/apidocs-sample") + outputDir.rmrf() + outputDir.mkdirsProperly() + + val classesOutputDir = File("target/classes-sample") + classesOutputDir.rmrf() + classesOutputDir.mkdirsProperly() + + args.outputDir = classesOutputDir.getPath()!! + + args.docConfig.docOutputDir = outputDir.getPath()!! + args.docConfig.title = "Sample" + + val exitCode = compiler.exec(System.err, args) + Assert.assertEquals(ExitCode.OK, exitCode) + } + +} + + diff --git a/libraries/tools/kdoc/src/test/sample/Hello.kt b/libraries/tools/kdoc/src/test/sample/Hello.kt index c6ae3c70c87..69368bd37b4 100644 --- a/libraries/tools/kdoc/src/test/sample/Hello.kt +++ b/libraries/tools/kdoc/src/test/sample/Hello.kt @@ -1,8 +1,8 @@ package sample /** A Comment */ -class Person(val name: String, val city: String) { +public class Person(val name: String, val city: String) { fun toString(): String = "Person($name, $city)" - fun hello(): String = "Hello $name" -} \ No newline at end of file + public fun hello(): String = "Hello $name" +}