-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow display name formatter to return null (#3764)
<!-- If this PR updates documentation, please update all relevant versions of the docs, see: https://github.com/kotest/kotest/tree/master/documentation/versioned_docs The documentation at https://github.com/kotest/kotest/tree/master/documentation/docs is the documentation for the next minor or major version _TO BE RELEASED_ --> Fixes #3679
- Loading branch information
Showing
18 changed files
with
116 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...-engine/src/commonMain/kotlin/io/kotest/engine/test/names/FallbackDisplayNameFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.kotest.engine.test.names | ||
|
||
import io.kotest.core.config.ProjectConfiguration | ||
import io.kotest.core.names.DisplayNameFormatter | ||
import io.kotest.core.test.TestCase | ||
import kotlin.reflect.KClass | ||
|
||
class FallbackDisplayNameFormatter( | ||
private val custom: DisplayNameFormatter?, | ||
private val fallback: DefaultDisplayNameFormatter, | ||
) { | ||
|
||
companion object { | ||
fun default() = default(ProjectConfiguration()) | ||
|
||
fun default(configuration: ProjectConfiguration) = | ||
FallbackDisplayNameFormatter(DefaultDisplayNameFormatter(configuration)) | ||
} | ||
|
||
constructor(fallback: DefaultDisplayNameFormatter) : this(null, fallback) | ||
|
||
fun format(kclass: KClass<*>): String { | ||
return custom?.format(kclass) ?: fallback.format(kclass) | ||
} | ||
|
||
fun format(testCase: TestCase): String { | ||
return custom?.format(testCase) ?: fallback.format(testCase) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ework-engine/src/commonMain/kotlin/io/kotest/engine/test/names/GetDisplayNameFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.kotest.engine.test.names | ||
|
||
import io.kotest.common.KotestInternal | ||
import io.kotest.core.config.ExtensionRegistry | ||
import io.kotest.core.config.ProjectConfiguration | ||
import io.kotest.core.extensions.DisplayNameFormatterExtension | ||
|
||
@KotestInternal | ||
fun getFallbackDisplayNameFormatter( | ||
registry: ExtensionRegistry, | ||
configuration: ProjectConfiguration, | ||
): FallbackDisplayNameFormatter { | ||
val custom = registry.all() | ||
.filterIsInstance<DisplayNameFormatterExtension>() | ||
.firstOrNull()?.formatter() | ||
return FallbackDisplayNameFormatter(custom, DefaultDisplayNameFormatter(configuration)) | ||
} |
3 changes: 1 addition & 2 deletions
3
...mework/kotest-framework-engine/src/commonMain/kotlin/io/kotest/engine/test/names/paths.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.