SpineEventEngine / logging

Multiplatform fluent logging API for Kotlin projects
0 stars 0 forks source link

`JvmLoggingFactorySpec` fails when is run standalone #39

Closed yevhenii-nadtochii closed 1 year ago

yevhenii-nadtochii commented 1 year ago

When the test is executed with others, it passes successfully.

But in a standalone mode, two test cases fail:

`JvmLoggingFactory` should[jvm] > obtain a logging domain for[jvm] > a class with annotated package()[jvm] FAILED
    io.kotest.assertions.AssertionFailedError: expected:<"OnPackage"> but was:<<empty string>>

`JvmLoggingFactory` should[jvm] > obtain a logging domain for[jvm] > a class in a nested non-annotated package()[jvm] FAILED
    io.kotest.assertions.AssertionFailedError: expected:<"OnPackage"> but was:<<empty string>>

The used command:

./gradlew :logging:cleanJvmTest :logging:jvmTest --tests "io.spine.logging.JvmLoggingFactorySpec"

The reason is in a lazy initialized annotatedPackages property that lives is LoggingDomainClassValue.kt. It grasps (once!) all packages that are annotated with the logging domain annotation and uses them for searching. But it looks like not all of them go there from the very beginning.

Workaround

Add an initialization block to JvmLoggingFactorySpec that triggers loading of the lacking packages in advance.

internal class JvmLoggingFactorySpec {

    init {
        // Triggers loading of Java packages to the runtime classpath in advance.
        // Thus, correctly initializing lazy `LoggingDomainClassValue.annotatedPackages` property.
        IndirectlyAnnotatedClass::class.simpleName shouldBe "IndirectlyAnnotatedClass"
    }

...
}