aboutsummaryrefslogtreecommitdiff
path: root/testApi/src
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-08-13 18:14:44 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-14 14:16:41 +0200
commite9ae3982e3b1e7b5dfd105a9e0cad9ccd9ee8d41 (patch)
tree859784920a58fe45cd757226e5dfaa636f1da074 /testApi/src
parentdd6bbdb88b0e4aaefde6598fee605714a3a516d8 (diff)
downloaddokka-e9ae3982e3b1e7b5dfd105a9e0cad9ccd9ee8d41.tar.gz
dokka-e9ae3982e3b1e7b5dfd105a9e0cad9ccd9ee8d41.tar.bz2
dokka-e9ae3982e3b1e7b5dfd105a9e0cad9ccd9ee8d41.zip
Refactor loggers to allow for message filtering
Diffstat (limited to 'testApi/src')
-rw-r--r--testApi/src/main/kotlin/testApi/logger/TestLogger.kt31
-rw-r--r--testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt12
2 files changed, 38 insertions, 5 deletions
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()