aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/basic/LoggerTest.kt
blob: 12c3969046e8528dc675d4c9d7a04c4298947a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package basic

import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.jetbrains.dokka.utilities.LoggingLevel
import org.jetbrains.dokka.utilities.MessageEmitter
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class LoggerTest {
    class AccumulatingEmitter : MessageEmitter {
        val messages: MutableList<String> = 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!") })
    }
}