Skip to content

Commit

Permalink
Fix tag inheritance. Fixes #3231
Browse files Browse the repository at this point in the history
  • Loading branch information
Kantis committed Oct 23, 2022
1 parent 5db3e46 commit 0c141ea
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
5 changes: 5 additions & 0 deletions documentation/docs/framework/config_props.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ object KotestEngineProperties {
* */
const val testNameAppendTags = "kotest.framework.testname.append.tags"

/**
* Controls whether classes will inherit tags from their supertypes. Default false
*/
const val tagInheritance = "kotest.framework.tag.inheritance"

/**
* Controls the [io.kotest.core.names.DuplicateTestNameMode] mode.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ abstract class AbstractProjectConfig {

open val testNameAppendTags: Boolean? = null

open val tagInheritance: Boolean? = null

/**
* Controls what to do when a duplicated test name is discovered.
* See possible settings in [DuplicateTestNameMode].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ object KotestEngineProperties {
* */
const val testNameAppendTags = "kotest.framework.testname.append.tags"

/**
* Controls whether classes will inherit tags from their supertypes. Default false
*/
const val tagInheritance = "kotest.framework.tag.inheritance"

/**
* Controls the [io.kotest.core.names.DuplicateTestNameMode] mode.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal fun applyConfigFromProjectConfig(config: AbstractProjectConfig, configu
// config
config.defaultTestCaseConfig?.let { configuration.defaultTestConfig = it }
config.logLevel?.let { configuration.logLevel = it }
config.tagInheritance?.let { configuration.tagInheritance = it }

// coroutines
config.coroutineDebugProbes?.let { configuration.coroutineDebugProbes = it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal actual fun applyConfigFromSystemProperties(configuration: ProjectConfig
allowMultilineTestName()?.let { configuration.removeTestNameWhitespace = it }
globalAssertSoftly()?.let { configuration.globalAssertSoftly = it }
testNameAppendTags()?.let { configuration.testNameAppendTags = it }
tagInheritance()?.let { configuration.tagInheritance = it }
duplicateTestNameMode()?.let { configuration.duplicateTestNameMode = it }
projectTimeout()?.let { configuration.projectTimeout = it }
logLevel(configuration.logLevel).let { configuration.logLevel = it }
Expand Down Expand Up @@ -65,6 +66,9 @@ internal fun globalAssertSoftly(): Boolean? =
internal fun testNameAppendTags(): Boolean? =
sysprop(KotestEngineProperties.testNameAppendTags)?.let { it.uppercase() == "TRUE" }

internal fun tagInheritance(): Boolean? =
syspropOrEnv(KotestEngineProperties.tagInheritance)?.let { it.uppercase() == "TRUE" }

internal fun duplicateTestNameMode(): DuplicateTestNameMode? =
sysprop(KotestEngineProperties.duplicateTestNameMode)?.let { DuplicateTestNameMode.valueOf(it) }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.sksamuel.kotest.engine.config

import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.config.LogLevel
import io.kotest.core.config.ProjectConfiguration
import io.kotest.core.internal.KotestEngineProperties
import io.kotest.core.spec.Isolate
import io.kotest.core.spec.style.FunSpec
import io.kotest.engine.config.applyConfigFromProjectConfig
import io.kotest.engine.config.applyConfigFromSystemProperties
import io.kotest.extensions.system.OverrideMode
import io.kotest.extensions.system.withEnvironment
import io.kotest.extensions.system.withSystemProperty
import io.kotest.matchers.shouldBe

private const val key = KotestEngineProperties.tagInheritance

@Isolate
class ApplyTagInheritanceConfigTest : FunSpec({
test("tag inheritance can come from sys props") {
val config = ProjectConfiguration()

config.tagInheritance shouldBe false

withEnvironment(key, "false", OverrideMode.SetOrOverride) {
withSystemProperty(key, "true", OverrideMode.SetOrOverride) {
applyConfigFromSystemProperties(config)
}
}

config.tagInheritance shouldBe true
}

test("tag inheritance can come from env vars with dots in name") {
val config = ProjectConfiguration()

config.tagInheritance shouldBe false

withEnvironment(key, "true", OverrideMode.SetOrOverride) {
applyConfigFromSystemProperties(config)
}

config.tagInheritance shouldBe true
}

test("tag inheritance can come from env vars with underscores in name") {
val config = ProjectConfiguration()

config.tagInheritance shouldBe false

withEnvironment(key.replace('.', '_'), "TRUE", OverrideMode.SetOrOverride) {
applyConfigFromSystemProperties(config)
}

config.tagInheritance shouldBe true
}

test("Tag inheritance can come from AbstractProjectConfig") {
val config = ProjectConfiguration()

config.tagInheritance shouldBe false

applyConfigFromProjectConfig(object : AbstractProjectConfig() {
override val tagInheritance = true
}, config)

config.tagInheritance shouldBe true
}
})

0 comments on commit 0c141ea

Please sign in to comment.