aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt7
-rw-r--r--testApi/src/main/kotlin/testApi/logger/TestLogger.kt31
-rw-r--r--testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt12
3 files changed, 42 insertions, 8 deletions
diff --git a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt
index 0a85ed35..c9ed307a 100644
--- a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt
+++ b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt
@@ -1,12 +1,12 @@
package basic
import org.jetbrains.dokka.DokkaException
+import org.jetbrains.dokka.testApi.logger.TestLogger
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.jetbrains.dokka.utilities.DokkaLogger
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
-import org.jetbrains.dokka.testApi.logger.TestLogger
class FailOnWarningTest : AbstractCoreTest() {
@@ -62,7 +62,6 @@ class FailOnWarningTest : AbstractCoreTest() {
@Test
fun `does not throw if now warning or error was emitted`() {
- logger = TestLogger(ZeroErrorOrWarningCountDokkaLogger())
val configuration = dokkaConfiguration {
failOnWarning = true
@@ -78,7 +77,9 @@ class FailOnWarningTest : AbstractCoreTest() {
"""
|/src/main/kotlin
|package sample
- """.trimIndent(), configuration
+ """.trimIndent(),
+ configuration,
+ loggerForTest = TestLogger(ZeroErrorOrWarningCountDokkaLogger())
) {
/* We expect no Exception */
}
diff --git a/testApi/src/main/kotlin/testApi/logger/TestLogger.kt b/testApi/src/main/kotlin/testApi/logger/TestLogger.kt
index 0bc66a2b..4f81f098 100644
--- a/testApi/src/main/kotlin/testApi/logger/TestLogger.kt
+++ b/testApi/src/main/kotlin/testApi/logger/TestLogger.kt
@@ -46,3 +46,34 @@ class TestLogger(private val logger: DokkaLogger) : DokkaLogger {
logger.error(message)
}
}
+
+class FilteringLogger(
+ private val minLevel: Level,
+ private val downstream: DokkaLogger
+) : DokkaLogger {
+ enum class Level { Debug, Info, Progress, Warn, Error }
+
+ override var warningsCount: Int by downstream::warningsCount
+
+ override var errorsCount by downstream::errorsCount
+
+ override fun debug(message: String) {
+ if (minLevel <= Level.Debug) downstream.debug(message)
+ }
+
+ override fun info(message: String) {
+ if (minLevel <= Level.Info) downstream.info(message)
+ }
+
+ override fun progress(message: String) {
+ if (minLevel <= Level.Progress) downstream.progress(message)
+ }
+
+ override fun warn(message: String) {
+ if (minLevel <= Level.Warn) downstream.warn(message)
+ }
+
+ override fun error(message: String) {
+ if (minLevel <= Level.Error) downstream.error(message)
+ }
+}
diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt
index 25b6b6f2..457325cf 100644
--- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt
+++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt
@@ -9,6 +9,7 @@ import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.testApi.logger.TestLogger
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
+import org.jetbrains.dokka.utilities.DokkaLogger
import org.junit.rules.TemporaryFolder
import java.io.File
import java.nio.charset.Charset
@@ -18,9 +19,9 @@ import java.nio.file.Path
import java.nio.file.Paths
// TODO: take dokka configuration from file
-abstract class AbstractCoreTest {
- protected var logger = TestLogger(DokkaConsoleLogger)
-
+abstract class AbstractCoreTest(
+ protected val logger: TestLogger = TestLogger(DokkaConsoleLogger)
+) {
protected fun getTestDataDir(name: String) =
File("src/test/resources/$name").takeIf { it.exists() }?.toPath()
?: throw InvalidPathException(name, "Cannot be found")
@@ -52,6 +53,7 @@ abstract class AbstractCoreTest {
configuration: DokkaConfigurationImpl,
cleanupOutput: Boolean = true,
pluginOverrides: List<DokkaPlugin> = emptyList(),
+ loggerForTest: DokkaLogger = logger,
block: TestBuilder.() -> Unit
) {
val testMethods = TestBuilder().apply(block).build()
@@ -59,7 +61,7 @@ abstract class AbstractCoreTest {
val fileMap = query.toFileMap()
fileMap.materializeFiles(testDirPath.toAbsolutePath())
if (!cleanupOutput)
- logger.info("Output generated under: ${testDirPath.toAbsolutePath()}")
+ loggerForTest.info("Output generated under: ${testDirPath.toAbsolutePath()}")
val newConfiguration =
configuration.copy(
outputDir = testDirPath.toAbsolutePath().toString(),
@@ -76,7 +78,7 @@ abstract class AbstractCoreTest {
)
DokkaTestGenerator(
newConfiguration,
- logger,
+ loggerForTest,
testMethods,
pluginOverrides
).generate()