From 9e15f07aefe6ea1f366466c6721b92e77e3f1b41 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Tue, 22 Jun 2021 15:17:55 +0200 Subject: Logging in CLI (#1976) --- .../src/test/kotlin/basic/FailOnWarningTest.kt | 2 +- plugins/base/src/test/kotlin/basic/LoggerTest.kt | 44 ++++++++++++++++++++++ .../kotlin/signatures/ObviousTypeSkippingTest.kt | 4 +- ...textModuleAndPackageDocumentationReaderTest1.kt | 2 +- ...textModuleAndPackageDocumentationReaderTest3.kt | 2 +- ...ntentModuleAndPackageDocumentationReaderTest.kt | 4 +- 6 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 plugins/base/src/test/kotlin/basic/LoggerTest.kt (limited to 'plugins/base/src/test/kotlin') diff --git a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt index 2a927b97..982d6550 100644 --- a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt +++ b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt @@ -116,7 +116,7 @@ class FailOnWarningTest : BaseAbstractTest() { } private class ZeroErrorOrWarningCountDokkaLogger( - logger: DokkaLogger = DokkaConsoleLogger + logger: DokkaLogger = DokkaConsoleLogger() ) : DokkaLogger by logger { override var warningsCount: Int = 0 override var errorsCount: Int = 0 diff --git a/plugins/base/src/test/kotlin/basic/LoggerTest.kt b/plugins/base/src/test/kotlin/basic/LoggerTest.kt new file mode 100644 index 00000000..92ffb539 --- /dev/null +++ b/plugins/base/src/test/kotlin/basic/LoggerTest.kt @@ -0,0 +1,44 @@ +package basic + +import org.jetbrains.dokka.utilities.DokkaConsoleLogger +import org.jetbrains.dokka.utilities.LoggingLevel +import org.jetbrains.dokka.utilities.MessageEmitter +import org.junit.jupiter.api.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class LoggerTest { + class AccumulatingEmitter : MessageEmitter { + val messages: MutableList = mutableListOf() + override fun invoke(message: String) { + messages.add(message) + } + } + + @Test + fun `should display info messages if logging is info`(){ + val emitter = AccumulatingEmitter() + val logger = DokkaConsoleLogger(LoggingLevel.INFO, emitter) + + logger.debug("Debug!") + logger.info("Info!") + + assertTrue(emitter.messages.size > 0) + assertTrue(emitter.messages.any { it == "Info!" }) + assertFalse(emitter.messages.any { it == "Debug!" }) + } + + @Test + fun `should not display info messages if logging is warn`(){ + val emitter = AccumulatingEmitter() + val logger = DokkaConsoleLogger(LoggingLevel.WARN, emitter) + + logger.warn("Warning!") + logger.info("Info!") + + + assertTrue(emitter.messages.size > 0) + assertFalse(emitter.messages.any { it.contains("Info!") }) + assertTrue(emitter.messages.any { it.contains("Warning!") }) + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/signatures/ObviousTypeSkippingTest.kt b/plugins/base/src/test/kotlin/signatures/ObviousTypeSkippingTest.kt index e85aa5a1..839fb7fe 100644 --- a/plugins/base/src/test/kotlin/signatures/ObviousTypeSkippingTest.kt +++ b/plugins/base/src/test/kotlin/signatures/ObviousTypeSkippingTest.kt @@ -4,16 +4,16 @@ import matchers.content.assertNode import matchers.content.hasExactText import org.jetbrains.dokka.model.firstMemberOfType import org.jetbrains.dokka.pages.* -import org.jetbrains.dokka.testApi.logger.FilteringLogger import org.jetbrains.dokka.testApi.logger.TestLogger import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.utilities.DokkaConsoleLogger +import org.jetbrains.dokka.utilities.LoggingLevel import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource import kotlin.reflect.KClass class ObviousTypeSkippingTest : BaseAbstractTest( - logger = TestLogger(FilteringLogger(minLevel = FilteringLogger.Level.Warn, DokkaConsoleLogger)) + logger = TestLogger(DokkaConsoleLogger(LoggingLevel.WARN)) ) { private fun source(signature: String) = diff --git a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt index 4b4116a2..4d296d17 100644 --- a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt +++ b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt @@ -75,7 +75,7 @@ class ContextModuleAndPackageDocumentationReaderTest1 : AbstractContextModuleAnd private val context by lazy { DokkaContext.create( configuration = configurationBuilder.build(), - logger = TestLogger(DokkaConsoleLogger), + logger = TestLogger(DokkaConsoleLogger()), pluginOverrides = emptyList() ) } diff --git a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt index 9319f5af..d8ea90d7 100644 --- a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt +++ b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt @@ -39,7 +39,7 @@ class ContextModuleAndPackageDocumentationReaderTest3 : AbstractContextModuleAnd private val context by lazy { DokkaContext.create( configuration = configurationBuilder.build(), - logger = DokkaConsoleLogger, + logger = DokkaConsoleLogger(), pluginOverrides = emptyList() ) } diff --git a/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt b/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt index b9837750..6a1f5f11 100644 --- a/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt +++ b/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt @@ -52,14 +52,14 @@ class InvalidContentModuleAndPackageDocumentationReaderTest : AbstractContextMod private val contextA by lazy { DokkaContext.create( configuration = configurationBuilderA.build(), - logger = DokkaConsoleLogger, + logger = DokkaConsoleLogger(), pluginOverrides = emptyList() ) } private val contextB by lazy { DokkaContext.create( configuration = configurationBuilderB.build(), - logger = DokkaConsoleLogger, + logger = DokkaConsoleLogger(), pluginOverrides = emptyList() ) } -- cgit