DefaultAsserter object. Add function to replace constructor invoke.
This commit is contained in:
committed by
Pavel Punegov
parent
ac0f612781
commit
1c4ecd287d
@@ -8,12 +8,17 @@ package kotlin.test
|
||||
/**
|
||||
* Default [Asserter] implementation to avoid dependency on JUnit or TestNG.
|
||||
*/
|
||||
// TODO: make object in 1.2
|
||||
class DefaultAsserter : Asserter {
|
||||
object DefaultAsserter : Asserter {
|
||||
override fun fail(message: String?): Nothing {
|
||||
if (message == null)
|
||||
throw AssertionError()
|
||||
else
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("DefaultAsserter is an object now, constructor call is not required anymore",
|
||||
ReplaceWith("DefaultAsserter", "kotlin.test.DefaultAsserter"))
|
||||
@kotlin.js.JsName("DefaultAsserterConstructor")
|
||||
@Suppress("FunctionName")
|
||||
fun DefaultAsserter(): DefaultAsserter = DefaultAsserter
|
||||
@@ -9,9 +9,4 @@ internal fun messagePrefix(message: String?) = if (message == null) "" else "$me
|
||||
internal expect fun lookupAsserter(): Asserter
|
||||
|
||||
@PublishedApi // required to get stable name as it's called from box tests
|
||||
internal fun overrideAsserter(value: Asserter?): Asserter? {
|
||||
// TODO: Replace with return _asserter.also { _asserter = value } after KT-17540 is fixed
|
||||
val previous = _asserter
|
||||
_asserter = value
|
||||
return previous
|
||||
}
|
||||
internal fun overrideAsserter(value: Asserter?): Asserter? = _asserter.also { _asserter = value }
|
||||
+1
-1
@@ -199,7 +199,7 @@ private fun checkFailedAssertion(assertion: () -> Unit) {
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER")
|
||||
private fun withDefaultAsserter(block: () -> Unit) {
|
||||
val current = overrideAsserter(DefaultAsserter())
|
||||
val current = overrideAsserter(DefaultAsserter)
|
||||
try {
|
||||
block()
|
||||
} finally {
|
||||
|
||||
@@ -9,12 +9,10 @@ import java.util.ServiceLoader
|
||||
|
||||
private val contributors = ServiceLoader.load(AsserterContributor::class.java).toList()
|
||||
|
||||
private val defaultAsserter = DefaultAsserter()
|
||||
|
||||
internal actual fun lookupAsserter(): Asserter {
|
||||
for (contributor in contributors) {
|
||||
val asserter = contributor.contribute()
|
||||
if (asserter != null) return asserter
|
||||
}
|
||||
return defaultAsserter
|
||||
return DefaultAsserter
|
||||
}
|
||||
Reference in New Issue
Block a user